128

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.

from selenium import webdriver

d = webdriver.Chrome('/home/PycharmProjects/chromedriver')

d.get('https://www.google.nl/')

I get the following error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)

I have the latest chrome version and chromedriver installed.

EDIT: After trying @b0sss solution I am getting the following error.

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)

26 Answers 26

188

Try to download HERE and use this latest chrome driver version:

Try this:

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

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
Sign up to request clarification or add additional context in comments.

11 Comments

I have already downloaded the latest chromedriver from that location.
Make sure that --no-sandbox option is the first one (unlike this example, where the first option is --headless. I kept getting that error, until I moved the --no-sandbox to the top of the list, adding it as the first option.
Note: from selenium.webdriver.chrome.options import Options
as far as I know --no-sandbox chrome options argument is enough
you need to match the versions of chromedriver which you use with chromium
|
42

This error message...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

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

Your main issue is the Chrome browser is not installed at the default location within your system.

The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:

Chrome_binary_expected_location

1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


Solution

In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:

  • Python Solution:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location = "C:\\path\\to\\chrome.exe"    #chrome binary location specified here
    options.add_argument("--start-maximized") #open Browser in maximized mode
    options.add_argument("--no-sandbox") #bypass OS security model
    options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
    driver.get('http://google.com/')
    
  • Java Solution:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions opt = new ChromeOptions();
    opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");  //chrome binary location specified here
    options.addArguments("start-maximized");
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(opt);
    driver.get("https://www.google.com/");
    

2 Comments

Setting the chrome binary worked. Gave you best answer. Also completely deleting Chrome/Chromedriver/Pycharm and then reinstalling everything did the trick as well, so now I won't have the set chrome binary.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: was killed. (unknown error: DevToolsActivePort file doesn't exist) I am getting this(killed) instead of crashed now. I have been looking up on the web fro 3+ hours now and nothing seems to be working
21

hope this helps someone. this worked for me on Ubuntu 18.10

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()

2 Comments

Works on raspberry pi 3b+ (os lite) with chromium.
Works, with downloaded driver and driver manager. Though, using the service object fails.
10

I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:

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

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')

1 Comment

isnt, using --no--sandbox option a security issue?
8

I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered

(unknown error: DevToolsActivePort file doesn't exist)
     (The process started from chrome location /usr/bin/google-chrome-stable is 
      no longer running, so ChromeDriver is assuming that Chrome has crashed.)

When I tried running chrome locally /usr/bin/google-chrome-stable, error message

Running as root without --no-sandbox is not supported

I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.

capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
  chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)

1 Comment

Another way to fix this is to not run the process (within the container) as root. This is better from a security perspective, anyway. :)
7

For RobotFramework

I solved it! using --no-sandbox

