硒屏幕捕捉 - 图像不可用
问题描述:
我想捕捉屏幕的http://www.flipkart.com使用硒与Firefox。硒屏幕捕捉 - 图像不可用
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();
}
}
}
}
它需要整页的屏幕截图,但它显示的内页图像许多其他图像不可用。我无法纠正它。帮我。
答
最好的解决办法是通过页面滚动,然后采取截图
//scroll to the bottom of the page
((JavascriptExecutor) webDriver).executeScript("window.scrollTo(0,document.body.scrollHeight)");
////scroll to the top of the page
((JavascriptExecutor) webDriver).executeScript("window.scrollTo(0,0)");
采取截图
我之前添加这些行试图用它工作得很好
希望这有助于你上面的解决方案...请回来,如果您有任何疑问
答
的原因是,加载页面时通过Ajax的图像。在制作屏幕截图之前放置一个Thread.sleep()
。这不是一个很好的解决方案,但它应该工作:)
答
使用此功能捕获已打开页面的图像,并放置相应的文件夹路径。但所有图像都以png格式存储。
public static void captureScreenShot(WebDriver ldriver) {
// Take screenshot and store as a file format
File src = ((TakesScreenshot) ldriver).getScreenshotAs(OutputType.FILE);
try {
// now copy the screenshot to desired location using copyFile method
// title=ldriver.getTitle();
FileUtils.copyFile(src, new File(System.getProperty("user.dir") + "\\src\\data\\" + siteCapture + "\\"
+ System.currentTimeMillis() + ".png"));
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
这工作完美,似乎是页面滚动时加载图像 –