selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome

后端 未结 2 1380
傲寒
傲寒 2020-11-21 22:36

when i run my script , i got this error

Traceback (most recent call last):
  File \"C:\\Users\\ishaq\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-         


        
相关标签:
2条回答
  • 2020-11-21 23:09

    I had the same error in Linux. The fix is pretty simple. Just run this command and the error will go away.

    sudo apt install chromium-chromedriver
    
    0 讨论(0)
  • 2020-11-21 23:26

    If we analyze the logs it seems the main issue is with in start os.path.basename(self.path) and subsequent error message selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

    So it's clear from the error that the Python client was unable to locate the chromedriver binary.

    You have to take care of a couple of points here:

    1. chrome_options.binary_location : The parameter configures the chrome.exe not the chromedriver.exe
    2. os.path.abspath("chromedriver") will pick up the file path of chromedriver but won't append chromedriver.exe at the end.
    3. Here is the sample code on my Windows 8 system to start Chrome in Headless Mode:

      from selenium import webdriver  
      from selenium.webdriver.chrome.options import Options 
      
      chrome_options = Options()  
      chrome_options.add_argument("--headless")  
      driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')  
      driver.get("http://www.duo.com") 
      print("Chrome Browser Initialized in Headless Mode")
      driver.quit()
      print("Driver Exited")
      
    0 讨论(0)
提交回复
热议问题