2017-02-07 70 views
0

我正在使用Selenium来自动化CEF应用程序。我成功地能够执行像点击等操作,但无法使用Selenium驱动程序截图。因为这是自动化所必需的特性。我怎样才能做到这一点?无法使用Selenium截取CEF应用程序的屏幕截图

我使用了以下内容:

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

我正面临错误。

+0

我们可以看看到目前为止您有什么代码?你使用什么驱动程序/语言?你研究过如何做到这一点? – halfer

+0

1)CEF应用程序 - 由CEF提供的示例应用程序(链接 - \t https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md) 2)硒罐 - 硒 - 服务器 - 独立3.0.1 3 )cef_binary_3.2924.1564.g0ba0378_windows64_client 4)chromedriver – Shweta12345

+0

Shweta,请编辑问题,如果你有更多的材料要添加,而不是在评论或答案中增加更多材料。 – halfer

回答

0

我使用了以下内容:

  1. CEF应用 -
  2. 硒罐子 - 通过CEF(https://bitbucket.org/chromiumembedded/cef/wiki/UsingChromeDriver.md链接) - 提供了示例应用程序硒的服务器独立-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(); 
    } 
} 
+3

Shweta,请[编辑问题](https://stackoverflow.com/posts/42095658/edit)如果你有更多的材料添加 - 答案框只用于答案。你也没有提到你所看到的错误。我已经尽可能多地编辑了这个问题。 – halfer

相关问题