348

I am trying to launch chrome with an URL, the browser launches and it does nothing after that.

I am seeing the below error after 1 minute:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

My configuration:

  • Chrome : 66
  • ChromeBrowser : 2.39.56

P.S everything works fine in Firefox

frianH
  • 7,295
  • 6
  • 20
  • 45
Kumar Sampath
  • 3,821
  • 2
  • 8
  • 11
  • I received this error when vncserver crashed and I had no X display anymore – xtian Aug 21 '18 at 15:10
  • For a fix for running without an X display, use `export DISPLAY=:0`, see https://stackoverflow.com/questions/50790733/unknown-error-devtoolsactiveport-file-doesnt-exist-error-while-executing-selen/50791503#comment91362049_50790733 – bers Mar 21 '22 at 08:56

49 Answers49

215

Thumb rule

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


This error message...

org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist 

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

Your code trials and the versioning information of all the binaries would have given us some hint about what's going wrong.

However as per Add --disable-dev-shm-usage to default launch flags seems adding the argument --disable-dev-shm-usage will temporary solve the issue.

If you desire to initiate/span a new Chrome Browser session you can use the following solution:

System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized"); // open Browser in maximized mode
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");

disable-dev-shm-usage

As per base_switches.cc disable-dev-shm-usage seems to be valid only on Linux OS:

#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// The /dev/shm partition is too small in certain VM environments, causing
// Chrome to fail or crash (see http://crbug.com/715363). Use this flag to
// work-around this issue (a temporary directory will always be used to create
// anonymous shared memory files).
const char kDisableDevShmUsage[] = "disable-dev-shm-usage";
#endif

In the discussion Add an option to use /tmp instead of /dev/shm David mentions:

I think it would depend on how are /dev/shm and /tmp mounted. If they are both mounted as tmpfs I'm assuming there won't be any difference. if for some reason /tmp is not mapped as tmpfs (and I think is mapped as tmpfs by default by systemd), chrome shared memory management always maps files into memory when creating an anonymous shared files, so even in that case shouldn't be much difference. I guess you could force telemetry tests with the flag enabled and see how it goes.

As for why not use by default, it was a pushed back by the shared memory team, I guess it makes sense it should be useing /dev/shm for shared memory by default.

Ultimately all this should be moving to use memfd_create, but I don't think that's going to happen any time soon, since it will require refactoring Chrome memory management significantly.


Reference

You can find a couple of detailed discussions in:


Outro

Here is the link to the Sandbox story.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 47
    But what caused this specific error about `DevToolsActivePort file doesn't exist`, and why did it suddenly start popping up? –  Jun 07 '18 at 09:43
  • 3
    The "Additional Consideration" items - they look like they're quite applicable to this issue. Especially this kind of situation where it hadn't been established exactly what caused the problem. – Pete Kelley Jun 11 '18 at 17:01
  • 7
    From the deleted part of @DebanjanB's post, this can be caused by using a Chromedriver which does not support the version of the installed Chrome. This can happen, for example, if chrome is upgraded without upgrading Chromedriver. – expz Nov 29 '18 at 21:12
  • This used to solve the issue for me, it doesn't on my current system (Ubuntu 18 + Python 3.7) – tw0000 Mar 19 '19 at 02:35
  • 10
    In case this helps anybody else, just adding `disable-dev-shm-usage` wasn't enough. I had to also add `--no-sandbox` to get it to work. This was the complete fix for me for Selenium-java: `chromeOptions.addArguments("--no-sandbox", "--disable-dev-shm-usage");` – George Pantazes Aug 08 '19 at 21:39
  • 6
    If none of the above options helped (as in my case) - just run: `chrome --headless` from command line and you will see the actual issue (in my case it was some lib incompatibility). If everything is ok with your chrome setup it should delay for few seconds and then return with something like: `[1006/110844.401199:ERROR:browser_process_sub_thread.cc(203)] Waited 3 ms for network service ` – ARA1307 Oct 06 '19 at 18:38
  • @GeorgePantazes, your statement is absolutely true. – S.K. Venkat Dec 22 '19 at 15:57
  • Unfortunately, @GeorgePantazes's solution did not help me. – Alpha Jan 24 '20 at 08:42
  • 2
    I was hit by this inside docker because I didn't have `--headless`. – GGhe Mar 29 '20 at 23:55
  • @user9315861 `DevToolsActivePort file doesn't exist` the error comes from chromedriver, we can run chromedriver whis options as `chromedriver --verbose` then log level will come into detail – huang botao Mar 24 '21 at 10:49
  • 1
    This post helped me resolve this issue with a Docker container. Thanks! – Ryan Harris Jul 06 '21 at 16:30
  • 1
    Perfect ! Thank you – BSQ Oct 31 '21 at 10:22
  • Does this fix apply even for **Windows OS**, beacuse i faced the same issue on one of my windows machine. only different thing in that system was i had disabled upgrade of google chrome from **Services**. – ItsPrinceAk Dec 15 '21 at 05:10
  • 1
    I think there's more to it. The `--no-sandbox` helps in my case of running a headless Chromium in a Docker container — however, I don't run it as root, I run it as a plain user. So the explanation about running as root doesn't apply, Idk why I have that problem. – Hi-Angel Oct 19 '22 at 15:33
98

I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run).
Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error. I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.

ChromeOptions options = new ChromeOptions();
        ...
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");
Pete Kelley
  • 3,713
  • 2
  • 16
  • 17
  • I want to clarify that this code was running each weekday on an Ubuntu Linux box, but equivalent code on Windows desktop ran OK even on Monday. I've found no info about what the functionality of the DevToolsActivePort file is for and that would be useful too. PK – Pete Kelley Jun 06 '18 at 17:15
  • 1
    These options stopped the error for me too. pd: using a Rails stack. – Mario Pérez Alarcón Jun 08 '18 at 17:19
  • I still get `[java] [1536892035.965][SEVERE]: Timed out receiving message from renderer: 60.000` errors even with this – Jonathan Sep 14 '18 at 02:28
  • @Jonathan - Hi! can you supply some more detail, like which OS, which versions of the components you're using, or how you're invoking the process? – Pete Kelley Sep 17 '18 at 12:13
  • @Toby : Hi! I didn't mean to imply that the position made a difference, just the minimal use of those parameters. It seemed that some of the default values that I had relied on were changed when upgrades happened. Any other details re your system or message that you provide might help. – Pete Kelley Jan 15 '19 at 20:34
  • Using protractor I added the above args to the chrome-options and it fixed it, odd as last time I ran the regression pack - about a month ago - with no args, it worked! – AEngineer Jul 01 '19 at 22:01
  • I additionally required `--remote-debugging-port=9222` to get it to work on Fedora 33 – Scott P. Dec 03 '20 at 18:00
  • adding options.addArguments("--no-sandbox"); did the trick for me. Thanks for sharing! – Pramod Yadav Dec 08 '20 at 12:12
81

We encountered the same issue on Jenkins (Linux machine) and tried all the options above.

The only thing that helped was setting the --headless argument:

chrome_options.add_argument('--headless')

When we investigated further, we noticed that the XVFB screen didn't start property, which caused this error. After we fixed the XVFB screen, the issue was resolved.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • 4
    this solved my issue, when running using C# (in this case the option looked like this: options.AddArgument("--headless"); – ozz Dec 03 '18 at 11:30
  • XVFB was the issue for me – lucaswxp Jul 23 '20 at 14:07
  • 7
    What was the issue with XVFB. Can you please explain. – Tyler Gallenbeck Sep 26 '20 at 00:21
  • 1
    This absolutely solved my problem! I was trying to get a python3.9 project with selenium and chromedriver running on Ubuntu 20.04 headless, but I kept getting OP's error. With your addition I got it to work! Thanks! – dnwjn Mar 07 '21 at 14:10
  • That was it - thanks! Xvfb had not been started on the server. As soon as I started it, everything ran without issue. Wish the original error message had been at least a bit more helpful for tracking this down. – Criminally Inane Nov 18 '21 at 04:19
60

I had the same problem in python. The above helped. Here is what I used in python -

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('/path/to/your_chrome_driver_dir/chromedriver',chrome_options=chrome_options)
36

In my case in the following environment:

  • Windows 10
  • Python 3.7.5
  • Google Chrome version 80 and corresponding ChromeDriver in the path C:\Windows
  • selenium 3.141.0

I needed to add the arguments --no-sandbox and --remote-debugging-port=9222 to the ChromeOptions object and run the code as administrator user by lunching the Powershell/cmd as administrator.

Here is the related piece of code:

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('--disable-infobars')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(options=options)
Soheil Pourbafrani
  • 3,249
  • 3
  • 32
  • 69
33

I was facing the same issue recently and after some trial and error it worked for me as well.

MUST BE ON TOP:

options.addArguments("--no-sandbox"); //has to be the very first option

BaseSeleniumTests.java

public abstract class BaseSeleniumTests {

    private static final String CHROMEDRIVER_EXE = "chromedriver.exe";
    private static final String IEDRIVER_EXE = "IEDriverServer.exe";
    private static final String FFDRIVER_EXE = "geckodriver.exe";
    protected WebDriver driver;

    @Before
    public void setUp() {
        loadChromeDriver();
    }

    @After
    public void tearDown() {
        if (driver != null) {
            driver.close();
            driver.quit();
        }
    }

