0
votes

I am trying to set up chrome webdriver in ubuntu. I already did

pip install selenium

and I can do

from selenium import webdriver

To install chrome webdriver, I have tried many things. For example, I tired an answer from Can't use chrome driver for Selenium Here, I tried

  1. Check you have installed latest version of chrome browser-> "chromium-browser -version"
  2. If not, install latest version of chrome "sudo apt-get install chromium-browser"
  3. Get the appropriate version of chrome driver from http://chromedriver.storage.googleapis.com/index.html
  4. Unzip the chromedriver.zip
  5. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
  6. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.
  7. finally you can execute the code.

According to it, I could do

from selenium import webdriver
driver = webdriver.Chrome()

However, in the second line I am getting the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/../.local/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/../.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/../.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/../.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/../.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.15.0-109-generic x86_64)

Can anyone help me?

2
Can you start your driver executable manually?Alexey R.
Hi, what do you mean by that?Khabbab Zakaria
I mean that you can run your webdriver executable file as any other executable file in Linux (not from your python code). You need to try to run it and watch if it will report any error.Alexey R.
Maybe try python 3 to see if it worksPhilippe

2 Answers

0
votes

Use webdriver-manager

webdriver-manager

Below 3 lines should do the job for you:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install()) 
0
votes

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.15.0-109-generic x86_64)

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

Your main issue is the incompatibility between the version of the binaries you are using as follows:

  • You are using chromedriver=2.26
  • Release Notes of chromedriver=2.26 clearly mentions the following :

Supports Chrome v53-55

  • Possibly you are using the latest chrome=83.0
  • Release Notes of ChromeDriver v83.0 clearly mentions the following :

Supports Chrome version 83

So there is a clear mismatch between ChromeDriver v2.26 and the Chrome Browser v83.0


Solution

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.