java main
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://index.baidu.com");
WebElement baiduLogin = driver.findElement(By.linkText("登录"));
baiduLogin.click();
WebElement userNameBox = driver.findElement(By.id("TANGRAM_12__userName"));
userNameBox.sendKeys("1234567890");
WebElement passwordBox = driver.findElement(By.id("TANGRAM_12__password"));
passwordBox.sendKeys("asd");
WebElement loginButton = driver.findElement(By.id("TANGRAM_12__submit"));
loginButton.submit();
Thread.sleep(3000);
WebElement searchBox = driver.findElement(By.id("schword"));
searchBox.sendKeys("汽车");
searchBox.submit();
Thread.sleep(2000);
snapshot((TakesScreenshot)driver,"汽车.png");
//主方法
public static void snapshot(TakesScreenshot drivername, String filename){
// this method will take screen shot ,require two parameters ,one is driver name, another is file name
File scrFile = drivername.getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
try {
System.out.println("save snapshot path is:"+filename);
FileUtils.copyFile(scrFile, new File(filename));
} catch (IOException e) {
System.out.println("Can't save screenshot");
e.printStackTrace();
}
finally{
System.out.println("screen shot finished");
}
}