    private void loadChromeDriver() {
        ClassLoader classLoader = getClass().getClassLoader();
        String filePath = classLoader.getResource(CHROMEDRIVER_EXE).getFile();
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        ChromeDriverService service = new ChromeDriverService.Builder()
                .usingDriverExecutable(new File(filePath))
                .build();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--no-sandbox"); // Bypass OS security model, MUST BE THE VERY FIRST OPTION
        options.addArguments("--headless");
        options.setExperimentalOption("useAutomationExtension", false);
        options.addArguments("start-maximized"); // open Browser in maximized mode
        options.addArguments("disable-infobars"); // disabling infobars
        options.addArguments("--disable-extensions"); // disabling extensions
        options.addArguments("--disable-gpu"); // applicable to windows os only
        options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        options.merge(capabilities);
        this.driver = new ChromeDriver(service, options);
    }

}

GoogleSearchPageTraditionalSeleniumTests.java

@RunWith(SpringRunner.class)
@SpringBootTest
public class GoogleSearchPageTraditionalSeleniumTests extends BaseSeleniumTests {

    @Test
    public void getSearchPage() {
        this.driver.get("https://www.google.com");
        WebElement element = this.driver.findElement(By.name("q"));
        assertNotNull(element);
    }

}

pom.xml

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>
Nital
  • 5,784
  • 26
  • 103
  • 195
  • Interesting ! How do you generate a .side file ? Is this something that a QA person does manually ? – Nital Jul 10 '19 at 19:54
  • You use the Selenium IDE to record a test. The result is a .side file. It runs fine using the IDE, but I'm trying to run it using selenium-side-runner but running into all kinds of problems with chromedriver. – pabrams Jul 11 '19 at 14:19
  • 6
    has to be first option -- spend days to find this haha – Jacob Brazeal Apr 20 '20 at 12:40
32

I ran into this problem on Ubuntu 20 with Python Selenium after first downloading the chromedriver separately and then using sudo apt install chromium-browser Even though they were the same version this kept happening.

My fix was to use the provided chrome driver that came with the repo package located at

/snap/bin/chromium.chromedriver

driver = webdriver.Chrome(chrome_options=options, executable_path='/snap/bin/chromium.chromedriver')
Lelouch
  • 549
  • 6
  • 6
  • 1
    Thx alot. This helped me: Specs: Ubuntu 20.04, python 3.8 with a snap-based Chromium installation. – hatze May 13 '21 at 19:35
  • 1
    As you figured out, when working on Ubuntu, seems like Chromium browser also install a compatible chrome-driver that will always interfere with the one downloaded from https://chromedriver.chromium.org/downloads. The default location of the preinstalled driver are found at: /snap/bin/chromium.chromedriver Search for snap in the post below for more info. https://www.pythonfixing.com/2021/10/fixed-webdriverexception-unknown-error.html The recommendation to get this to work is: Do NOT download driver from on your own. Use the one in snap/bin. Otherwise you will always get this error! – Daniel Nelson Feb 16 '22 at 09:30
  • Very helpful! I wonder if this will mark the end of the endless battle to keep chromedriver updated to the correct chrome version? I am assuming that the snaps update automatically. Any idea if the chrome driver updates along with it? – Digestible1010101 Apr 27 '22 at 22:10
  • In Nightwatchjs edit the server path in a config file like this https://nightwatchjs.org/guide/configuration/nightwatch-configuration-file.html – Sean Burlington Jul 17 '23 at 10:38
24

Update:

I am able to get through the issue and now I am able to access the chrome with desired url.

Results of trying the provided solutions:

I tried all the settings as provided above but I was unable to resolve the issue

Explanation regarding the issue:

As per my observation DevToolsActivePort file doesn't exist is caused when chrome is unable to find its reference in scoped_dirXXXXX folder.

Steps taken to solve the issue

  1. I have killed all the chrome processes and chrome driver processes.
  2. Added the below code to invoke the chrome

    System.setProperty("webdriver.chrome.driver","pathto\\chromedriver.exe");    
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get(url);
    

Using the above steps I was able to resolve the issue.

Thanks for your answers.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Kumar Sampath
  • 3,821
  • 2
  • 8
  • 11
  • 5
    Do you know what affect useAutomationExtension has? It disables extensions for automation (screenshots/control etc) no? Shouldn't the advent of DevTools render this change to have no affect? https://codereview.chromium.org/2785413002 – Toby Jan 08 '19 at 20:13
16

In my case it was problem with CI Agent account on ubuntu server, I solved this using custom --user-data-dir

chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')

My account used by CI Agent didn't have necessary permissions, what was interesting everything was working on root account

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-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--profile-directory=Default')
chrome_options.add_argument('--user-data-dir=~/.config/google-chrome')

