标签:exception nqa www print out selenium set public 窗体
本篇介绍Selenium中截图类TakeScreenshout,这个类主要是获取浏览器窗体内的内容,不包括浏览器的菜单和桌面的任务栏区域。
package lessons; import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class TakeScreenshot { public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", ".\\Tools\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://www.baidu.com"); Thread.sleep(1000); // 调用截图方法 File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { // 拷贝截图文件到我们项目./Screenshots FileUtils.copyFile(src, new File(".\\Screenshots\\screen.png")); } catch (IOException e) { System.out.println(e.getMessage()); } } }
标签:exception nqa www print out selenium set public 窗体
原文地址:http://www.cnblogs.com/liu-Gray/p/7805208.html