我实际上想使用python在网页上“点击”一个按钮。我正在尝试使用硒包(如本示例how_can_i_essentially_click_a_button_on_a_webpage/所示),但是运行代码后,我得到以下消息:
我真的不明白发生了什么。 如果可以的话,我将不胜感激。
from selenium import webdriver
browsre = webdriver.Chrome()
Traceback (most recent call last):
File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
browsre = webdriver.Chrome()
File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\pablo\AppData\Local\Programs\Python\Python36-32\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
答案 0 :(得分:1)
您的chromedriver.exe在哪里?它位于您的测试中指定的路径中吗?
在您的代码中尝试一下:
browser = webdriver.Chrome('/path/to/chromedriver')
答案 1 :(得分:0)
关注
“ chromedriver”可执行文件必须位于PATH
中
您的脚本似乎无法在PATH下找到chromedriver.exe
,因此您需要add the folder, containing the chromedriver.exe
to your system PATH
如果您通过PyCharm运行测试,则可以在“运行/调试”配置中执行相同的操作:
最后但并非最不重要的一点是,您可以修改驱动程序初始化行以包含chromedriver.exe
driver = webdriver.Chrome("c:\\path\\to\\chromedriver.exe")
参考文献: