Unable to take screenshot of CEF application using Selenium

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:29:35

问题


I am using Selenium to automate the CEF application. I am successfully able to perform operations like click etc. But not able to take the screenshot using Selenium driver. As it is very much required feature for automation. How can I do this?

I'm using the following:

  1. CEF application - 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

Find the below code:

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();
    }
}

I am facing the error.


回答1:


I'm using the following:

  1. CEF application - Sample application provided by CEF (link - https://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

Here is the code:

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();
    }
}


来源:https://stackoverflow.com/questions/42095658/unable-to-take-screenshot-of-cef-application-using-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!