driver = webdriver.Chrome(options=chrome_options)
url = 'https://www.google.com'
driver.get(url) 
get_url = driver.current_url 
print(get_url)
rafalkasa
  • 1,743
  • 20
  • 20
  • I am getting this error ```selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.``` Anyone got the solution for this issue? – bhattraideb Apr 22 '21 at 11:53
  • this option worked for me, but ONLY when I had ALL of the above arguments added. Missing one, any one, would cause me to get the same error. I was using selenium in a docker `FROM python:3.8-slim-buster` image. – Caleb Jay Aug 18 '21 at 09:17
  • This also works when using a custom user in a docker image that does not have root – Paul Collingwood Feb 13 '22 at 22:37
13

There is lot of possible reasons for the RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist error message (as we can see from the number of answers for this question). So let's dive deeper to explain what exactly this error message means.

According to chromedriver source code the message is created in ParseDevToolsActivePortFile method. This method is called from the loop after launching chrome process.

In the loop the driver check if the chrome process is still running and if the ParseDevToolsActivePortFile file was already created by chrome. There is a hardcoded 60s timeout for this loop.

I see two possible reasons for this message:

  • Chrome is really slow during startup - for example due to lack of system resources - mainly CPU or memory. In this case it can happen that sometimes chrome manage to start in time limit and sometimes not.
  • There is another issue which prevents chrome to start - missing or broken dependency, wrong configuration etc. In such case this error message is not really helpful and you should find another log message which explain the true reason of the failure.
eNca
  • 1,043
  • 11
  • 21
11

It happens when chromedriver fails to figure out what debugging port chrome is using.

One possible cause is an open defect with HKEY_CURRENT_USER\Software\Policies\Google\Chrome\UserDataDir

But in my last case, it was some other unidentified cause.

Fortunately setting port number manually worked:

final String[] args = { "--remote-debugging-port=9222" };
options.addArguments(args);
WebDriver driver = new ChromeDriver(options);
radzimir
  • 1,178
  • 13
  • 10
10

I know it's an old question and it already has a lot of answers. However, I ran into this issue, bumped into this thread and none of the proposed solutions helped. After spending a few days(!) on it I finally found a solution:

My problem was that I was using the selenium/standalone-chrome image on a MacBook with M1 chip. After switching to seleniarm/standalone-chromium everything finally started to work.

SaturnFromTitan
  • 1,334
  • 14
  • 20
8

As stated in this other answer:

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

Among the possible causes, I would like to mention the fact that, in case you are running an headless Chromium via Xvfb, you might need to export the DISPLAY variable: in my case, I had in place (as recommended) the --disable-dev-shm-usage and --no-sandbox options, everything was running fine, but in a new installation running the latest (at the time of writing) Ubuntu 18.04 this error started to occurr, and the only possible fix was to execute an export DISPLAY=":20" (having previously started Xvfb with Xvfb :20&).

Piercarlo Slavazza
  • 478
  • 1
  • 5
  • 16
7

I was stuck on this for a very long time and finally fixed it by adding this an additional option:

options.addArguments("--crash-dumps-dir=/tmp")

PlumsAhoy
  • 118
  • 1
  • 5
  • Hey. @PlumsAhoy. Hope you are doing well. I had this problem all day, and tried to find the right solution all day... I followed all upvoted answers, but they were not for me. Just found your answer in over 24 hours, and this solved my problem... Thanks for your answer... – jis0324 Jun 01 '22 at 15:14
  • 3
    For selenium version 4.x+ you should change this line to this: `chrome_options.add_argument("--crash-dumps-dir=/tmp")` . As V4.X+ has changed `addArguments()` to `add_argument()` – Jameu Lukasli1 Jul 20 '22 at 07:20
6

You can get this error simply for passing bad arguments to Chrome. For example, if I pass "headless" as an arg to the C# ChromeDriver, it fires up great. If I make a mistake and use the wrong syntax, "--headless", I get the DevToolsActivePort file doesn't exist error.

Chris Moschini
  • 36,764
  • 19
  • 160
  • 190
4

Old question but a similar issue nearly drove me to insanity so sharing my solution. None of the other suggestions fixed my issue.

When I updated my Docker image Chrome installation from an old version to Chrome 86, I got this error. My setup was not identical but we were instantiating Chrome through a selenium webdriver.

The solution was to pass the options as goog:chromeOptions hash instead of chromeOptions hash. I truly don't know if this was a Selenium, Chrome, Chromedriver, or some other update, but maybe some poor soul will find solace in this answer in the future.