${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    test-type
Call Method    ${chrome_options}    add_argument    --disable-extensions
Call Method    ${chrome_options}    add_argument    --headless
Call Method    ${chrome_options}    add_argument    --disable-gpu
Call Method    ${chrome_options}    add_argument    --no-sandbox
Create Webdriver    Chrome    chrome_options=${chrome_options}

Instead of

Open Browser    about:blank    headlesschrome
Open Browser    about:blank    chrome

2 Comments

i am also facing the same problem but was a little confused regarding your above comment. can you please help. my current code is SeleniumLibrary.Open Browser about:blank ${BROWSER} ..so i replace this line with your statements?
robotframework-seleniumlimbrary: Open Browser ${url} ${browser} options=add_argument("--no-sandbox")
5

Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.

If you close all tabs and run again, the error should clear up.

Comments

5

in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:

opts.set_headless(True)

Comments

5

A simple solution that no one else has said but worked for me was running without sudo or not as root.

Comments

3

I had the same problem but it was solved just by reinstalling chrome again with the commands below:

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb

Comments

2

Make sure that both the chromedriver and google-chrome executable have execute permissions

sudo chmod -x "/usr/bin/chromedriver"

sudo chmod -x "/usr/bin/google-chrome"

1 Comment

sudo chmod +x "/usr/bin/chromedriver" sudo chmod +x "/usr/bin/google-chrome"
2

The solutions that every body provide here is good for Clear the face of the issue but

All you need to solve this problem is that You have to run The App on non-root user on linux.

According to this post

https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321

Comments

2

Fixed it buy killing all the chrome processeses running in the remote server before running my script. That may explain why some answers that recommend you run your script as root works.

$ pkill -9 chrome
$ ./my_script.py

Comments

2

Just do not run the script as the root user (in my case).

Comments

1

This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.

Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.

It solved the issue I was having; not elegantly but it works.

from selenium import webdriver
from selenium.common.exceptions import WebDriverException

try:
    self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
    print("\nChrome crashed on launch:")
    print(e)
    print("Trying again in 10 seconds..")
    sleep(10)
    self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
    print("Success!\n")
except Exception as e:
    raise Exception(e)

2 Comments

I see this error with selenium==4.0.0.b1 selenium==4.0.0.a7 works fine, only in linux, windows fine.
capabilities is not defined
1

I came across this error on linux environment. If not using headless then you will need

from sys import platform
    if platform != 'win32':
        from pyvirtualdisplay import Display
        display = Display(visible=0, size=(800, 600))
        display.start()

Comments

1

Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger. First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.

In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.

The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:

enter image description here

1 Comment

Found similar solution in the clone question, this also may help stackoverflow.com/a/57403093/6875391
1

For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.

Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version. Versions at the time of the initial error:

# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77

I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:

# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16

However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.

sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable

wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin

After that, my Selenium calls were able to work again. The final version combo:

# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71

1 Comment

Finally found the root cause for my error: user did not have perms to the /tmp/Crashpad directory. stackoverflow.com/questions/72306987/… My python error looked just like the one in url above and I kept seeing 'DevToolsActivePort file doesn't exist' and 'chrome not reachable'. Once I ran google-chrome --headless through the linux terminal, it spit out the true error: [0604/150957.804329:ERROR:filesystem_posix.cc(63)] mkdir /tmp/Crashpad/new: Permission denied (13) Everything worked after I fixed perms.
1

I did not see this mentioned anywhere but running a Python Selenium script over SSH can also cause the following errors:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
   (chrome not reachable)
   (The process started from chrome location /opt/render/.wdm/drivers/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

If you are using SSH, Some scripts may be working and some wont. If you have scripts that a managed by a process manager such as PM2, those scripts can appear to be working. But if you try to create a new process or run the script manually, those wont work.

To see if Chrome can start, run the following command in the terminal

google-chrome

If Chrome starts on your remote machine, then you have a different issue other than running your code via SSH. But if you get something like

[90345:90345:0505/150128.901178:ERROR:ozone_platform_x11.cc(243)] Missing X server or $DISPLAY
[90345:90345:0505/150128.901231:ERROR:env.cc(258)] The platform failed to initialize.  Exiting.

That means Chrome can't access your display driver. This also means that you will be able to run Chrome in --headless mode via SSH.

Keep in mind that, if you created process managing tasks via SSH for your code that runs selenium scripts, you will likely need to kill those, restart your machine and login without using SSH and start/enable those processes again.

Comments

0

i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.

Comments

0

i faced the same problem but i solved it by moving the chromedriver to this path '/opt/google/chrome/'

and this code works correctly

from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')

Comments

0

In my case, chrome was broken. following two lines fixed the issue,

apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install

Comments

0

Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
0

For me the problem was that I was running chromedriver from a user that did not have a home directory, and apparently chromium needs one.

So I have used mkhomedir_helper <username> to create it and everything worked again.

Comments

0

Maybe it may help to someone: I was experimenting multi-thread web-driver implementation. Even though I took "cleaning up the driver instance" seriously, sometime after the program started I kept getting "Chrome has crashed..." error.

I have done everything written here and more, but did not resolve the issue. Eventually I realized that driver.quit() method had been creating zombie and orphaned processes which then lead to crashes. You can simply use "init:true" in your docker compose file to clean up those. This fixed my problem.

Comments

0

Good afternoon,

I wanted to share my experience with setting up headless Chrome in a Docker container, which fixed my headless issue and helped with reCAPTCHA.

Steps I Followed:

  1. I first ran some commands to ensure Google Chrome was installed:

    docker exec -it container_name /bin/bash
    

    Check if Google Chrome is installed by running:

    google-chrome --version
    
  2. Then, I opened a Python shell:

    python
    
  3. Next, I ran this code to take a screenshot of the Google homepage:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    import time
    
    # Configure Chrome options to run headless
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--headless")  # Run in headless mode
    chrome_options.add_argument("--no-sandbox")  # Bypass OS security model
    chrome_options.add_argument("--disable-dev-shm-usage")  # Overcome limited resource problems
    chrome_options.add_argument("--disable-gpu")  # Disable GPU (for headless stability)
    
    # Set up the WebDriver
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
    
    # Open a test page
    driver.get("https://www.google.com")
    
    # Wait for the page to load
    time.sleep(2)
    
    # Take a screenshot and save it to a file
    driver.save_screenshot("snapshot.png")
    
    print("Screenshot saved as snapshot.png")
    
    # Close the browser
    driver.quit()
    
  4. I ran pwd to check my current directory and then downloaded the screenshot to my PC. If I was able to see the Google homepage, then Chrome was working fine.

  5. If the above worked, I modified my Chrome options as follows to improve compatibility with reCAPTCHA:

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--headless")  # Run in headless mode
    chrome_options.add_argument("--no-sandbox")  # Bypass OS security model
    chrome_options.add_argument("--disable-dev-shm-usage")  # Overcome limited resource problems
    chrome_options.add_argument("--disable-gpu")  # Disable GPU (for headless stability)
    
    # Add a common user-agent to mimic a real browser, especially in case of reCAPTCHA
    chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
    
    # Disable automation flags to avoid detection by reCAPTCHA
    chrome_options.add_argument("--disable-blink-features=AutomationControlled")
    
    # Set up the WebDriver with the configured options
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
    

This should be fine. If you have any inquiries, message me. If it does not work, drop a comment on where you face challenges. Please don't minus my count. Thank you!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.