繁体   English   中英

Selenium-Firefox Webdriver将仅截取部分屏幕截图

[英]Selenium - Firefox webdriver will only take partial screenshot

从我阅读的代码如下:

    File s = ((TakesScreenshot)driver_).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(s,new File("C:\\scr.png"));
    } catch (IOException exception) {
        exception.printStackTrace();
    }

应该拍摄整页的屏幕截图。 但就我而言,它将仅获取浏览器窗口中当前可见内容的屏幕截图。 这是预期的行为,还是代码出了点问题?

是的,这是Firefox的预期行为。 如果要截取全屏屏幕截图,可以使用类似的方法将整个内容缩小到可见区域

executor = (JavascriptExecutor)driver.getDriver();
executor.executeScript(
         "document.body.style.zoom=
            (top.window.screen.height-70)/
            Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);");
File scrFile = ((TakesScreenshot)driver.getDriver()).getScreenshotAs(OutputType.FILE);

它将尝试将所有内容带到可见区域,尽管您仍然可能会从最底部错过一些内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM