Web Elements Captuing using mshtml and shdocview vb.net/C#

226 views Asked by At

I want to design a WPF page where we can capture web screen elements. This should work something similar to IE F12(DOM Explorer) select element option. Can anybody please suggest where to start. Thanks in advance

1

There are 1 answers

2
Leon Barkan On

you can use selenium for that, after the installation you can achieve it by:

driver.get("http://www.google.com");
WebElement element = driver.findElement(By.id("hplogo"));

// Get entire page screenshot
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
BufferedImage fullImg = ImageIO.read(screenshot);

// Get the location of element on the page
Point point = element.getLocation();

// Get width and height of the element
int eleWidth = element.getSize().getWidth();
int eleHeight = element.getSize().getHeight();

// Crop the entire page screenshot to get only element screenshot
BufferedImage eleScreenshot= fullImg.getSubimage(point.getX(), point.getY(),
    eleWidth, eleHeight);
ImageIO.write(eleScreenshot, "png", screenshot);

// Copy the element screenshot to disk
File screenshotLocation = new File(@"C:\GoogleLogo.png");
FileUtils.copyFile(screenshot, screenshotLocation);