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 reachable
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!
If you are a startup finding it hard to hire technical QA engineers, learn more about Qxf2 Services.
I am a dedicated quality assurance professional with a true passion for ensuring product quality and driving efficient testing processes. Throughout my career, I have gained extensive expertise in various testing domains, showcasing my versatility in testing diverse applications such as CRM, Web, Mobile, Database, and Machine Learning-based applications. What sets me apart is my ability to develop robust test scripts, ensure comprehensive test coverage, and efficiently report defects. With experience in managing teams and leading testing-related activities, I foster collaboration and drive efficiency within projects. Proficient in tools like Selenium, Appium, Mechanize, Requests, Postman, Runscope, Gatling, Locust, Jenkins, CircleCI, Docker, and Grafana, I stay up-to-date with the latest advancements in the field to deliver exceptional software products. Outside of work, I find joy and inspiration in sports, maintaining a balanced lifestyle.
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?
Hi Pradeep,
We haven’t faced this issue in Windows but got it in Linux box. we need the complete error message which you get. This may be one of the causes.You can refer this URL.
https://stackoverflow.com/questions/23014220/webdriver-randomly-produces-chrome-not-reachable-on-linux-tests.
Hi Avinash,
Thanks for the tip. I’m having the exactly same problem. Sorry to say but adding chrome_options did not solve the issue. I’m running a freshly installed Ubuntu 16.04 and Chrome, chromedriver and selenium are installed. The problem occurs both with Python 2.7 and 3.4.
SOLVED!
Figuring out that the problem is not reaching Chrome, I started Chrome from my X. It did not start… so I thought that maybe there is a problem because I have Chromium web browser open. So, I closed Chromium and started Chrome, and it started.
Then I ran the python script to test the connection and… tadaa… it WORKED!! :))
Funnily, after that I can have Chromium open, and the script works anyway. So, I really don’t know why.
By the way, I didn’t need setting the chrome_options parameters, at all. It works quite well without any of them.
Just thought I would let you know…:))
hey this works for WSL issue with chromedriver and selenium-python. I was trying to access a website but kept getting “chrome not reachable”. Thanks!
Hi Stanlin,
You tried to run a Selenium test on WSL & keep getting chrome not reachable?
Dude, you just made my day.
HUGE THANKS!
Thank you avinash!
i have set up on remote server, and my config is:
options = webdriver.ChromeOptions()
# options.headless = True
options.add_argument(“–disable-infobars”)
# options.binary_location = binary_path
options.add_argument(“–no-sandbox”)
options.add_argument(“–disable-setuid-sandbox”)
options.add_argument(“start-maximized”)
options.add_argument(“–disable-extensions”)
options.add_argument(“–start-maximized”)
options.add_argument(“–headless”)
options.add_argument(“–disable-popup-blocking”)
options.add_argument(‘window-size=1920×1480’)
self.driver = webdriver.Chrome(executable_path = binary_path, chrome_options=options)
but not working for me
Hi Nakul,
Can you share details of the error?
Regards,
Rohini