Home > Enterprise >  WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally using Selenium
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally using Selenium

Time:08-03

I'm running this script:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)

driver.get('http://192.168.15.1/me_configuracao_avancada.asp',)
user = driver.find_element(By.ID, "txtUser")
user.send_keys("support")
pass_ = driver.find_element(By.ID, "txtPass")
pass_.send_keys("password")
btnLogin = driver.find_element(By.ID, "btnLogin")
btnLogin.click()
driver.get('http://192.168.15.1/reboot.asp',)
reboot = driver.find_element(By.ID, "btnReboot")
reboot.click()
alert = driver.switch_to.alert
alert.accept()
print("Modem Reiniciado!")

I'm using Google Chrome 103.0.5060.134, ChromeDriver 103.0.5060.134 and Selenium version 4.3.0. But when I run the script, this error messages appears:

Traceback (most recent call last):
  File "modem.py", line 7, in <module>
    driver = webdriver.Chrome(service=service)
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
    super().__init__(
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 277, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 370, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "/home/fabio/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
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.)
Stacktrace:
#0 0x56156ba81cd3 <unknown>
#1 0x56156b889968 <unknown>
#2 0x56156b8ae25c <unknown>
#3 0x56156b8a98fa <unknown>
#4 0x56156b8e494a <unknown>
#5 0x56156b8deaa3 <unknown>
#6 0x56156b8b43fa <unknown>
#7 0x56156b8b5555 <unknown>
#8 0x56156bac92bd <unknown>
#9 0x56156bacd418 <unknown>
#10 0x56156bab336e <unknown>
#11 0x56156bace078 <unknown>
#12 0x56156baa7bb0 <unknown>
#13 0x56156baead58 <unknown>
#14 0x56156baeaed8 <unknown>
#15 0x56156bb04cfd <unknown>
#16 0x7fbf96e7c609 <unknown>

Some weeks ago the script ran without any issues, but now it gives this error. How can I correct it?

CodePudding user response:

You need to take care of a couple of things here as follows:

  • You need webdriver.Chrome() only once. If you don't need the arguments through Options() keep:

    driver = webdriver.Chrome(service=service)
    

    and remove:

    driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
    

    or vice versa.

  • If you are executing as a non-root using add_argument('--headless') generally you may not even require the following arguments:

    • add_argument('--no-sandbox')
    • add_argument('--disable-dev-shm-usage')
  • You can try to initiate the new Browsing Context i.e. using:

    driver = webdriver.Chrome(service=ChromeDriverManager().install(), options=chrome_options)
    
  • Your effective code block will be:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    # optional
    chrome_options.add_argument('--no-sandbox')
    # optional
    chrome_options.add_argument('--disable-dev-shm-usage')
    
    driver = webdriver.Chrome(ChromeDriverManager().install(),options=chrome_options)
    driver.get('http://192.168.15.1/me_configuracao_avancada.asp')
    

Note: Ensure that you have installed webdriver-manager and Chrome browser within your system before you kickoff your test execution.

  • Related