Selenium webdriver截图
java语言,进行截图的代码如下:
public void screenshot(WebDriver driver){ File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);//截图代码 SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");//设置日期格式 //将截图剪切到指定路径 try{ FileUtils.moveFile(screenShotFile, new File("test-output/snapshot/" + df.format(new Date())+ ".jpg")); }catch(IOException e){ System.out.println("can't save screenshot"); } }
其中关键的代码是
File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)