我想设计一个 WPF 页面,我们可以在其中捕获网页屏幕元素。这应该类似于 IE F12(DOM Explorer) 选择元素选项。任何人都可以建议从哪里开始。提前致谢
user6734638
问问题
205 次
1 回答
0
您可以为此使用 selenium,安装后您可以通过以下方式实现:
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);
于 2018-05-22T07:18:02.337 回答