您可能需要使用RemoteWebDriver接口。你使用Firefox还是IE?见下面
File screenshotFile = null;
try {
// This checks to make sure we're not running an
// incompatible driver to take a screenshot (e.g.
// screenshots are not supported by the HtmlUnitDriver)
//the following line will throw a ClassCastException if the current driver is not a browser typed driver
RemoteWebDriver compatibleDriver = (RemoteWebDriver) driver;
screenshotFile = ((TakesScreenshot) compatibleDriver).getScreenshotAs(OutputType.FILE);
} catch (ClassCastException e) {
//this driver does not support screenshots.
// this should get logged as a warning -- this only means the driver cannot be of type RemoteWebDriver
} finally {
if (screenshotFile == null) {
System.out.println("This WebDriver does not support screenshots");
return; //get us outa here
}
}
try {
String pathString = "some path of your choice"
File path = new File(pathString);
if (!path.exists())
path.mkdirs();
stringPath.concat("/someFileName.png");
File newFileLocation = new File(pathString);
System.out.println("Full path to screenshot: " + newFileLocation.getAbsolutePath());
FileUtils.copyFile(screenshotFile, newFileLocation);
} catch (IOException e) {
e.printStackTrace();
}
觉得我们只能采取截图的网页的可见部分,但我们没有任何选择采取截屏整网页通过向下/向上滚动,甚至无法通过PrintScreen/SysRq –
感谢您的回复,但为了防火狐狸硒硒,我设法采取整个内容的屏幕截图。但不能通过Java代码 –