Chrome not reachable error when running Selenium test on Linux

I recently faced a Chrome not reachable error while running a Selenium test in Chrome browser on a Ubuntu machine. I had a hard time isolating the problem because I was trying to get setup with Chrome driver on Ubuntu as part of a Docker image.

Problem:

selenium.common.exceptions.WebDriverException: Message: chrome not reachableChrome Not reachable Issue


Solution:

Initially, I suspected the error is because of the below issues:
1. Xvfb display, not getting set properly
2. Chrome driver version/environment issue

Even after making sure that these were set properly I still got this error. After quite a bit of Googling, I came across this particular StackOverflow solution which helped me resolve my issue. The solution was to add a couple of arguments (no-sandbox, disable-setuid-sandbox) when starting up Chrome.

Since I did not understand the solution, I got more info on what Chrome’s Linux sandbox means from this link. The Chrome-Sandbox SUID Helper Binary launches when Chrome does and sets up the sandbox environment. The sandbox environment is meant to be restrictive to the file system and other processes, attempting to isolate various Chrome parts (such as the renderer) from the system.

Adding arguments to disable the sandbox and no sandbox helped me get past my issue and running my tests again

#Selenium script to print the title of http://qxf2.com
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
 
chrome_options = Options()
#argument to switch off suid sandBox and no sandBox in Chrome 
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-setuid-sandbox")
 
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://qxf2.com')
print driver.title
driver.quit()

Hope this post helps you get past the Chrome not reachable error. Happy testing!

Avinash Shetty
I am a software tester with over 10 years of experience in software testing. Currently I am working at Qxf2 Services Bangalore. As a student of the context-driven approach to software testing I feel there is a lot to learn out there which keeps me very excited. My work has helped me gain good experience in different areas of testing like CRM, Web, Mobile and Database testing. I have good knowledge of building test scripts using Automation tools like Selenium and Appium using Java and Python. Beside testing I am a “Sports Fanatic” and love watching and playing sports.

© 2013-2017, Avinash Shetty. All rights reserved.

2 Comments

  1. Pradeep said:

    Hi Avinash,
    Thanks for the detailed articled. I’ve been facing this issue intermittently for few days now and the frequency has just increased. I’m running my scripts on Windows and the below code worked for me.
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument(‘–no-sandbox’)
    driver=webdriver.Chrome(“C:\\Python27\\Scripts\\chromedriver.exe”,chrome_options=chrome_options)

    Also the below thread on stack overflow helped.
    https://stackoverflow.com/questions/43008622/python-linux-selenium-chrome-not-reachable.

    But i see that sometimes even the above solution sometimes doesn’t work( 1 out of 4 times). I’m still monitoring it. Have you faced any such issue after this solution?

    November 14, 2017
    Reply

Leave a Reply

Your email address will not be published.