空白屏幕拍摄与Selenium脚本

时间:2017-06-26 20:33:24

标签: selenium-webdriver

当我打开.jpeg文件时,它是空白的。

    public static void main(String[] args) throws Exception {

            System.setProperty("webdriver.chrome.driver","C:\\Users\\allan\\workspace\\Login\\chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File("C:\\screenshots\\screenshot.jpeg"));


            driver.get("https://www.facebook.com/");
}

1 个答案:

答案 0 :(得分:0)

您在导航到任何网站之前都会截取屏幕截图。

public static void main(String[] args) throws Exception {
    System.setProperty("webdriver.chrome.driver","C:\\Users\\allan\\workspace\\Login\\chromedriver.exe");
            WebDriver driver = new ChromeDriver();
            driver.get("https://www.facebook.com/");
            File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(scrFile, new File("C:\\screenshots\\screenshot.jpeg"));   
}