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.