无法使用Selenium拍摄CEF应用程序的屏幕截图 [英] Unable to take screenshot of CEF application using Selenium

查看:97
本文介绍了无法使用Selenium拍摄CEF应用程序的屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

我正在使用以下内容:

  1. CEF应用程序- CEF提供的示例应用程序
  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();
    }
}

我正面临错误.

推荐答案

我正在使用以下内容:

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

这篇关于无法使用Selenium拍摄CEF应用程序的屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