Eric Dauenhauer
  • 710
  • 6
  • 23
  • Could you describe how you used `goog:chromeOptions` a little more? Right now I'm using `chrome_options = webdriver.ChromeOptions()` and `chrome_options.add_argument(...)` – CPak Nov 16 '20 at 01:41
  • Unfortunately I recently left the company where I implemented this @CPak so I don't have a code example in front of me. I was using the Ruby driver and I believe it was just a hash passed to ChromeOptions(). Something like `chrome_options = webdriver.ChromeOptions({"goog:chromeOptions": { args: ["headless"] })`. I'm sorry I don't have an exact snippet for the syntax. – Eric Dauenhauer Nov 17 '20 at 17:04
4

For Ubuntu 20 it did help me to use my systems chromium driver instead of the downloaded one:

# chromium which
/snap/bin/chromium

driver = webdriver.Chrome('/snap/bin/chromium.chromedriver',
                          options=chrome_options)

And for the downloaded webdriver looks like it needs the remote debug port --remote-debugging-port=9222 to be set, as in one of the answers (by Soheil Pourbafrani):

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('<path_to>/chromedriver', options=chrome_options)
natalka
  • 51
  • 2
4

Date 9/16/2021

Everything works fine running chrome with selenium locally with python inside the docker hosted ubuntu container. When attempting to run from Jenkins the error above is returned WebDriverException: unknown error: DevToolsActivePort

Environment:

-Ubuntu21.04 inside a docker container with RDP access.

-chromedriver for chrome version: 93

Solution: Inside the python file that starts the browser I had to set the DISPLAY environment variable using the following lines:

import os

os.environ['DISPLAY'] = ':10.0'
#DISPLAY_VAR = os.environ.get('DISPLAY')
#print("DISPLAY_VAR:", DISPLAY_VAR)
Jortega
  • 3,616
  • 1
  • 18
  • 21
3

I had the same issue, but in my case chrome previously was installed in user temp folder, after that was reinstalled to Program files. So any of solution provided here was not help me. But if provide path to chrome.exe all works:

chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");

I hope this helps someone =)

3

In my case it happened when I've tried to use my default user profile:

...
options.addArguments("user-data-dir=D:\\MyHomeDirectory\\Google\\Chrome\\User Data");
...

This triggered chrome to reuse processes already running in background, in such a way, that process started by chromedriver.exe was simply ended.

Resolution: kill all chrome.exe processes running in background.

radzimir
  • 1,178
  • 13
  • 10
  • I had a similar issue, but in linux - my chrome processes were not properly exited after the script crashed, and they were being reused incorrectly. killing them solved the issue – jeremycg Dec 27 '18 at 16:42
  • This was my exact issue too. I wanted to use my default profile. After killing all other chrome instances I had already running, it worked fine. – Robert Dec 13 '22 at 00:57
3

update capabilities in conf.js as

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
    }
  },

};
user2694064
  • 357
  • 2
  • 4
3

Had the same issue. I am running the selenium script on Google cloud VM.

options.addArguments("--headless");

The above line resolved my issue. I removed the other optional arguments. I think the rest lines of code mentioned in other answers did not have any effect on resolving the issue on the cloud VM.

2

In my case, I was trying to create a runnable jar on Windows OS with chrome browser and want to run the same on headless mode in unix box with CentOs on it. And I was pointing my binary to a driver that I have downloaded and packaged with my suite. For me, this issue continue to occur irrespective of adding the below:

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
options.setBinary("/pointing/downloaded/driver/path/in/automationsuite");
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-gpu"); // applicable to windows os only
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("window-size=1024,768"); // Bypass OS security model
options.addArguments("--log-level=3"); // set log level
options.addArguments("--silent");//
options.setCapability("chrome.verbose", false); //disable logging
driver = new ChromeDriver(options);

Solution that I've tried and worked for me is, download the chrome and its tools on the host VM/Unix box, install and point the binary to this in the automation suite and bingo! It works :)

Download command:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

Install command:

sudo yum install -y ./google-chrome-stable_current_*.rpm

Update suite with below binary path of google-chrome:

options.setBinary("/opt/google/chrome/google-chrome");

And.. it works!

jww
  • 97,681
  • 90
  • 411
  • 885
2

I also faced this issue while integrating with jenkins server, I was used the root user for jenkin job, the issue was fixed when I changed the user to other user. I am not sure why this error occurs for the root user.

  • Google Chrome Version 71.0
  • ChromeDriver Version 2.45
  • CentOS7 Version 1.153
frianH
  • 7,295
  • 6
  • 20
  • 45
Osanda Deshan
  • 1,473
  • 3
  • 14
  • 30
  • Non-root user worked for me, I had the correct chrome driver version for the chromium. –  Jun 30 '20 at 19:51
2

