java Selenium屏幕捕获图像不可用
我试图用selenium和firefox捕捉http://www.flipkart.comurl的屏幕
public class App {
private static final String APP_URL = "http://www.flipkart.com";
public static void main(String[] args) {
WebDriver webDriver = null;
try {
webDriver = new FirefoxDriver();
webDriver.get(APP_URL);
webDriver.manage().window().maximize();
if (webDriver instanceof TakesScreenshot) {
TakesScreenshot screenshot = (TakesScreenshot) webDriver;
File imageFile = screenshot.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(imageFile, new File(
"C:\\Captures\\captured.png"));
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (webDriver != null) {
webDriver.quit();
}
}
}
}
它拍摄了整个页面的屏幕截图,但显示图像的内部页面不适用于许多其他图像。我无法纠正它。帮帮我
# 1 楼答案
原因是页面正在通过Ajax加载图像。在做截图之前放一个
Thread.sleep()
。这不是一个好的解决方案,但它应该有效:)# 2 楼答案
最好的解决方案是滚动页面,然后截图
在截图之前添加这些行
我尝试了上述解决方案,效果很好
希望这能帮助你。。。如果您有任何疑问,请回电
# 3 楼答案
使用此功能为打开的页面捕获图像,并放置相应的文件夹路径。但所有图像都以png格式存储