我试着用selenium和火狐一起捕捉http://www.flipkart.com url的屏幕。
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();
}
}
}
}它接受整个页面的屏幕截图,但是它显示的内部页面显示的图像对于许多其他图像来说是不可用的。我无法改正它。帮帮我。

发布于 2015-07-21 10:44:47
最好的解决方案是滚动页面,然后截图。
//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)");在截图前添加这一行
我试着用上面的解决方案,效果很好。
如果您有任何疑问,希望这有助于you...Kindly返回。
发布于 2015-07-21 10:12:21
原因是页面正在通过Ajax加载图像。在制作截图之前先放一个Thread.sleep()。这不是一个很好的解决方案,但它应该有效:)
发布于 2017-04-21 12:51:37
使用此函数可以捕获打开的页面的图像,并与相应的文件夹path.but一起放置所有图像都以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());
}
}https://stackoverflow.com/questions/31536124
复制相似问题