0

I've been having difficulty getting Selenium-dependent programs in Python to work (when they did in the past).

#Loading Webdriver
options = webdriver.ChromeOptions()
# options.add_argument('--headless')

#Set download folder to newly created folder
prefs = {"download.default_directory" : newfilepath}
options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path=r'C:\Users\ujcho\Desktop\chromedriver.exe', options=options)

wait = WebDriverWait(driver,10)

#Calibrate url to find corresponding file in Karpel
url = "[insert url link here]"
driver.get(url)
login(driver)

For some reason, when the headless argument is added, the program seems to work fine. But when that line is commented out, I get the following error:

Traceback (most recent call last):
  File "c:\Users\ujcho\Desktop\StanfordLabs2\test.py", line 80, in <module>
    driver = webdriver.Chrome(executable_path=r'C:\Users\ujcho\Desktop\StanfordLabs2\chromedriver.exe', options=options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 84, in __init__
    super().__init__(
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__
    super().__init__(
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
    self.error_handler.check_response(response)
  File "C:\Users\ujcho\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

In the past, the code above would open a new window where the remaining program would automate the processes I instructed it to do. Now, it just opens an empty tab on a current window with "data;" in the url bar.

I don't know if this is relevant to the current problem I'm posing, but since I've been prompted to update my ChromeDriver to 113, Selenium has just been breaking down on me. Any help would be appreciated... I've tried reinstalling Google Chrome and that hasn't worked.

What web browser do you recommend using for Python Selenium (esp. for Windows 11)? Curious if Chrome maybe just ain't it.

jocho
  • 13
  • 2
  • Chrome is definitely preferred since Selenium is Google's code. Having said that, they update the Chromedriver much more often than Mozilla does for geckodriver... so I think geckodriver/firefox is a bit more stable. (but with less features...) – pcalkins May 16 '23 at 18:52
  • as for this error: DevToolsActivePort file doesn't exist... I've seen that happen randomly before... I'm guessing it happens sometimes when Chrome decides to update or download updates. The error suggests that the browser couldn't create the file that is needed for chromedriver to get the port and/or session id. This can be caused by permissions issues, or if using custom profiles/options a missing/bad directory.... or another chromedriver/chrome process interfering with browser startup. – pcalkins May 16 '23 at 19:00

1 Answers1

0

That specific error (DevToolsActivePort file doesn't exist) generally happens when there is a permissions issue. (Eg. https://stackoverflow.com/a/50642913/7058266 - but that solution is for Linux users, while you're on Windows.)

If you set download.default_directory to a folder that Selenium doesn't have permission to access, you can expect errors for that.

You also mentioned that you've "been prompted to update my ChromeDriver to 113". The major browser version and the major driver version should match in order for things to work. Many Selenium frameworks have a driver manager to download the correct driver to match your browser, and some of them set specific command-line options by default to work around permissions issues.

Eg. SeleniumBase, (pip install seleniumbase), and then running the following script with python:

from seleniumbase import Driver

driver = Driver(browser="chrome", headless=False)
driver.get("https://seleniumbase.github.io/")
driver.quit()

Additionally, the default downloads folder will be downloaded_files/, which is unique to SeleniumBase and will be separate from the standard downloads folder.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48