首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >Selenium v>=3.4.0上的全页截图?

Selenium v>=3.4.0上的全页截图?
EN

Stack Overflow用户
提问于 2017-07-23 23:11:24
回答 2查看 253关注 0票数 3

Selenium开发人员决定停止全页截图功能:https://github.com/SeleniumHQ/selenium/issues/3912

在应用程序测试脚本中模仿这个特性需要哪些代码呢?

我试图降级为Selenium 3.3.1,但有些依赖于驱动程序和/或浏览器版本,这是不兼容的。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-08-04 22:03:16

在一个晦涩的开源库中找到的解决方案:

pom.xml

代码语言:javascript
代码运行次数:0
运行
复制
    <dependency>
        <groupId>ru.yandex.qatools.ashot</groupId>
        <artifactId>ashot</artifactId>
        <version>1.5.4</version>
    </dependency>

SomeJavaTest.java

代码语言:javascript
代码运行次数:0
运行
复制
private void screenshot(File out) throws IOException, InterruptedException, AWTException {

    final Screenshot screenshot = new AShot()
            .shootingStrategy(ShootingStrategies.viewportPasting(100))
            .takeScreenshot(driver);

    final BufferedImage image = screenshot.getImage();
    ImageIO.write(image, "PNG", out);

}
票数 0
EN

Stack Overflow用户

发布于 2017-07-24 13:50:11

尝尝这个。

代码语言:javascript
代码运行次数:0
运行
复制
import unittest
from selenium import webdriver
import datetime

class Tests(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome(desired_capabilities={'browserName': 'chrome', 'chromeOptions': {'args': ['--headless'], 'binary': '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'}})
        self.driver.get('http://google.com/')

def tearDown(self):
    self.driver.quit()

def test_screenshot(self):
    width = self.driver.execute_script(
        "return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")
    height = self.driver.execute_script(
        "return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);")
    self.driver.set_window_size(width+100, height+100)
    self.driver.save_screenshot('screenshot ' + str(datetime.datetime.now().date()) + ' ' + str(datetime.datetime.now().time()) + '.png')
if __name__ == '__main__':
    unittest.main()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45270682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档