session not created: Chrome version must be between 71 and 75 [duplicate] - selenium

After update of chromedriver to version 2.46 my tasts fail to initialize.
I got message like this:
Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 44269
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Failed to invoke configuration method com.personal.CustomTest.initTests not created: Chrome version must be between 71 and 75
(Driver info: chromedriver=2.46.628402,platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.58 seconds
Build info: version: '2.53.1'
It is clearly saying that my browser version is not valid. But I am using Chrome 72.0.3626.119 so it is between 71 and 75.
Selenium version is 2.53.1.
And I am running test through console command with the help of testNG.
Any idea? Every ideas that I found was about changing selenium version but I cant do it.

For me to resolve this problem :
On Windows
cd C:\Users\[myname]\AppData\Roaming\npm\node_modules\protractor
npm i webdriver-manager#latest
webdriver-manager update
webdriver-manager start &
On Cent-OS (I used Cent-OS 7.4.* and it worked fine.)
cd /usr/lib/node_modules/protractor/
sudo npm i webdriver-manager#latest
sudo webdriver-manager update
sudo webdriver-manager start &
I hope this helps you in any way.

This error message...
Starting ChromeDriver 2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1) on port 44269
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Failed to invoke configuration method com.personal.CustomTest.initTests not created: Chrome version must be between 71 and 75
...implies that the ChromeDriver v2.46 is not compatible with the Chrome Browser version which is being accessed by your program/webdriver.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.46
Release Notes of chromedriver=2.46 clearly mentions the following :
Supports Chrome v71-73
Though you mentioned you are using Chrome 72.0.3626.119 possibly there are multiple instances of Chrome Browser installed within your system and your program by default is accessing the Chrome Browser whose version is not between v71.x and v75.x
You are using chrome=67.0
Release Notes of ChromeDriver v2.38 clearly mentions the following :
Supports Chrome v65-67
Solution
Keep JDK upgraded to recent levels JDK 8u201.
Uninstall all the instances of Chrome Browser (you can opt to use Revo Uninstaller).
Upgrade ChromeDriver to current ChromeDriver v2.46 level.
Keep Chrome version between Chrome v71-73 levels. (as per ChromeDriver v2.46 release notes)

For me, I had to update my chrome driver in my project to match the version of Chrome on my local machine.
yarn add chromedriver#76.0.0 -D
https://www.npmjs.com/package/chromedriver

