怎么用Selenium webdriver進行截圖操作


1.IE瀏覽器下截圖:

 1 public static void takeScreenShotIE(WebDriver driver, String name){
 2   WebDriver augmentedDriver = new Augmenter().augment(driver);
 3   File output = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
 4   File file = new File(screenshootDir, name + ".png");
 5   try {
 6       FileUtils.copyFile(output, file);
 7   } catch (IOException e) {
 8       e.printStackTrace();
 9   }
10 } 

 

2.Chrome&FireFox瀏覽器下截圖:

 1 public static void takeScreenShotChromeFirefox(WebDriver driver, String name){
 2   File output = null;
 3   File file;
 4   output = ((TakesScreenshot) driver)
 5                   .getScreenshotAs(OutputType.FILE);
 6   file = new File(screenshootDir, name + ".png");
 7   try {
 8       FileUtils.copyFile(output, file);
 9   } catch (IOException e) {
10       e.printStackTrace();
11   }
12 } 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM