Selenium firefox - WebDriverException: Reached error page: about:certerror - java

Meta :-
Firefox v51.0.1 (32-bit)
Windows 10
Selenium 3.0.1
Geckodriver Win32 v0.13.0
Java v1.8.0_71
Steps to reproduce :-
WebDriver driver = new FirefoxDriver();
driver.get("untrusted/self-signed URL")
Stacktrace :-
org.openqa.selenium.WebDriverException: Reached error page: about:certerror?e=nssBadCert&u=xxxxxxxx&c=UTF-8&f=regular&d=xxxxxx%20uses%20an%20invalid%20security%20certificate.%0A%0AThe%20certificate%20is%20not%20trusted%20because%20it%20is%20self-signed.%0AThe%20certificate%20is%20not%20valid%20for%20the%20name%20xxxxxx%0A%0AError%20code%3A%20%3Ca%20id%3D%22errorCode%22%20title%3D%22SEC_ERROR_UNKNOWN_ISSUER%22%3ESEC_ERROR_UNKNOWN_ISSUER%3C/a%3E%0A
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'Saurabh-PC', ip: '192.168.3.8', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_71'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Screenshot :-
I have also tried using FirefoxProfile as :-
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(dc);
driver.get("untrusted/self-signed URL");
But issue is the same as above.
Reference Link which have tried :-
How to disable Firefox's untrusted connection warning using Selenium?
https://groups.google.com/forum/?fromgroups#!topic/webdriver/frWtNrEwNPk
Handling UntrustedSSLcertificates using WebDriver
According to this bug Support for untrusted/self-signed certificates has been added via bug 1103196 and will be available starting with Firefox 52.
But I could not find any solution for Firefox v51.0.1 (32-bit).
Is there any way to solve this issue using Firefox v51.0.1 (32-bit)?

As in this bug mentioned Support for untrusted/self-signed certificates will be available starting with Firefox 52, we need to wait until Firefox 52 is not released.
Solution :-
For now, as alternate solution we need to use existing Firefox profile where the certificate for untrusted/self-signed URL is already added into Firefox's exception list.
How to create custom Firefox profile for selenium?
Need to follow this link to create manually custom Firefox profile
Add manually certificate for untrusted/self-signed URL into Firefox's exception list
Launch Firefox using existing profile as :-
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver")
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("created Profile Name");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("untrusted/self-signed URL");

Related

SessionNotCreatedException: Could not start a new session. Response code 500 error using Selenium Java and WebDriverManager through pom.xml

I want to test my script on chrome beta version and for that reason I have installed chrome beta version but somehow I am not able to start it using Selenium Java. I have all the needed dependency added in pom.xml file regarding webdriver manager etc. I am sharing my console error and also script.
ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\Users\\WRP\\Downloads\\Programs\\ChromeSetup.exe");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(optionsBeta);
//System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver.exe");
// WebDriver driver = new ChromeDriver();
WebDriverManager.chromedriver().setup();
//WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
//WebDriver driver = new ChromeDriver();
WebDriverWait waits=new WebDriverWait (driver, Duration.ofSeconds(10));
Error tracelogs:
Starting ChromeDriver 104.0.5112.29 (eff877e18f767c77fef0481a1cba402c8cbad404-refs/branch-heads/5112#{#422}) on port 55215
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'AWAIS-PC', ip: '192.168.1.62', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., extensions: []}}}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:264)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:179)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:70)
at First_Test.Practice_First.main(Practice_First.java:29)
This error message...
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. google-chrome session.
Your have to take care of a couple of things here as follows:
setBinary() argument should be used to point to the binary executable i.e. chrome.exe post installation of the browser software (ChromeSetup.exe)
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");
You'd use either of the following (not both):
The downloaded version of the chromedriver.exe using the System.setProperty() line as follows:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
The WebDriverManager dependency in pom.xml and setup the chromedriver as:
WebDriverManager.chromedriver().setup();
Your effective code block will be:
Using downloaded ChromeDriver:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");
WebDriver driver = new ChromeDriver(optionsBeta);
Using Maven Dependency in pom.xml:
WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");
WebDriver driver = new ChromeDriver(optionsBeta);
Use the below chrome option
options = webdriver.ChromeOptions()
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--ignore-ssl-errors=yes')
options.add_argument('--ignore-certificate-errors')
This line very important on skip this error
options.add_argument('--disable-dev-shm-usage')

SessionNotCreatedException: session not created exception from unknown error: Runtime.executionContextCreated has invalid 'context' with Chrome driver

Error stack trace (Updated from comments):
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 7778 Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"961185F0AA38D24650EF6C797BC32535","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.68 seconds Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:41'
System info: host: 'LTAH024', ip: '192.168.131.142', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: ChromeDriver
I wrote simple program to launching a chrome browser. Please see the below code. I have already set a path in environment variable:
package automationFramework;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver drive = new ChromeDriver();
drive.get("http://toolsqa.com/selenium-webdriver/running-tests-in-chrome-browser/");
System.out.println("Successfully open tools qa website in Chrome browser");
//Thread.sleep(5000); //To initiate thread , we need to add throws interrupt exception
//Close the driver
//driver.quit();
}
}
Please look into this and help me out. The same thing geckodriver for firefox is working.
This error message...
Starting ChromeDriver 2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067) on port 7778 Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created exception from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"961185F0AA38D24650EF6C797BC32535","isDefault":true,"type":"default"},"id":1,"name":"","origin":"://"}
(Session info: chrome=70.0.3538.102)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.68 seconds Build info: version: '3.141.5', revision: 'd54ebd709a', time: '2018-11-06T11:58:41'
System info: host: 'LTAH024', ip: '192.168.131.142', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: ChromeDriver
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
You have 3 issues exactly and your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.2.20
Release Notes of chromedriver=2.20 clearly mentions the following :
Supports Chrome v43-48
You are using chrome=70.0
Release Notes of ChromeDriver v2.43 clearly mentions the following :
Supports Chrome v69-71
Your Selenium Client version is the current version of 3.141.5..
Your JDK version is 1.8.0_60 which is pretty ancient.
So there is a clear mismatch between the JDK v8u60 , Selenium Client v3.141.5 , ChromeDriver v2.20 and the Chrome Browser v70.0
Solution
While using Selenium v3.x clients you need to download the latest ChromeDriver from ChromeDriver - WebDriver for Chrome store it anywhere within your system and provide the absolute path of the ChromeDriver through System.setProperty() line as follows:
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
Upgrade JDK to recent levels JDK 8u191.
Upgrade ChromeDriver to current ChromeDriver v2.43 level.
Keep Chrome version between Chrome v69-71 levels. (as per ChromeDriver v2.43 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Download chrome driver, keep it at your local and put the path at System.setProperty try the below code, hope it helps.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class ChromeBrowser {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "B:\\chromedriver.exe"); //put driver path here
WebDriver drive = new ChromeDriver();
drive.get("http://toolsqa.com/selenium-webdriver/running-tests-in- chrome-browser/");
System.out.println("Successfully open tools qa website in Chrome browser");
drive.quit();
}
}
Their are Three Ways to open The Chrome Browser:
First one:using system.setproperty
System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
Webdriver driver = new ChromeDriver();
Second one : using Chrome Options:
//set path to chromedriver.exe
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
options.setBinary(new File("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"));
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
driver = new ChromeDriver(options);
Last one : if you are using maven use this
This downloads the latest chrome driver version and starts it. You can use WebDriverManager within using bonigarcia dependency. Add The bonigarcia dependency in your Pom.xml File and start using it via WebdriverManager
https://github.com/bonigarcia/webdrivermanager
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
Finally What is Version for your Gecko driver & Firefox?

Unable to run Headless Chrome Browser on Linux Machine using Selenium Webdriver java

