I am using C# Selenium for automated testing, and after the most recent chromedriver update 89.0.4389.2300, Google chrome starts and crashes right away. The weirdest thing is that when I am running it on my local, everything works fine, but I am also using Azure pipelines to run my tests on a server. The server one gives me this:
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I have googled around and tried things like adding chromeOptions.AddArgument("--no-sandbox") and chromeOptions.AddArguments("disable-dev-shm-usage") but nothing helps. Chrome on my server is updated to the correct version too. The tests run headless.
Anyone else is having this issue?
The error mentions that chromedriver could not bind to open debug port on running Chrome.
Possible cases I met with:
old version of Chrome browser or chromedriver - since some version the port has changed
wrong Chrome binary location (chromedriver is looking for C:\Program Files (x86)\Google\Chrome\Application\chrome.exe)
Related
I have been using chromedriver with selenium using C# and I used to add "options.AddUserProfilePreference("safebrowsing", "enabled");" to options object and everything has been perfect(since almost a year now) until a couple of days ago chrome browser had an update version 93.0.4577.63 so I had to update chrome driver to version 93.0.4577.1500, when I tried to run the scripts, I got this error:
OpenQA.Selenium.WebDriverException : unknown error: Chrome failed to start: crashed.
(unknown error: DevToolsActivePort file doesn't exist)
Note: The error goes away when I remove the option: options.AddUserProfilePreference("safebrowsing", "enabled");
Regards,
Not sure why, but it worked when I changed AddUserProfilePreference method arguments to be like this options.AddUserProfilePreference("safebrowsing.enabled", "true");.
This is most likely a duplicate question, but in my looking around i couldnt find an answer that matches my question exactly.
I am using selenium and NUnit to run unit tests, due to circumstances I have not been working on it for a while, and now that I come back I get this error on all my chrome tests:
OneTimeSetUp: System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 79 (SessionNotCreated)
I have updated the driver to make sure that wasn't the issue, but even using the version 83 one, I still get this same error.
The ChromeDriver in your Windows %PATH% is likely a different version. The updated driver you downloaded needs to be saved over top of the ChromeDriver in your path.
Open the command prompt
Type where ChromeDriver and press Enter.
Save the updated ChromeDriver in the folder specified in the output of the where command.
You should update the ChromeDriver in your project. It might be done via Tools -> NugetPages.
For this same error there are many questions in Stackoverflow. But none of them solved my problem. So I have to post this again.
My Code:
ChromeOptions options = new ChromeOptions();
options.AddArguments("--disable-gpu");
options.AddArguments("--disable-extensions");
options.AddArgument(#"user-data-dir=C:\Users\myname\AppData\Roaming\Chrome\Profile 6");
options.AddArgument("--profile-directory=Profile 6");
IWebDriver driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://google.com");
Initially I was getting an error " Unable to move cache folder, access denied."
then I have added the line options.AddArguments("--disable-gpu"); and the error is gone.
Now my Code is opening the browser with profile : "Profile 6". But after that its throwing the error
Error in the line : IWebDriver driver = new ChromeDriver(options);
"Exception thrown: 'OpenQA.Selenium.WebDriverException' in WebDriver.dll
An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll
invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
"
I have already read almost all topics related to this error. Few of them are :
How to open a Chrome Profile through --user-data-dir argument of Selenium
InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium
How to initiate a new Chrome session when the default session is already running using ChromeDriver and Chrome through Selenium and Python
I am stuck in this problem for more than a week now. Please help.
EDIT:
To confirm that I am not using the already opened default user profile, I checked Cheome://version to confirm the user data directory path. Its different than the default.
Also I tried to to run the code after closing all the open chrome instances. This Time I have not received the error. The browser opened by the webdriver. But after that nothing happened. The code got time out error after 60 seconds in the line : IWebDriver driver = new ChromeDriver(options);
Possibly you are specifying the wrong directory. Instead of:
C:\Users\myname\AppData\Roaming\Chrome\Profile 6
You need to pass:
C:\Users\myname\AppData\Local\Chrome\Profile 6
So the effective line of code will be:
options.AddArgument(#"user-data-dir=C:\Users\myname\AppData\Local\Chrome\Profile 6");
Update 1
Additionally, you can remove the argument --profile-directory as in:
options.AddArgument("--profile-directory=Profile 6");
Update 2
If I close all the chrome instances and run the code, I am not getting this error means ChromeDriver is able to open the Chrome browsing instance perfectly. But to analyze why nothing happened can be interpreted from the TRACE level logs.
Ensure that:
JDK is upgraded to current levels JDK 8u251.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v83.0 level.
Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
My Chrome browser is updated to version 78 and when I tried to execute any code of automation, it shows the error
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
How can I fix it?
This error message...
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
Nov 11, 2019 11:25:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
[1573451709.039][WARNING]: Timed out connecting to Chrome, retrying...
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Analysis
The first log message:
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
is part of the startup log when using ChromeDriver and is informative in nature.
You can find a detailed discussion in How do I protect the ports that chromedriver use?
The following log message:
[1573451703.668][WARNING]: Timed out connecting to Chrome, retrying...
indicates there are some incompatibility between the version of the binaries you are using.
Solution
Ensure that:
JDK is upgraded to current levels JDK 8u222.
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v78.0 level.
Chrome is updated to current Chrome Version 78.0 level. (as per ChromeDriver v78.0 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 and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
I have fixed this issue of timeout / Connection reset by changing my code from:
public void AfterScenario(Scenario sc) {
driver.close();
driver.quit();
driver = null;
}
to:
public void AfterScenario(Scenario sc) {
driver.quit();
driver = null;
}
So basically I removed the driver.close() and this fixed my issue. I do not know why this is happening, but experts can explain more...
I had to update to the dev version of chrome 79 and the latest dev version of chromedriver to make it work. Although I've run against other issues with this version, so I don't know if its a good solution.
Every time I launch Selenium WebDriver on one of my test servers, I'm receiving the following error from the SDK:
System.InvalidOperationException: System.InvalidOperationException:
Unexpected error launching Internet Explorer. IELaunchURL() returned
800700C1 for URL 'http://localhost:5555/' (NoSuchDriver).
The rest of my test servers are not having any trouble. Also, I verified that all of the internet zones were set to protected.
Delete the "C:\Program" file from your system
Answer from https://code.google.com/p/selenium/issues/detail?id=6181
It seems a bit odd, but when I checked, there was a 0 byte "Program" file in the root of the C drive. I deleted the file and the issue went away.