[Solved] Error: DevToolsActivePort file doesn't exist


Hello friends, I was running a web scraper in python and I recieved this error

1
WebDriverException: unknown error: DevToolsActivePort file doesn’t exist

I was trying to create a webdriver.Chrome() instance by using the following code

1
2
from selenium import webdriver
driver = webdriver.Chrome()

Then I searched on internet about it, added Selenium to $PATH variable, tried to run it in –no-sandbox mode, and lots of other things but with no success.
But, finally after extensive research on this topic I found the correct way to implement it.
I will start from the start
1. Install pip

1
sudo apt install python3-pip

2. Install Selenium

1
pip install selenium

3. Install Chromium

1
sudo apt-get install chromium-browser

4. Copy the path of Chromium, in my case it was:

1
/usr/bin/chromium-browser

5. Implement this code in python

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

1
2
options.binary_location = "/usr/bin/chromium-browser"
driver = webdriver.Chrome(chrome_options=options)

And now, you won’t get the error on executing your python code!
You can also add below options according to your needs:

1
2
3
4
5
6
7
8
9
10
11
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("--window-size=1920,1080");
options.addArguments("--enable-precise-memory-info");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-default-apps");
options.addArguments("test-type=browser");
options.AddArgument("--incognito");
options.AddArgument("--no-sandbox");

Thanks for reading! Happy Coding :)
Buy Me a Coffee - https://www.buymeacoffee.com/agautam

Comments