selenium-webdriver
Ta skärmbilder
Sök…
Introduktion
Ta skärmbilder och spara på en viss väg
Syntax
- File src = ((TakesScreenshot) drivrutin) .getScreenshotAs (OutputType.FILE);
- FileUtils.copyFile (src, ny fil ("D: \ screenshot.png"));
JAVA
Kod att ta och spara skärmdump:
public class Sample
{
public static void main (String[] args)
{
*//Initialize Browser*
System.setProperty("webdriver.gecko.driver", "**E:\\path\\to\\geckodriver.exe**");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.google.com/");
//Take Screesnshot
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
//Save Screenshot in destination file
FileUtils.copyFile(src, new File("D:\\screenshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Tar skärmdump:
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Butiker Skärmdump från källa till destination:
FileUtils.copyFile(src, new File("D:\\screenshot.png"));
Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow