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.
Can someone please help me out on taking the screenshot of CEF application using Selenium.
I'm using the following -
1) CEF application - Sample application provided by CEF (link - https://bitbucket.org/chromiumembedded/ ... eDriver.md)
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();
}
static void sleep(int time) {
try { Thread.sleep(time); } catch (InterruptedException e) {}
}
}
-----------------------------------------------------------------------------------------
Facing the following error -
System info: host: 'INNOSZLP00222', ip: '192.168.42.21', os.name: 'Windows 7', o
s.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_25'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEn
abled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.44
0174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=C:\Users\VB0053~1\A
ppData\Local\Temp\scoped_dir4660_14066}, takesHeapSnapshot=true, pageLoadStrateg
y=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, versi
on=, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCe
rts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrom
e, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexp
ectedAlertBehaviour=}]
Session ID: bb7a4653e3468fe8f5a04c49180bee45
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
rce)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.
java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHa
ndler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:635)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:658)
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebD
river.java:340)
at Example.main(Example.java:26)
D:\CEFTesting>java -cp ".;*" Example[0208/101054.009:WARNING:dns_config_service_
win.cc(661)] Failed to read DnsConfig.
[0208/101206.131:ERROR:dns_config_service_win.cc(745)] DNS config watch failed.
shweta
Posts: 2
Joined: Tue Feb 07, 2017 11:39 am
Top