Java 未间歇性捕获网页的屏幕截图

Java 未间歇性捕获网页的屏幕截图,java,selenium-webdriver,screenshot,snapshot,Java,Selenium Webdriver,Screenshot,Snapshot,我正在使用SeleniumWeb驱动程序执行一个测试用例,并使用以下代码捕获网页的快照 // following code executes the logout button on the portal. Config.firefox_dri.findElement(By.xpath("//li[@class='dropdown-parent']/div[@class='account']/div[@class='fleft']")).click(); Config.firefox_dri.

我正在使用SeleniumWeb驱动程序执行一个测试用例,并使用以下代码捕获网页的快照

// following code executes the logout button on the portal.

Config.firefox_dri.findElement(By.xpath("//li[@class='dropdown-parent']/div[@class='account']/div[@class='fleft']")).click();
Config.firefox_dri.findElement(By.xpath("//li[@class='settings-item']/a[@id='logout']")).click();

//below code takes the snapshot of the web page after logging out.

try {
    Thread.sleep(3000);
    File scrFile =     ((TakesScreenshot)Config.firefox_dri).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File(screen_shot_file_name));

} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
但我在快照方面面临的问题是,有时会捕获快照快照,而有时会捕获空白快照或部分网页的快照。
在插入一些等待之后,我也尝试了它,以便在捕获快照之前加载页面。但这个问题仍然存在。代码是用Java编写的,注销门户的功能正常工作。请提供帮助。

您是否尝试使用wait.untill()?而不是thread.sleep(3000),wait.untill(‘找到确保页面已加载的元素’)此问题的答案可能会有所帮助: