【发布时间】:2017-06-25 00:57:44
【问题描述】:
我正在使用 Selenium 来自动化 CEF 应用程序。我能够成功执行点击等操作。但无法使用 Selenium 驱动程序截取屏幕截图。因为它是自动化非常需要的功能。我该怎么做?
我正在使用以下内容:
- CEF 申请 - sample application provided by CEF
selenium jar - selenium-server-standalone-3.0.1cef_binary_3.2924.1564.g0ba0378_windows64_client- 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