[英]How to make the screenshot of the entire display containing the browser using webdriver?
有人知道如何使用webdriver制作完整的显示屏幕截图吗? 在Selenium文档中,我读到有可能:( http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/TakesScreenshot.html )
..
我使用硒网格。 我的集线器在linux上,节点在Windows上。 我尝试使用Robot,但是在Linux上需要截图,但是在Windows上需要
如果要获取当前正在运行的浏览器实例的屏幕截图,则可以使用以下代码进行操作:
public static void captureScreen(WebDriver driver, String screenshotFileName)
{
String screenshotsFile = screenshotsFolder+screenshotFileName+imageExtention;
try {
File screenShot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenShot, new File(screenshotsFile));
} catch (IOException e) {
}
}
但是,如果您想获取活动窗口的屏幕截图(仅适用于浏览器),则可以使用Robot类。
编辑:
尽管为时已晚,但下面的链接包含您的答案。 我认为这可能对其他搜索同一事物的人有所帮助。 Selenium Webdriver中的屏幕截图问题
您需要使用FirefoxDriver截屏整个页面。 Chrome和IE不支持它。
嗨,像下面这样尝试,它将完成整个网页的屏幕截图
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
//The below method will save the screen shot in defined drive with name "screenshot.png"
FileUtils.copyFile(scrFile, new File("yourPath\\screenshot.png"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.