I run selenium tests with Jenkins running on an Ubuntu 18 LTS linux. I had this error until I added the argument 'headless' like this (and some other arguments):

ChromeOptions options = new ChromeOptions();
options.addArguments("headless"); // headless -> no browser window. needed for jenkins
options.addArguments("disable-infobars"); // disabling infobars
options.addArguments("--disable-extensions"); // disabling extensions
options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
options.addArguments("--no-sandbox"); // Bypass OS security model
ChromeDriver driver = new ChromeDriver(options);

driver.get("www.google.com");
Codev
  • 1,040
  • 2
  • 14
  • 31
2

in my case, when i changed the google-chrome and chromedriver version, the error was fixed :)

#google-chrome version
[root@localhost ~]# /usr/bin/google-chrome --version
Google Chrome 83.0.4103.106 

#chromedriver version
[root@localhost ~]# /usr/local/bin/chromedriver -v
ChromeDriver 83.0.4103.14 (be04594a2b8411758b860104bc0a1033417178be-refs/branch-heads/4103@{#119})

ps: selenium verison was 3.9.1

huang botao
  • 405
  • 6
  • 13
1

No solution worked for my. But here is a workaround:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")
Alex
  • 41,580
  • 88
  • 260
  • 469
1

It seems there are many possible causes for this error. In our case, the error happened because we had the following two lines in code:

System.setProperty("webdriver.chrome.driver", chromeDriverPath);
chromeOptions.setBinary(chromeDriverPath);

It's solved by removing the second line.

shiuu
  • 123
  • 2
  • 9
  • seems the exact opposite of @sergiy-konoplyaniy fix above :'( – Toby Jan 08 '19 at 20:01
  • In our setBinary, we tried to set chrome driver, which seems a mistake. @sergiy-konoplyaniy's fix sets chrome.exe via setBinary. – shiuu Jan 10 '19 at 01:09
  • Where did you have this code? All I have is a .side file, and it has no C# code in it. – pabrams Jul 10 '19 at 14:24
  • 1
    Hahahaha, this solved issue for me, but not removing this line and adding it! Thank you) Seems driver couldn't find my executable using a default path. But why id didn't just say this, showing strange messages.... – Frankie Drake Jun 04 '21 at 09:49
1

I ran into same issue, i am using UBUNTU, PYTHON and OPERA browser. in my case the problem was originated because i had an outdated version of operadriver.

Solution: 1. Make sure you install latest opera browser version ( do not use opera beta or opera developer), for that go to the official opera site and download from there the latest opera_stable version.

  1. Install latest opera driver (if you already have an opera driver install, you have to remove it first use sudo rm ...)

wget https://github.com/operasoftware/operachromiumdriver/releases/download/v.80.0.3987.100/operadriver_linux64.zip

   unzip operadriver_linux64.zip
   sudo mv operadriver /usr/bin/operadriver
   sudo chown root:root /usr/bin/operadriver
   sudo chmod +x /usr/bin/operadriver

in my case latest was 80.0.3987 as you can see

  1. Additionally i also installed chromedriver (but since i did it before testing, i do not know of this is needed) in order to install chromedriver, follow the steps on previous step :v

  2. Enjoy and thank me!

Sample selenium code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Opera()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.quit()
Adrian Jimenez
  • 979
  • 9
  • 23
1

I came across the same problem, in my case there are two different common user userA and userB in Linux system. userA first run the selinium programe which start chrome browswer with ChromeDriver successfully, when it came to userB, the DevToolsActivePort file doesn't exist error occur.

I tried the --remote-debugging-port=9222 option, but it lead to a new exception: selenium.common.exceptions.WebDriverException: Message: chrome not reachable

The I ran google-chome directory and see the following error:
mkdir /tmp/Crashpad/new: Permission denied (13)

The I search the problem and got this:
https://johncylee.github.io/2022/05/14/chrome-headless-%E6%A8%A1%E5%BC%8F%E4%B8%8B-devtoolsactiveport-file-doesn-t-exist-%E5%95%8F%E9%A1%8C/

chrome_options.add_argument(f"--crash-dumps-dir={os.path.expanduser('~/tmp/Crashpad')}")

Thanks to @johncylee.

yong
  • 61
  • 3
  • I found the same problem and fixed it by making /tmp/Crashpad world-writable (on a shared workstation), but this is a better idea. – Walter Gillett Jun 02 '23 at 19:31
0

I ran into the same issue running Chrome via Behat/Mink and Selenium in a Docker container. After some fiddling, I arrived at the following behat.yml which supplies the switches mentioned above. Note that all of them were required for me to get it running successfully.

default:
    extensions:
        Behat\MinkExtension:
            base_url: https://my.app/
            default_session: selenium2
            selenium2:
                browser: chrome
                capabilities:
                    extra_capabilities:
                        chromeOptions:
                            args:
                                - "headless"
                                - "no-sandbox"
                                - "disable-dev-shm-usage"
Chris
  • 6,914
  • 5
  • 54
  • 80
0

In my case, I'm in a Kubernetes environment where I cannot use the default TMPDIR because it will fill up the temp directory with garbage.

So I was using this to use a different tmpdir:

driver = new ChromeDriver(new ChromeDriverService.Builder()
                    .withEnvironment(ImmutableMap.of("TMPDIR", customTmpPath))
                    .build(), options);

But now that I've upgraded everything to the latest, this no longer seems to work. I will need to find a new way to do this.

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152
0

Wrong port number in my case. Check if port number when starting Selenium server is the same as in your script.

Jaroslav Štreit
  • 415
  • 1
  • 5
  • 16
0

TL;DR: If you are using VirtualBox shared folders, do not create the Chrome profile there!


I ran into this error under Debian 10, but it did not occur under Ubuntu 18.04.

In my Selenium tests, I wanted to install an extension, and use the following Chrome options:

chromeOptions.addArguments(
  `load-extension=${this.extensionDir}`,
  `user-data-dir=${this.profileDir}`,
  `disable-gpu`,
  `no-sandbox`,
  `disable-setuid-sandbox`,
  `disable-dev-shm-usage`,
);

The issue was that I was attempting to create a Chrome profile under a nonstandard directory which was part of a VirtualBox shared folder. Despite using the exact same version of Chrome and Chromedriver, it didn't work under Debian.

The solution was to choose a profile directory somewhere else (e.g. ~/chrome-profile).

slhck
  • 36,575
  • 28
  • 148
  • 201
0

I use chromium but I have created a shell script called chrome just to be easy for me to open the browser from dmenu.

#!/bin/bash

/usr/bin/chromium

Chrome driver looking for chrome in PATH and executes that. In result I got the same error.

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /home/s1n7ax/.local/share/s1n7ax/bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 's1n7ax', ip: '127.0.1.16', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.70-1-lts', java.version: '11.0.8'
Driver info: driver.version: ChromeDriver
remote stacktrace: #0 0x56030c96dd99 <unknown>

I just removed the shell script and added a soft link to chromium. Everything working now.

s1n7ax
  • 2,750
  • 6
  • 24
  • 53
0

My problem was a bug in php-webdriver. My code was:

$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments([
    '--headless',
    '--no-sandbox',
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--no-proxy-server'
]);
$chromeOptions->setExperimentalOption('detach', true);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(
    ChromeOptions::CAPABILITY,
    $chromeOptions
);

as you can see, everything is in line with the rest of possible reasons.

But actually capabilities weren't passing to chromedriver. I had to change setting chrome options capability to:

$capabilities->setCapability(
    ChromeOptions::CAPABILITY_W3C, // <<< Have to use W3C capabilities with recent versions of Chromedriver.
    $chromeOptions->toArray() // <<<<< bug in php-webdriver 1.9, object not getting serialized automatically like with the deprecated capability ChromeOptions::CAPABILITY
);

My setup was:

$ chromedriver --version
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614})
$ java -jar selenium-server-standalone-3.141.59.jar --version
Selenium server version: 3.141.59, revision: e82be7d358