Used Selenium Webdriver(V2.29), selenium-api version(3.4.0), Chrome
Version (62.0.3202.94) 64 bit and tried to run chrome browser in linux machine with the below code.
WebDriver driver;
String chromeBinaryPath = "/data/Package/CHROME_NEW";
String driverPath = "/data/Package/Selenium/WebDrivers/ChromeDrivers/chromedriver_linux32/chromedriver";
System.setProperty("webdriver.chrome.driver", driverPath);
System.setProperty("webdriver.chrome.verboseLogging","true");
System.setProperty("webdriver.chrome.logfile","/data/Package/log/chromedriver.log");
ChromeOptions optionsLinux64 = new ChromeOptions();
optionsLinux64.setBinary(chromeBinaryPath);
optionsLinux64.addArguments("--headless");
optionsLinux64.addArguments("--no-sandbox");
optionsLinux64.addArguments("--disable-gpu");
optionsLinux64.addArguments("--headless");
driver = new ChromeDriver(optionsLinux64);
When tried to create a chrome session, getting below exception:
unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.29.461571 (8a88bbe0775e2a23afda0ceaf2ef7ee74e822cc5),platform=Linux 3.10.0-693.5.2.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.10 seconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'el4014.bc', ip: '10.120.94.70', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.5.2.el7.x86_64', java.version: '1.8.0_151' Driver info: driver.version: ChromeDriver
Installed Chrome at /data/Package/CHROME_NEW folder using rpm file.
Message in chromedriver.log:
[0.204][DEBUG]: DevTools request: http://localhost:12111/json/version
LaunchProcess: failed to execvp:
/data/Package/CHROME_NEW/
[0.379][DEBUG]: DevTools request failed
Can anyone help me in resolving with the above issue.
This should be work:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
Try adding window size
optionsLinux64.addArguments("window-size=1024x780");

How to run selenium tests on chrome if only binary file of chrome is placed in a server location in E drive

I have a situation in my project as below :
My code was executing as expected till the IT admin uninstalled chrome and FF from Jenkins server.
After raising a concern they placed a chrome binary in E drive .( E:\GC Local\GoogleChrome).But Chrome is not installed anywhere
I am facing issues to resolve this.
Do anyone guide here ?
Code I used :
if ("chrome".equals(browser))
{
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\\src\\test\\resources\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
options.addArguments("--start-maximized");
driver = new ChromeDriver(options);
}
Will it work for you ?
ChromeOptions options = new ChromeOptions();
options.setBinary("E:\\GC Local\\GoogleChrome");
I understand that in homepath \app data chrome should be installed by default to run chrome tests. In my case , there is no chrome istalled in homepath-app but in E drive
When I used the below code :
ChromeOptions options = new ChromeOptions();
options.setBinary("E:\\GCLocal\\GoogleChrome\\GoogleChromePortable.exe");
// System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Browsers\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")
+ "\\src\\test\\resources\\drivers\\chromedriver.exe");
driver = new ChromeDriver(options);
I am getting getting the following :
T E S T S
Running TestSuite
Browser :chrome
Starting ChromeDriver 2.29.461591 (62ebf098771772160f391d75e589dc567915b233) on port 45594
Only local connections are allowed.
Error in initializing the Test .Details :-
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 62.74 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'WHIS2002', ip: '10.192.129.112', os.name: 'Windows Server 2008 R2', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.chrome.ChromeDriver
./TestReport.html
The above approach is correct. My issue was that portable-chrome binary refused to open due to some issues in server .code was fine.
This happened because of portable chrome binary performance issues which I solved like this :
Google Chrome Portable may run slowly from some flash drives. You can speed this up by copying GoogleChromePortable.ini from the GoogleChromePortable\Other\Source directory to the GoogleChromePortable directory and editing it to set RunLocally=true. If you do so, be sure to allow Google Chrome Portable time to copy your profile back after shutting it down. Of course, there are privacy implications to copying your personal data locally to a PC not under your control.
Thanks

ChromeDriver needs a Chrome installation?

I have the following code:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
webDriver = new ChromeDriver(chromeOptions);
It throws the exception:
Gtk-Message: Failed to load module "topmenu-gtk-module"
Created new window in existing browser session.
Exception in thread "main" org.openqa.selenium.WebDriverException:
Timed out waiting for driver server to start.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'luis', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-87-generic', java.version: '1.8.0_112'
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:193)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:181)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
I'm new to this, am I missing something? Should be any other server running in my host?
First of all if you want to use chrome then you need to download it's binary from below URL :-
https://sites.google.com/a/chromium.org/chromedriver/
Now add System.setPropertybefore driver instance
System.setProperty("webdriver.chrome.driver","D:\\Workspace\\JmeterWebdriverProject\\src\\lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
Nowif you want to use headless then use phantomjs. It is a stable build with you can use for your headleass jobs. donwload it from below link :-
http://phantomjs.org/download.html
Now add System.setPropertybefore driver instance
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // not really needed: JS enabled by default
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:/phantomjs.exe");
WebDriver driver = new PhantomJSDriver(caps);
refer the link below for more info :-
http://seleniumworks.blogspot.in/2013/03/headless-browser-testing-using.html
Hope it will help you :)

Categories

Resources