WebDriverException: Message: chrome not reachable - selenium

I use Selenium Python,
when I run my crawler I got this error
WebDriverException: Message: chrome not reachable
(Driver info: chromedriver=2.9.248304,platform=Linux 3.16.0-4-amd64 x86_64)
I read this question
I downloaded chromedriver (binary) and I copy/paste it to /usr/bin
I tried by
driver = webdriver.Chrome('/usr/bin/chromedriver')
but I have the same error

In your protractor.configuration file, if you have the following:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'binary': 'path/to/chromedriver.exe';
} },
Then please remove that binary and instead point to the chromdriver like this:
//protractor.conf.js
chromeDriver: "C:/path/to/chromedriver.exe",
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
}
},
Notice how I removed the 'binary' argument from the capabilities and added the "chromedriver:" attribute.
That worked for me in removing that annoying error that says "
UnknownError: chrome not reachable
28-Jul-2016 10:16:57
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),
platform=Windows NT 10.0 x86_64)
(WARNING: The server did not provide any stacktrace information)
Lastly makes sure you update both chromedriver and seleniumServer like this:
webdriver-manager update
OR
Run this command below to update to a SPECIFIC chromedriver version i.e v2.24 as of 10/04/2016:
webdriver-manager update --versions.chrome 2.24
if it says that the command is not recognized, then add it to your PATH in windows environment variable. The webdriver-manager generally sits in the Protractor folder which you can get with npm install protractor

Related

Selenium::WebDriver::Error Chrome Crashed on M1 chip

