【问题标题】:How to make the screenshot of the entire display containing the browser using webdriver?如何使用 webdriver 制作包含浏览器的整个显示的屏幕截图?
【发布时间】:2016-08-21 20:26:15
【问题描述】:

有人知道如何使用 webdriver 制作完整的屏幕截图吗? 在 Selenium 文档中,我读到有可能:(http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/TakesScreenshot.html)

..

  • 包含浏览器的整个显示屏幕截图
  • ..

    我使用 Selenium Grid。我的集线器在 linux 上,节点在 windows 上。我尝试使用Robot,但是它在linux上截屏,但是在windows上需要

    【问题讨论】:

    • 您需要更多信息;这里真的没有问题。例如,您尝试过什么?你有你写的任何代码吗?如果是,请发布!

    标签: java selenium selenium-webdriver selenium-grid


    【解决方案1】:

    如果您想要当前运行的浏览器实例的屏幕截图,则可以使用以下代码:

      public static void captureScreen(WebDriver driver, String screenshotFileName)
        {
            String screenshotsFile = screenshotsFolder+screenshotFileName+imageExtention;
    
            try {
                File screenShot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenShot, new File(screenshotsFile));
            } catch (IOException e) {
    
            }
        }
    

    但是,如果您想截取活动窗口的屏幕截图(仅浏览器除外),则可以使用 Robot 类。

    编辑:

    虽然为时已晚,但下面的链接包含您的答案。我认为这可能对正在寻找相同事物的其他人有所帮助。 Screen shot issue in selenium webdriver

    【讨论】:

    • 是的,我需要对我的活动窗口进行截图。但是我的集线器在 Linux 上,节点在 Windows 上。所以Robot在linux上截图
    【解决方案2】:

    你好,像下面这样尝试,它将拍摄完整的网页屏幕截图

     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     //The below method will save the screen shot in defined drive with name "screenshot.png"
     FileUtils.copyFile(scrFile, new File("yourPath\\screenshot.png"));
    

    【讨论】:

    • 谢谢,但我需要截屏。
    【解决方案3】:

    您需要使用 FirefoxDriver 来截取整个页面。 Chrome 和 IE 不支持。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多