A few days ago, I had a sudden idea when I was automating during research, thinking about whether I could take a picture so that I could view it later. The implementation method is actually not difficult. After all, selenium webdriver has provided the screenshot function, TakesScreenshot interface function (in English, means taking-screenshot).
Don't say much nonsense, just upload the code
package com.wch;import java.io.File;import java.io.IOException;import org.junit.After;import org.junit.Before;import org.junit.Test;import org.openqa.selenium.OutputType;import org.openqa.selenium.TakesScreenshot;import org.openqa.selenium.WebDriver;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.support.ui.WebDriverWait;import com.sun.jna.platform.FileUtils;public class TestTakesScreenshot {public static void main(String[] args) {System.setProperty("webdriver.firefox.bin", "D://Program Files (x86)//Mozilla Firefox//firefox.exe");WebDriver driver = new FirefoxDriver();driver.get("http://www.baidu.com");File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //Talk the screenshot image to be captured in the form of a file {org.apache.commons.io.FileUtils.copyFile(srcFile, new File("d://screenshot.png")); //Use the copyFile() method to save the obtained screenshot file} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}driver.quit();}}If there are other methods, I hope you can provide them and learn from each other.
The above example of Selenium Webdriver implementing screenshot function is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.