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()
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:
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.
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.
Already on GitHub? Sign in to your account OS: Ubuntu Server 16.04 Selenium Version: Java, 3.12.0 Browser Version: 2.40
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With