In my case I was getting the same error after my chrome was updated to version 76. Which was happening when chimp tries to use chromedriver to execute the selenium test.
DevTools listening on ws://127.0.0.1:49220/devtools/browser/e88586cb-ed67-44fc-a742-43b767e2b8f9
[chimp][helper] setupBrowserAndDDP had error
{ Error: session not created: Chrome version must be between 71 and 75
at Object.wait (C:\ACPMS\ELS_AT\node_modules\fibers\future.js:449:15)
at Object.<anonymous> (C:\ACPMS\ELS_AT\node_modules\wdio-sync\build\index.js:344:27)
at Object.<anonymous> (C:\ACPMS\ELS_AT\node_modules\chimp\dist\lib\session-manager.js:145:21)
at initBrowser (C:\ACPMS\ELS_AT\node_modules\chimp\dist\lib\chimp-helper.js:189:43)
at Object.setupBrowserAndDDP (C:\ACPMS\ELS_AT\node_modules\chimp\dist\lib\chimp-helper.js:264:7)
at Context.<anonymous> (C:\ACPMS\ELS_AT\node_modules\chimp\dist\lib\mocha\mocha-helper.js:13:15)
at C:\ACPMS\ELS_AT\node_modules\chimp\dist\lib\utils\fiberize.js:29:22
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.17134 x86_64)
at new RuntimeError (C:\ACPMS\ELS_AT\node_modules\webdriverio\build\lib\utils\ErrorHandler.js:143:12)
at Request._callback (C:\ACPMS\ELS_AT\node_modules\webdriverio\build\lib\utils\RequestHandler.js:318:39)
at Request.self.callback (C:\ACPMS\ELS_AT\node_modules\request\request.js:185:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (C:\ACPMS\ELS_AT\node_modules\request\request.js:1161:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous>
For me it didn't work when I updated the chrome driver by npm (both globally and locally) and then I followed these steps to resolve the issue, which might give some idea on where to check in this kind a issue:
Because exception was thrown in node_modules\chimp\dist\lib\utils\fiberize.js i navigated to that file and found one level above this file node_modules\chimp\dist\lib\chromedriver.js which has the code to start chromedriver.
I added a console.log to chromedriverPath which can be seen below and re-executed the tests to get the chromedriver path in console logs.
Chromedriver.prototype.start = function(callback) {
var self = this;
var port = self.options.port;
if (this.child) {
callback();
return;
}
var chromedriverPath = chromedriver.path;
//this was added my me the see that chrome drive path
console.log("[chimp] " + chromedriverPath);
if (fs.existsSync(chromedriverPath)) {
this.child = processHelper.start(
{
bin: chromedriverPath,
prefix: "chromedriver",
args: ["--port=" + port, "--url-base=wd/hub"],
waitForMessage: /Starting ChromeDriver/,
errorMessage: /Error/
},
callback
);
} else {
callback("[chimp][chromedriver] Chromedriver executable not found.");
}
};
When i got the path of the chromedriver which is used to execute the tests, i just navigated to that folder and replaced chromedriver executable with the most recent version.
I hope this helps.

Try this: Download the compatible ChromeDriver.exe file for the updated version of Chrome browser and replace it. It works for me.

Related

Sidekiq job getting Selenium::WebDriver::Error::UnknownError: invalid argument: can't kill an exited process (but only when run async) [duplicate]

Server: Raspberry Pi 3
OS: Dietpi - version 159
Geckodriver version: 0.22 for arm
Firefox version: 52.9.0
Python version: 3.5
Selenium version: 3.14.1
Gecko is executable, and is located in /usr/local/bin/
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time
options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)
print('Need your login credential')
username = input('What is your username?:\n')
password = input('What is your password?:\n')
...
...
Output:
root#RPi3:~# python3.5 ITE-bot.py
Traceback (most recent call last):
File "ITE-bot.py", line 12, in <module>
driver = webdriver.Firefox(firefox_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
keep_alive=True)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
Any idea what is wrong? I've tried google without luck.
If you are running Firefox on a system with no display, make sure you use headless mode.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Also, make sure you have compatible versions of Firefox, Selenium, and Geckodriver:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html
Thumb rule
A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.
This error message...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Your GeckoDriver version is 0.22.0.
Release Notes of GeckoDriver v0.21.0 (2018-06-15) clearly mentions the following:
Firefox 57 (and greater)
Selenium 3.11 (and greater)
Your Firefox version is 52.9.0.
So there is a clear mismatch between GeckoDriver v0.22.0 and the Firefox Browser v57
Solution
Upgrade GeckoDriver to GeckoDriver v0.22.0 level.
GeckoDriver is present in the specified location.
GeckoDriver is having executable permission for non-root users.
Upgrade Firefox version to Firefox v62.0.2 levels.
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 through Revo Uninstaller and install a recent GA and released version of Web Client.
Execute your Selenium Test as a non-root user.
GeckoDriver, Selenium and Firefox Browser compatibility chart
I was on headless mode, using correct versions of everything, and the only way to get out of this error message was not to execute the selenium test as root
Yes checked Start Xvfb before the build can fix the problem, but if you have a job like a pipeline or multibranch pipeline this option is not visible. In the node of your Selenium grid that you go to execute the test you need:
1- Install Xvfb: apt install xvfb
2- Execute Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
3- Rerun your node, for example: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991
This solution worked for me
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
As there can be many different underlying causes for this error it is best to find the root cause setting selenium to use debug level logging. In my case, for Ruby with capybara I needed to set: Selenium::WebDriver.logger.level = :debug. And voilĂ , running the same spec I could see in the logs that a dependency was missing, in my case:
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
After installing it all worked fine.
I used:
VS Code
Linunx/Ubuntu:18.10
Nightwatch.js
My problem was that I tried to run Nightwatch (which automatically starts GeckoDriver) from the VS Code terminal.
I had the same problem, and realized that the real problem was some firefox dependencies not being installed inside the docker container I was testing in.
Try to initiate firefox and check if it returns an error.
As Nico and jay have stated you need to check the logs to see the details of the error. As you might use different systems, you can specify the path where the log is stored (i.e. "/tmp/geckodriver.log").
from selenium import webdriver
firefox_options = webdriver.firefox.webdriver.Options()
driver = webdriver.Firefox(log_path="/tmp/geckodriver.log",
options=firefox_options)
In my particular case, what the log said was:
Error: no DISPLAY environment variable specified
That was resolved adding in the options the headless mode before starting the driver. With the line:
firefox_options.set_headless()
I was able to fix this by running my tests with Xvfb. I was running them on a remote server.
I was using Jenkins so I checked the box that looked like this:
Credit to https://www.obeythetestinggoat.com/book/chapter_CI.html
in my case, I was running test cases as root
geckodriver.log
1576076416677 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenCbl2e"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
1576077143004 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7wpSQ7"
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: telemetry
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1576077143689 addons.webextension.screenshots#mozilla.org WARN Loading extension 'screenshots#mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1576077145372 Marionette INFO Listening on port 35571
1576077145423 Marionette WARN TLS certificate errors will be ignored for this session
1576077200207 mozrunner::runner INFO Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenhoHlr"
Running Firefox as root in a regular user's session is not supported. ($HOME is /home/seluser which is owned by seluser.)
i could get around by
cd /home
chown -R root seluser
i woundnt say its correct but it got my job done

Chrome failed to start: crashed. from crontab [duplicate]

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.
from selenium import webdriver
d = webdriver.Chrome('/home/PycharmProjects/chromedriver')
d.get('https://www.google.nl/')
i get the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)
i have the latest chrome version and chromedriver installed
EDIT:
After trying #b0sss solution i am getting the following error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
Try to download HERE and use this latest chrome driver version:
https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Solution
In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Python Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe" #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
Java Solution:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); //chrome binary location specified here
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
hope this helps someone. this worked for me on Ubuntu 18.10
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()
I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome-stable is
no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried running chrome locally /usr/bin/google-chrome-stable, error message
Running as root without --no-sandbox is not supported
I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)
I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')
For RobotFramework
I solved it! using --no-sandbox
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Instead of
Open Browser about:blank headlesschrome
Open Browser about:blank chrome
Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.
If you close all tabs and run again, the error should clear up.
in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:
opts.set_headless(True)
A simple solution that no one else has said but worked for me was not running without sudo or not as root.
The solutions that every body provide here is good for Clear the face of the issue but
All you need to solve this problem is that You have to run The App on non-root user
on linux.
According to this post
https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321
I had the same problem but it was solved just by reinstalling chrome again with the commands below:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.
Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.
It solved the issue I was having; not elegantly but it works.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
try:
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
print("\nChrome crashed on launch:")
print(e)
print("Trying again in 10 seconds..")
sleep(10)
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
print("Success!\n")
except Exception as e:
raise Exception(e)
I came across this error on linux environment. If not using headless then you will need
from sys import platform
if platform != 'win32':
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger.
First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.
In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.
The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:
Just do not run the script as the root user (in my case).
i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.
i faced the same problem but i solved it by moving the chromedriver to this path
'/opt/google/chrome/'
and this code works correctly
from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')
In my case, chrome was broken. following two lines fixed the issue,
apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install
Fixed it buy killing all the chrome processeses running in the remote server before running my script.
That may explain why some answers that recommend you run your script as root works.
$ pkill -9 chrome
$ ./my_script.py
Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.
For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.
Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version.
Versions at the time of the initial error:
# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77
I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:
# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16
However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.
sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable
wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin
After that, my Selenium calls were able to work again. The final version combo:
# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71
Make sure that both the chromedriver and google-chrome executable have execute permissions
sudo chmod -x "/usr/bin/chromedriver"
sudo chmod -x "/usr/bin/google-chrome"

