Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

后端 未结 14 1984
走了就别回头了
走了就别回头了 2020-11-21 23:05

Recently I switched computers and since then I can\'t launch chrome with selenium. I\'ve also tried Firefox but the browser instance just doesn\'t launch.

f         


        
14条回答
  •  春和景丽
    2020-11-21 23:31

    This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.

    Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.

    It solved the issue I was having; not elegantly but it works.

    from selenium import webdriver
    from selenium.common.exceptions import WebDriverException
    
    try:
        self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
    except WebDriverException as e:
        print("\nChrome crashed on launch:")
        print(e)
        print("Trying again in 10 seconds..")
        sleep(10)
        self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
        print("Success!\n")
    except Exception as e:
        raise Exception(e)
    

提交回复
热议问题