我需要捕获IE浏览器的整个页面。我正在使用网络驱动程序。请帮助我。
下面的代码仅用于捕获当前窗口。
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));
答案 0 :(得分:1)
您可以在截取屏幕截图之前将浏览器更改为全屏。这是代码:
private void changeToFullScreen() {
try {
Robot r;
r = new Robot();
r.keyPress(java.awt.event.KeyEvent.VK_F11);
r.keyRelease(java.awt.event.KeyEvent.VK_F11);
driver.sleep(2);
} catch (AWTException e) {
log.error("It was not possible to maximize", e)
driver.manage().window().maximize();
}
}
如果您不想更改屏幕尺寸,可以获得浏览器高度并在向下滚动到底部时使用screenShots(可以使用Robot完成):
int numberOfScrolls = pageHeight / browserHeight;
for(int i = 0 ; i < numberOfScrolls ; i++){
takeScreenshot();
scrollDown(browserHeight);
}
concatenateScreenshots();
答案 1 :(得分:0)
import java.io.File;
import javax.imageio.ImageIO;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
public class TakeScreenshotWithScroll {
static WebDriver driver;
public static void main(String args[]) throws Exception{
String key = "webdriver.gecko.driver";
String value = "driver/geckodriver.exe";
driver = new FirefoxDriver();
System.setProperty(key, value);
driver.get("ENTER THE URL HERE");
Thread.sleep(2000);
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
}
}
以下是aShot Jar文件
的下载链接