Jenkins run causes Selenium tests to fail with org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally?

I'm running Selenium tests for Chrome through Jenkins pipeline on CentOs machine. When ran, it gives following error -
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally
[testng] (unknown error: DevToolsActivePort file doesn't exist)
[testng] (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
However if I run same tests with same command(which is used through Jenkins pipeline) from that machine locally, it succeeds.
For the same, I went through link1, link2, link3 and other answers. From those answers, only following helped -
chrome_options.add_argument('--headless')
But this run tests with chrome in headless mode which is not my intention.
In my case, having matching Chrome browser and chromedriver version did not help, also Chrome has executable permission for all.
Note: I've my CentOs machine display enabled
Could you please help to understand what is causing this failure? Also please help with what code and/or machine level changes I've to make for its success.
EDIT:
In case, this helps to get more info.
ls | grep 'chrome' under /usr/bin gave following result -
lrwxrwxrwx 1 root root 31 Jan 20 12:29 google-chrome -> /etc/alternatives/google-chrome
lrwxrwxrwx 1 root root 32 Jan 20 12:29 google-chrome-stable -> /opt/google/chrome/google-chrome
Do you run chromedriver locally on a linux machine? What version of CentOS are you using? If you haven't already you need to install the correct chromedriver for linux. As far as I know if you want to run via Jenkins you have to run in headless mode. But I may be wrong. Below is another post that can help:
Steps to Install and run headless chrome browser on centos 6.5 using chrome driver
Below are my own settings for chrome options:
options.addArguments("--headless");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--window-size=1920,1080");
options.addArguments("start-maximized");
options.addArguments("enable-automation");
options.addArguments("--disable-infobars");
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
options.addArguments("--force-device-scale-factor=1");

Chrome failed to start: exited abnormally through Jenkins on Ubuntu? [duplicate]

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.
from selenium import webdriver
d = webdriver.Chrome('/home/PycharmProjects/chromedriver')
d.get('https://www.google.nl/')
i get the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)
i have the latest chrome version and chromedriver installed
EDIT:
After trying #b0sss solution i am getting the following error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
Try to download HERE and use this latest chrome driver version:
https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Solution
In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Python Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe" #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
Java Solution:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); //chrome binary location specified here
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
hope this helps someone. this worked for me on Ubuntu 18.10
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()
I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome-stable is
no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried running chrome locally /usr/bin/google-chrome-stable, error message
Running as root without --no-sandbox is not supported
I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)
I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')
For RobotFramework
I solved it! using --no-sandbox
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Instead of
Open Browser about:blank headlesschrome
Open Browser about:blank chrome
Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.
If you close all tabs and run again, the error should clear up.
in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:
opts.set_headless(True)
A simple solution that no one else has said but worked for me was not running without sudo or not as root.
The solutions that every body provide here is good for Clear the face of the issue but
All you need to solve this problem is that You have to run The App on non-root user
on linux.
According to this post
https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321
I had the same problem but it was solved just by reinstalling chrome again with the commands below:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.
Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.
It solved the issue I was having; not elegantly but it works.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
try:
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
print("\nChrome crashed on launch:")
print(e)
print("Trying again in 10 seconds..")
sleep(10)
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
print("Success!\n")
except Exception as e:
raise Exception(e)
I came across this error on linux environment. If not using headless then you will need
from sys import platform
if platform != 'win32':
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger.
First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.
In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.
The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:
Just do not run the script as the root user (in my case).
i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.
i faced the same problem but i solved it by moving the chromedriver to this path
'/opt/google/chrome/'
and this code works correctly
from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')
In my case, chrome was broken. following two lines fixed the issue,
apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install
Fixed it buy killing all the chrome processeses running in the remote server before running my script.
That may explain why some answers that recommend you run your script as root works.
$ pkill -9 chrome
$ ./my_script.py
Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.
For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.
Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version.
Versions at the time of the initial error:
# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77
I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:
# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16
However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.
sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable
wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin
After that, my Selenium calls were able to work again. The final version combo:
# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71
Make sure that both the chromedriver and google-chrome executable have execute permissions
sudo chmod -x "/usr/bin/chromedriver"
sudo chmod -x "/usr/bin/google-chrome"

