【问题标题】:Unable to take screenshot of CEF application using Selenium无法使用 Selenium 截取 CEF 应用程序的屏幕截图
【发布时间】:2017-06-25 00:57:44
【问题描述】:

我正在使用 Selenium 来自动化 CEF 应用程序。我能够成功执行点击等操作。但无法使用 Selenium 驱动程序截取屏幕截图。因为它是自动化非常需要的功能。我该怎么做?

我正在使用以下内容:

  1. CEF 申请 - sample application provided by CEF
  2. selenium jar - selenium-server-standalone-3.0.1
  3. cef_binary_3.2924.1564.g0ba0378_windows64_client
  4. chromedriver

找到下面的代码:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;

public class Example  {
    public static void main(String[] args) {
        // Path to the ChromeDriver executable.
        System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
        // Path to the CEF executable.
        ChromeOptions options = new ChromeOptions();

         options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");

        WebDriver driver = new ChromeDriver(options);
        driver.get("http://www.google.com/xhtml");
        sleep(3000);  // Let the user actually see something!
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("ChromeDriver");
        searchBox.submit();
        sleep(5000);  // Let the user actually see something!

        String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
        System.out.println(screenshotBase64);
        sleep(5000);  // Let the user actually see something!
        driver.quit();
    }
}

我遇到了错误。

【问题讨论】:

  • 我们可以看看你目前有什么代码吗?您使用什么驱动程序/语言?您是否研究过如何做到这一点?
  • 1) CEF 应用程序 - CEF 提供的示例应用程序 (link - bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md) 2) selenium jar - selenium-server-standalone-3.0.1 3) cef_binary_3.2924.1564.g0ba0378_windows64_client 4) chromedriver
  • Shweta,如果您有更多要添加的材料,请编辑问题,而不是在 cmets 或答案中添加更多材料。

标签: selenium chromium chromium-embedded


【解决方案1】:

我正在使用以下内容:

  1. CEF 应用程序 - CEF 提供的示例应用程序(链接 - https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md
  2. 硒罐 - selenium-server-standalone-3.0.1
  3. cef_binary_3.2924.1564.g0ba0378_windows64_client
  4. chromedriver

代码如下:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.OutputType;

public class Example  {
    public static void main(String[] args) {
        // Path to the ChromeDriver executable.
        System.setProperty("webdriver.chrome.driver", "D:/CEFTesting/chromedriver.exe");
        // Path to the CEF executable.
        ChromeOptions options = new ChromeOptions();

        options.setBinary("D:/CEFTesting/cef_binary_3.2924.1564.g0ba0378_windows64_client/Release/cefclient.exe");

        WebDriver driver = new ChromeDriver(options);
        driver.get("http://www.google.com/xhtml");
        sleep(3000);  // Let the user actually see something!
        WebElement searchBox = driver.findElement(By.name("q"));
        searchBox.sendKeys("ChromeDriver");
        searchBox.submit();
        sleep(5000);  // Let the user actually see something!

        String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
        System.out.println(screenshotBase64);
        sleep(5000);  // Let the user actually see something!
        driver.quit();
    }
}

【讨论】:

  • Shweta,如果您有更多材料要添加,请edit the question - 答案框仅用于答案。您还没有提及您看到的错误。我已经尽可能多地编辑了这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-26
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
  • 2017-12-25
  • 2013-11-17
  • 2011-03-18
相关资源
最近更新 更多