在测试移动设备外形时,Chrome屏幕截图只是可见窗口.我很好,这是标准和预期的行为.但是,我还想捕获页面的完整滚动高度,以便我可以检查整个页面的渲染.
我认为最简单的解决方案是将铬窗口高度设置为足够大的值,并完成工作.但是,Chrome窗口高度似乎受我的物理屏幕高度限制,即.我把它设置为5,000 browser.manage().window().setSize(375,5000);,但它只调整到1,200的高度.
我已经知道[根据WebDriver规范] [1],[ takeScreenshot()function] [2] 不应该捕获整个页面,但应该只显示可见区域的屏幕截图.
我试图在Firefox浏览器代码中使用selenium webdriver 2.47.0版本中添加的WebElement#getScreenShotAs(OutputType.FILE)功能
public static void main(String[] args) throws IOException {
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://automationpractice.com/index.php");
WebElement element=driver.findElement(By.cssSelector("a[title='Contact Us']"));
System.out.println(element.getText());
element.getScreenshotAs(OutputType.FILE);
File destination=new File("Image.png");
FileUtils.copyFile(null, destination);
}
Run Code Online (Sandbox Code Playgroud)
..但我得到以下异常:
Contact us
Exception in thread "main" org.openqa.selenium.UnsupportedCommandException: Unrecognized command: GET /session/e796089b-1d64-4590-9157-a0716a57e399/screenshot/%7B4329461b-5e9c-4f8b-b589-ddc1af1d55a6%7D
Command duration or timeout: 16 milliseconds
Build info: version: '2.52.0', revision: '4c2593cfc3689a7fcd7be52549167e5ccc93ad28', time: '2016-02-11 11:22:43'
System info: host: 'mrunal-laptop', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=41.0.2, …Run Code Online (Sandbox Code Playgroud)