NightWatch Selenium Socket Hangup in Jenkins / Ubuntu16

Issue :
We are running NightWatch tests in Jenkins, and once in a while, we get this error :
[0;31mConnection refused! Is selenium server started?
[0m[0;90m{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at Socket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:501:12) code: 'ECONNRESET' }[0m
The fix recommended in other places is already there :
export DBUS_SESSION_BUS_ADDRESS=/dev/null
This is how we run the tests :
sudo npm install selenium-standalone -g
selenium-standalone install --version=3.0.1 --baseURL=https://selenium-release.storage.googleapis.com --drivers.chrome.version=2.28 --drivers.chrome.baseURL=https://chromedriver.storage.googleapis.com --basePath=bin
sudo npm install nightwatch#0.9.13 -g && nightwatch --tag sanity --retries 1 --suiteRetries 1
Rebuilding the job usually run the tests successfully.
Softwares' version:
Chrome : 57
Chrome driver : 2.28
Selenium: 3.0.1
NightWatch : 0.9.13 (bumped down from 0.9.14 in case the latest release had a bug but no change.)
Jenkins : 1.6x
Ubuntu : 16.04
Using xvfb
Error Scenarios
The tests were running fine until about 2 weeks ago, just when we switched to Ubuntu 16, but that day it started happening on Ubuntu 14 too.
It especially happens when we've just spun a new Jenkins slave (on AWS cloud.) Happens more often at the very start of the test run but sometimes it happens in the middle of the run too.
I'll appreciate any help or pointers!
I have the same problem yesterday.
Maybe you can change the version of Chrome.
such as Chrome:55.
when i changed the version of chrome the selenium
We ran into a similar issue, but our error message was more specific:
Selenium is already running on port ####. Or some other service is.
The solution was to use the Jenkins Port Allocator Plugin to assign an available port number to an environment variable.
From there, we were able to set the port number in our globals.js like this (with a default of 4444 for running locally):
portNumber: process.env.PORT_NUMBER || 4444,
In our nightwatch.conf.js file, we used a lodash template to replace values in our nightwatch.json like this:
fs = require('fs'),
_ = require('lodash'),
template = _.template(fs.readFileSync('./nightwatch.json', 'utf8')),
settingsString,
settings;
settingsString = template({
portNumber: globals.portNumber
});
settings = JSON.parse(settingsString);
module.exports = settings;
Finally, in our nightwatch.conf file, we set the values for all port references to:
"<%= portNumber %>"