selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser

后端 未结 2 827
情书的邮戳
情书的邮戳 2021-01-20 17:33

I have following environment at my local Chrome 67 Python 3.5.0 Selenium 3.12.0

I have downloaded chromedriver with version 2.39

I have .py file as follows

相关标签:
2条回答
  • 2021-01-20 17:47

    At a first glance to your code trial it seems there is a minor bug in the value of the argument executable_path. Instead of hromedriver.exe it should have been:

    # Windows OS
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
    # Linux OS
    driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
    

    This error message...

    selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe
    

    ...implies that the the program/script was unable to initiate/spawn the ChromeDriverService through chromedriver.exe.

    The potential reason for the error can be:

    • Due to missing the entry 127.0.0.1 localhost in /etc/hosts

    Solution

    • Windows OS - Add 127.0.0.1 localhost to /etc/hosts

    • Mac OSX - Ensure the following entries:

      127.0.0.1   localhost
      255.255.255.255 broadcasthost
      ::1 localhost
      fe80::1%lo0 localhost   
      

    References

    As per the discussion in selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver:

    • Selenium does not require 127.0.0.1 localhost to be explicitly set in the host file.
    • However it is mandatory requirement to map localhost to the IPv4 local loopback (127.0.0.1)
    • The mechanism of this mapping does not have to be through the hosts file always.
    • On Windows OS systems it is not mapped in the hosts file at all (resolving localhost is done by the DNS resolver).

    TL;DR

    How to reset the Hosts file back to the default

    0 讨论(0)
  • 2021-01-20 17:50

    You've made a mistake into the executable address :

    driver = webdriver.Chrome(executable_path="hromedriver.exe")
    

    It should be :

    driver = webdriver.Chrome(executable_path="chromedriver.exe")
    
    0 讨论(0)
提交回复
热议问题