2017-06-26 80 views
-1

當我打開.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/"); 
} 

回答

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")); 
}