“ chromedriver”可执行文件必须位于PATH中,但已经存在

时间:2019-11-07 09:30:28

标签: javascript python python-3.x

我想使用Python向this website发送消息。

可以说是用python来做以下事情:

introducir la descripción de la imagen aquí

这就是为什么我用Selenium尝试以下脚本的原因:

api_location = 'http://iphoneapp.spareroom.co.uk'
api_search_endpoint = 'flatshares'
api_details_endpoint = 'flatshares'

location = 'http://www.spareroom.co.uk'
details_endpoint = 'flatshare/flatshare_detail.pl?flatshare_id='
def contact_room(self, room_id):
    url = '{location}/{endpoint}/{id}?format=json'.format(location=self.api_location, endpoint=self.api_details_endpoint, id=room_id)
    from selenium import webdriver

    driver = webdriver.Chrome()
    # Go to your page url
    driver.get(url)
    # Get button you are going to click by its id ( also you could use find_element_by_css_selector to get element by css selector)
    button_element = driver.find_element_by_id('button id')
    button_element.click()

但是它返回:

C:\Users\antoi\Documents\Programming\projects\roomfinder>python test_message.py
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Python36\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Python36\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_message.py", line 21, in <module>
    contact_room(13829371)
  File "test_message.py", line 14, in contact_room
    driver = webdriver.Chrome()  # Optional argument, if not specified will search path.
  File "C:\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

虽然我已将其添加到PATH中:

introducir la descripción de la imagen aquí

我是javascript学习者。如果您有技巧和时间来展示如何用Javascript回答问题,我也总是很乐于学习:)

1 个答案:

答案 0 :(得分:0)

chromedriver必须位于python脚本的路径中,或者需要将其添加到驱动程序中:

driver_path = 'Path\to\your\Driver'
driver = webdriver.Chrome(executable_path = driver_path)

如果您谈论webdriver.Firefox(),为什么要使用Chrome