4

I am running following python3 script on ubuntu

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')  # Last I checked this was necessary.
driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)

Running as normal user, I am getting following error:

$ python3 getStock.py
Traceback (most recent call last):
File "getStock.py", line 61, in <module>
    driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, 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: unknown error: chrome failed to start
(Driver info: chromedriver=2.38.551591 (bcc4a2cdef0f6b942b2bb8049068f65340fa2a69),platform=Linux 4.2.0-042stab120.16 x86_64)

Trying with sudo also; still I am getting following error

$ sudo python3 getStock.py
[sudo] password for admin:
Traceback (most recent call last):
File "getStock.py", line 61, in <module>
    driver = webdriver.Chrome("/home/admin/web/web.com/public_html/scripts/az/chromedriver", chrome_options=options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, 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: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.38.551591 (bcc4a2cdef0f6b942b2bb8049068f65340fa2a69),platform=Linux 4.2.0-042stab120.16 x86_64)

Not sure what is going on? I have tried following;

  1. I have tried updating selenium;
  2. I have tried running as python 2.x and python 3.x
  3. I have tried running the script as a normal user and sudo user
  4. I have tried changing the permissions to even chmod 777

Here are my versions:

Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial

Python 3.5.2
Requirement already satisfied: selenium in /usr/local/lib/python3.5/dist-packages (3.11.0)
2
  • Does adding options.add_argument('--no-sandbox') solve it? Commented Apr 19, 2018 at 23:56
  • for me this was an intermittent issue. closing all other browser instances and rerunning the program fixed it. I don't think r as the accepted answer mentioned makes much of a difference in python3 Commented Dec 24, 2018 at 17:13

3 Answers 3

4

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: chrome failed to start

...implies that your WebClient Chrome failed to start.

Solution

You need to pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver through single forward slash i.e. \ along with the raw i.e. r switch as follows :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
#options.add_argument('--disable-gpu')  # applicable to windows os only
driver = webdriver.Chrome(chrome_options=options, executable_path=r'/home/admin/web/web.com/public_html/scripts/az/chromedriver')

Additional Steps

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Use CCleaner tool to wipe off all the OS chores 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.
Sign up to request clarification or add additional context in comments.

Comments

2

The real error is unknown error: Chrome failed to start: exited abnormally .

Since , you are using chromedriver=2.38.551591.

Just make sure whether you are using correct chromedriver version with respect to the chrome browser installed on your local machine.

Your version of chromedriver works with chrome browser versions > 67.xx

You can refer this page for compatibility references.

Comments

0

this code below is working for me on the same environment (but my chromedriver version is 2.36):

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--window-position=0,0")
options.add_argument("--headless")
driver = webdriver.Chrome("path", chrome_options=options)

Check if it works for you :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.