Made a bug report and a PR to fix this bug in php-webdriver

https://github.com/php-webdriver/php-webdriver/issues/849

gvlasov
  • 18,638
  • 21
  • 74
  • 110
0

I had the same error, and I found out that the cause was because my computer disk was full. After deleting some unnecessary files, the error went away.

Red
  • 26,798
  • 7
  • 36
  • 58
0

If adding arguments/options does not fix it then it could be a permissions issue on /tmp directory.

Make sure your user that executes Chrome has permissions to create folder/files in /tmp folder. This was the solution in my case

hzak
  • 719
  • 9
  • 18
0

I also esperienced this issue and none of the proposed solutions seemed to work. Then I found out that the problem is that I was running on WSL version 1, and it seems there chromedriver works with the windows browser, not the one installed with aptitude.

To make it compatible with WSL version 1 and version 2 I found (and tested in debian WSLv2 and ubuntu WSLv1 that it works) that the version of the platform is displayed with the first letter in uppercase for the word Microsoft.

So the solution ended up like this:

    import platform
    from selenium.webdriver.chrome.service import Service as ChromeService
    from seleniumwire import webdriver

    chromedriver = 'chromedriver.exe'
    
    # According to:
    # https://stackoverflow.com/a/71879688/7019069
    # When using WSL v1 the chromedriver.exe of local chrome of windows is used
    # In WSL v2 (updated version) it does work using the installation shown in the README.md)
    # And according to
    # https://github.com/microsoft/WSL/issues/4555
    # It is possible to differentiate the version of WSL by the first uppercase of the platform 
    # version of Microsoft. Therefore only the linux chromedriver is used if that word is matched 
    # in the platform of the driver. 
    if platform.system() == 'Linux' and not re.search(re.escape('Microsoft'), platform.platform()):
        chromedriver = 'chromedriver'

    driver_path = os.path.join(drivers_path, chromedriver)
  service = ChromeService(driver_path)

    driver = webdriver.Chrome(
        service=service,
        options=__get_chrome_options(headless)
    )
