selenium webdriver学习(十二)------------如何利用selenium-webdriver截图
在自动化测试中常常会用到截图功能。最近用了一下selenium-webdriver的截图功能还算不错,可以截取页面全图,不管页面有多长。
?
下面的代码演示了如何使用webdriver进行截图:
/** * Capture the screenshot and store it in the specified location. * * <p>For WebDriver extending TakesScreenshot, this makes a best effort * depending on the browser to return the following in order of preference: * <ul> * <li>Entire page</li> * <li>Current window</li> * <li>Visible portion of the current frame</li> * <li>The screenshot of the entire display containing the browser</li> * </ul> * * <p>For WebElement extending TakesScreenshot, this makes a best effort * depending on the browser to return the following in order of preference: * - The entire content of the HTML element * - The visisble portion of the HTML element * * @param <X> Return type for getScreenshotAs. * @param target target type, @see OutputType * @return Object in which is stored information about the screenshot. * @throws WebDriverException on failure. */
?试了一下截取Webelement最终发现WebElement接口没有实现这个类。搞了半天也只是会了截取页面的全图。截取当前的frame也截取的页面全图。难道这个功能没有完善,好吧,这样说自我安慰一下。
selenium-webdriver 面向接口编程,找一个需要的功能还真是挺难的。