2017-02-07 68 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

相關問題