nck
  • 1,673
  • 16
  • 40
0

For me, the issue was in the systemD service file. I pass the shell environment as venv

Environment="proejct/venv/bin"

when I add the /bin:/usr/bin to Environment:

Environment="proejct/venv/bin:/usr/bin:/bin"

and Finally, it worked.

Ericgit
  • 6,089
  • 2
  • 42
  • 53
0

This one worked for me. If you are on a server without a graphical environment, you might need to use Xvfb to simulate a display.

from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 800))
display.start()
options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(chrome_options=options)
PSN
  • 2,326
  • 3
  • 27
  • 52
0

Error: selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

  1. vps on DO
  2. ubuntu 22.10
  3. python 3.10.7

It worked for me:

options.add_argument('--no-sandbox')
options.add_argument("--remote-debugging-port=9222")
options.add_argument('--headless')
options.add_argument('--disable-gpu')
Ruslan
  • 175
  • 1
  • 1
  • 7
0

I've received this issue while running multiple chromium instances at the same machine. You need to create a separate temp directory for every chromium instance.

addArguments(`user-data-dir=${CURRENT_CHROMIUM_TMP_DIR}`);
puchu
  • 3,294
  • 6
  • 38
  • 62
0

This may happen as well if the version of chrome & chrome driver do not match. The versions must be exactly the same version!

Vitaliy
  • 291
  • 1
  • 14
0

For GitHub Actions

For anyone running into this error while running tests on their CI/CD environment (GitHub Actions in my case), I was getting this because I was trying to replace the GitHub runner's default version of Chrome with an earlier version in order to fix a separate issue. I fixed it by replacing my rm and mv commands with a simple ln command to symbolically link the default Chrome binary (located at usr/bin/google-chrome) to my newly-downloaded one.

Here is the relevant part of my GitHub Actions workflow:

  - name: Downgrade Chrome browser to v114
    uses: browser-actions/setup-chrome@v1
    with:
      chrome-version: 1134343 # Last commit number for Chrome v114
    id: setup-chrome
  - run: sudo ln -fs ${{ steps.setup-chrome.outputs.chrome-path }} /usr/bin/google-chrome
  - name: Downgrade Chrome driver to v114
    run: php artisan dusk:chrome-driver `/usr/bin/google-chrome --version | cut -d " " -f3 | cut -d "." -f1`
Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
-1

Since this is the most active message for this type of error, I wanted to mention my solution (after spending hours to fix this).

On Ubuntu 18.04, using Chrome 70 and Chromedriver 2.44, and Python3 I kept getting the same DevToolsActivePort error, even when I disabled all options listed above. The chromedriver log file as well as ps showed that the chromedriver I set in chrome_options.binary_location was running, but it always gave DevToolsActivePort error. When I removed chrome_options.binary_location='....' and add it to webdriver creation, I get it working fine. webdriver.Chrome('/path to ... /chromedriver',chrome_options=chrome_options)

Thanks everybody for your comments that make me understand and resolve the issue.

Obrc
  • 51
  • 2
-1

was facing the same issue while trying to run selenium on a linux server ,try downgrading your chrome version ,it did the trick for me

pick version from here

http://170.210.201.179/linux/chrome/deb/pool/main/g/google-chrome-stable/

jack chyna
  • 83
  • 4
-2

I solve this problem by installing yum -y install gtk3-devel gtk3-devel-docs", it works ok

My work env is :

Selenium Version 3.12.0
ChromeDriver Version v2.40
Chrome 68 level

Before:
enter image description here enter image description here

After:
enter image description here enter image description here

JustBaron
  • 2,319
  • 7
  • 25
  • 37
何贤勇
  • 21
  • 2
-3
crifan
  • 12,947
  • 1
  • 71
  • 56
  • Hi crifan. I can see in your other linked answer that you've _correctly_ demonstrated the recommended solution to run as a non-root user. Did you perhaps have a typo here and mean to say _don't_ use the root user? – jamesmortensen Sep 09 '22 at 07:08
  • 1
    @jamesmortensen thanks for your kind remind. I has fixed my typo – crifan Sep 09 '22 at 08:05