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

后端 未结 14 1763
走了就别回头了
走了就别回头了 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)
    
    0 讨论(0)
  • 2020-11-21 23:34

    Try to download HERE and use this latest chrome driver version.

    https://sites.google.com/a/chromium.org/chromedriver/downloads

    EDIT:

    Try this:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.add_argument('--disable-dev-shm-usage')
    d = webdriver.Chrome('/home/PycharmProjects/chromedriver',chrome_options=chrome_options)
    d.get('https://www.google.nl/')
    
    0 讨论(0)
  • 2020-11-21 23:34

    i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.

    0 讨论(0)
  • 2020-11-21 23:37

    A simple solution that no one else has said but worked for me was not running without sudo or not as root.

    0 讨论(0)
  • 2020-11-21 23:41

    in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:

    opts.set_headless(True)
    
    0 讨论(0)
  • 2020-11-21 23:46

    This error message...

    selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
      (unknown error: DevToolsActivePort file doesn't exist)
      (The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
    

    ...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.

    Your main issue is the Chrome browser is not installed at the default location within your system.

    The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:

    Chrome_binary_expected_location

    1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


    Solution

    In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:

    • Python Solution:

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      options = Options()
      options.binary_location = "C:\\path\\to\\chrome.exe"    #chrome binary location specified here
      options.add_argument("--start-maximized") #open Browser in maximized mode
      options.add_argument("--no-sandbox") #bypass OS security model
      options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
      options.add_experimental_option("excludeSwitches", ["enable-automation"])
      options.add_experimental_option('useAutomationExtension', False)
      driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
      driver.get('http://google.com/')
      
    • Java Solution:

      System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
      ChromeOptions opt = new ChromeOptions();
      opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");  //chrome binary location specified here
      options.addArguments("start-maximized");
      options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
      options.setExperimentalOption("useAutomationExtension", false);
      WebDriver driver = new ChromeDriver(opt);
      driver.get("https://www.google.com/");
      
    0 讨论(0)
提交回复
热议问题