繁体   English   中英

Webdriver中的屏幕截图

[英]Screenshot in Webdriver

我想使用Selenium WebDriver拍摄每个访问页面的屏幕截图吗? 我用这个代码:

try{

     File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     FileUtils.copyFile(screenshot,new File("C:\\Users\\udit\\Desktop\\screenshot.jpeg"));
 }catch(Exception e){
       System.out.println("Failure to take screenshot "+e);

尝试这种方式,它将为您工作。

try{

                 File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                 String screenshotPath= "C:\\Users\\udit\\Desktop\\screenshot.jpeg";
                 FileUtils.copyFile(screenshot,new File(screenshotPath));
             }catch(Exception e){
                   System.out.println("Failure to take screenshot "+e);
}

希望您需要进行多屏拍摄。尝试以下链接https://github.com/Pavan-and-Vikas-Utilities/MultiScreenShot

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM