Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix selenium "DevToolsActivePort file doesn't exist" exception in Python [duplicate]

When I use both arguments --headless and user-data-dir. Selenium raise selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist exception. If only 1 of them is used, then everything works as needs.

I tried to swap arguments and remove some of them. Specified the full path to chromedriver.exe. None of this helped.

chromeOptions.add_argument("--disable-dev-shm-using") DIDN'T HELP ME.

login = "test"
chromeOptions = webdriver.ChromeOptions() 
chromeOptions.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) 
chromeOptions.add_argument("--no-sandbox") 
chromeOptions.add_argument("--disable-setuid-sandbox") 
chromeOptions.add_argument("--disable-dev-shm-using") 
chromeOptions.add_argument("--disable-extensions") 
chromeOptions.add_argument("--disable-gpu") 
chromeOptions.add_argument("start-maximized") 
chromeOptions.add_argument("disable-infobars") 
chromeOptions.add_argument("--headless") 
chromeOptions.add_argument(r"user-data-dir=.\cookies\\" + login) 
b = webdriver.Chrome(chrome_options=chromeOptions) 
b.get("https://google.com/") 
b.quit() 
like image 416
vffuunnyy Avatar asked Jun 17 '19 19:06

vffuunnyy


People also ask

How to fix “error - devtoolsactiveport file doesn't exist”?

Error: unknown error: 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. This helped! Try reinstalling Chrome. Press: CTRL+T Then enter the commands:

What is headless and no sandbox in selenium?

The “– no sandbox” parameter allows chrome to run under the root permission, and the “– headless” parameter allows chrome to have a better experience without opening the graphical interface Under Ubuntu system, selenium opens the Firefox browser and prompts’ unable to find a matching set of capabilities.

How to implement selenium on $PATH variable?

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. 1. Install pip 2. Install Selenium 3. Install Chromium 4.

What version of selenium is available on GitHub?

Already on GitHub? Sign in to your account OS: Ubuntu Server 16.04 Selenium Version: Java, 3.12.0 Browser Version: 2.40


1 Answers

I solve it by adding an argument --remote-debugging-port=<port>

chromeOptions = webdriver.ChromeOptions() 
chromeOptions.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) 
chromeOptions.add_argument("--no-sandbox") 
chromeOptions.add_argument("--disable-setuid-sandbox") 

chromeOptions.add_argument("--remote-debugging-port=9222")  # this

chromeOptions.add_argument("--disable-dev-shm-using") 
chromeOptions.add_argument("--disable-extensions") 
chromeOptions.add_argument("--disable-gpu") 
chromeOptions.add_argument("start-maximized") 
chromeOptions.add_argument("disable-infobars")
chromeOptions.add_argument(r"user-data-dir=.\cookies\\test") 

b = webdriver.Chrome(chrome_options=chromeOptions) 
b.get("https://google.com/") 
b.quit()
like image 156
vffuunnyy Avatar answered Oct 22 '22 22:10

vffuunnyy