0

When I try to use Python3, Selenium & ChromeDriver to launch a non-headless Chrome browser instance (from VSCode's Terminal)

from chromedriver_py import binary_path 
from selenium import webdriver

driver = webdriver.Chrome(executable_path=binary_path)
driver.get('http://google.com')
driver.close()

this will throw the error

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (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.)

The only way I get avoid the error is to run in headless mode:

from chromedriver_py import binary_path  
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')

driver = webdriver.Chrome(executable_path=binary_path, options=options)
x = driver.get('http://google.com')
driver.close()

Why does it not work unless it is in headless mode? Both code works when not running using Vscode's Terminal. How can it run it non-headless from within Vscode?


Using chromedriver-py==88.0.4324.96 & selenium==3.141.0 on Ubuntu 20.04. Python file is executed using VSCode.

Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
  • Does this answer your question? [WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser](https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t) – Cyrus Feb 26 '21 at 05:19
  • @Cyrus Thanks, clarified that my question is using VSCode's Terminal to launch the Pytho script. Everything works as expected when not using VSCode to execute the Python code. – Nyxynyx Feb 26 '21 at 05:30
  • Perhaps your script is inheriting improper permissions from VS Code. Do you run your script as super user when you run it from the terminal? – Cyrus Feb 26 '21 at 05:34
  • @Cryus I am running the script as a non-root user, both in VSCode which gave the error, as well as in a regular terminal which does not give the error – Nyxynyx Feb 26 '21 at 14:39

0 Answers0