I've spent several days trying to solve this issue I'm encountering with the following code:
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
:args => ['--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36 LegalMonsterNoBlock"']
}
)
driver = Selenium::WebDriver.for :remote, url: selenium_host, :desired_capabilities => caps
driver.get(url)
I'm trying to run a test that calls this method. The test runs fine. It opens up Chrome runs the test, but whenever I reach the part of my application that calls the above method, the test fails with the following error:
Minitest::UnexpectedError: Selenium::WebDriver::Error::UnknownError: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: '7a6aaccda364', ip: '172.17.0.2', os.name: 'Linux', os.arch: 'amd64', os.version: '4.19.121-linuxkit', java.version: '1.8.0_232'
Driver info: driver.version: unknown
remote stacktrace: #0 0x0040004b6479 <unknown>
My setup:
Macbook with Apple M1, running Big Sur 11.2.2
ruby version 2.7.2
ChromeDriver 89.0.4389.23 (for m1 chip)
Chrome version 89.0.4389.72 (Official Build) (arm64)
gem selenium-webdriver version 3.142.3
Running a docker selenium/standalone-chrome-debug:3.141.59-zinc
I have tried several things already:
Adding --headless, --no-sandbox options to args: args => ['--headless', '--no-sandbox' ...
Installing chromedriver and chrome via brew instead of downloading binary
Reinstalling chrome and chromedriver
Explicitly speficying path to both chrome and chromedriver (Selenium::WebDriver::Chrome.path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' and Selenium::WebDriver::Chrome.driver_path="/path/to/chrome_driver_binary/chromedriver")
Any other experiencing such issues?
It turned out that it is my docker image, that does not support the arm64-architecture, so it was this step:
Running a docker selenium/standalone-chrome-debug:3.141.59-zinc.
There was no issue if I disabled the part of the tests that used the docker container. I imagine this is no possible for everyone, but lets hope that there'll be a selenium image that will support arm64 architecture soon.
See Selenium issue here.
For me using a docker image compatible with the arm64 architecture solved the issue. It was easy to set it up after understanding the problem using an image from https://hub.docker.com/u/seleniarm
I just run the command
docker run -d -p 4444:4444 seleniarm/standalone-chromium
This set it up where I needed and worked just fine.
I had the same error when I was trying to run in a docker using the below command.
docker run -d -p 4444:4444 selenium/standalone-chrome
My solution was mentioned in the github answer for the issue posted above and the link to the answer so we can give the proper credits is this:
https://github.com/SeleniumHQ/docker-selenium/issues/1076#issuecomment-788343926
Hope this sheds some light for others.

Adjust protractor config to debug in non-headless mode

When executing the protractor test, it succeeds in --headless mode, but when I remove the --headless option, it fails stating: the user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir.
As you can see, I'm not using that particular argument, so I'm not what to do about this.
Update: When the crome browser tab opens, data:, is in the address bar.
Error
$ protractor conf.js
[14:10:17] I/launcher - Running 1 instances of WebDriver
[14:10:17] I/direct - Using ChromeDriver directly...
[14:10:18] E/launcher - 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
(Driver info: chromedriver=79.0.3945.16 (93fcc21110c10dbbd49bbff8f472335360e31d05-refs/branch-heads/3945#{#262}),platform=Windows NT 10.0.17763 x86_64)
[14:10:18] E/launcher - WebDriverError: 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
(Driver info: chromedriver=79.0.3945.16 (93fcc21110c10dbbd49bbff8f472335360e31d05-refs/branch-heads/3945#{#262}),platform=Windows NT 10.0.17763 x86_64)
at Object.checkLegacyResponse (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
at parseHttpResponse (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
at C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\selenium-webdriver\lib\http.js:441:30
at processTicksAndRejections (internal/process/task_queues.js:93:5)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:761:15)
at Direct.getNewDriver (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\built\driverProviders\direct.js:77:33)
at Runner.createBrowser (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\built\runner.js:195:43)
at C:\Install\node-v12.13.1-win-x64\node_modules\protractor\built\runner.js:339:29
at _fulfilled (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\q\q.js:834:54)
at C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\q\q.js:863:30
at Promise.promise.promiseDispatch (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\q\q.js:796:13)
at C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\q\q.js:556:49
at runSingle (C:\Install\node-v12.13.1-win-x64\node_modules\protractor\node_modules\q\q.js:137:13)
[14:10:18] E/launcher - Process exited with error code 199
Config
exports.config = {
chromeOnly: true,
directConnect: true,
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['--no-sandbox', "--headless", "--disable-gpu", "--window-size=800,600"]
},
},
specs: ['login.jenkins.js']
};
The reason for this error is that there are multiple chrome browser instances running on different profiles. When protractor starts your tests, chrome creates a default profile and runs your tests on that profile. If there are multiple chrome instances running, chrome will ask for your user defined profile in the --user-data-dir argument.
This means that you should make sure that there are no pending processes of chrome running before you start your tests. Check for running processes and remove those processes. Then make sure you add an onComplete section like below in your configuration file so that your chrome browser instance is closed after your tests are done. Here is the code snippet.
onComplete: async () => {
await browser.driver.close();
await browser.driver.quit();
}
Try it out once! Might solve the problem you are facing.

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

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.

selenium-side-runner is failing for Chrome, ran through fine with Firefox

I'm trying out the command line runner of Selenium IDE selenium-side-runner on a .side file.
I can open this .side file in Selenium IDE and run the test suite, it can execute just fine, but when running the command line runner i get this error.
myuser#mycomputer [10:02:36] $ selenium-side-runner --debug selenium/seleniumtesting.side
debug: Could not load /Users/myuser/projects/selenium/.side.yml
debug: { capabilities: { browserName: 'chrome' },
params: {},
runId: 'a508a80619537b4ac9c18368857f84f2',
path: '/usr/local/lib/node_modules/',
server: undefined,
timeout: 15000,
baseUrl: undefined }
info: Running selenium/seleniumtesting.side
debug: jest worker args
debug: 0=--no-watchman, 1=--testMatch, 2={**/***/*.test.js,**/***.test.js}
debug: jest work opts
debug: cwd=/Users/myuser/projects/selenium/side-suite-seleniumtesting, stdio=inherit
FAIL ./BasicFullCheckoutflow.test.js (6.314s)
Basic Full Checkout flow
✕ 2. Add product to the cart (3035ms)
✓ 3. Checkout (1530ms)
● Basic Full Checkout flow › 2. Add product to the cart
StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.3 x86_64)
at Object.checkLegacyResponse (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/error.js:585:15)
at parseHttpResponse (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:533:13)
at Executor.execute (../../../../../../usr/local/lib/node_modules/selenium-side-runner/node_modules/selenium-webdriver/lib/http.js:468:26)
UPDATE: This is only happening for chrome webdriver, when i run with firefox it went through fine
selenium-side-runner -c "browserName=firefox" selenium/seleniumtesting.side
Try in headless mode with below options:-
selenium-side-runner -c "browserName=chrome chromeOptions.args=[headless,no-sandbox,disable-dev-shm-usage]" selenium/seleniumtesting.side

Chrome driver not working on centos 7

I m unable to run my test cases using chrome browser on centos 7. i m using chromedriver version 2.30.477691
and chrome binary version
# google-chrome -version
Google Chrome 59.0.3071.109
running the testcases with root so tried --no-sandbox option didnt work . also tried with no such options in command line.
Please help.
[root#Server ~]# time xvfb-run -a -s "-screen 0 1024x768x24" java
-jar Project.jar -Dwebdriver.chrome.binary=/usr/bin/google-chrome --no-sandbox
Starting ChromeDriver 2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57) on port 26527 Only local connections are allowed. Exception in thread "main" org.openqa.selenium.WebDriverException: chrome not reachable (Driver info: chromedriver=2.30.477691 (6ee44a7247c639c0703f291d320bdf05c1531b57),platform=Linux
3.10.0-514.21.1.el7.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout:
114.41 seconds