我在mac上安装了pycharm(python3.6)+ selenium(3.8)。
尝试运行:
from selenium import webdriver
driver=webdriver.Firefox()
我收到错误:
/Users/ronavaida/PycharmProjects/untitled/venv/bin/python /Users/ronavaida/PycharmProjects/untitled/testselenium.py
Traceback (most recent call last):
File "/Users/ronavaida/PycharmProjects/untitled/testselenium.py", line 3, in <module>
driver=webdriver.Firefox()
File "/Users/ronavaida/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
keep_alive=True)
File "/Users/ronavaida/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Users/ronavaida/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Users/ronavaida/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/Users/ronavaida/PycharmProjects/untitled/venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
请指教,谢谢!
答案 0 :(得分:0)
您看到的错误说明了一切:
geckodriver
您需要从此link
下载最新的 WebDriver
二进制文件并将其保存在系统中,并在初始化时提供Browser
二进制文件的绝对路径 from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
driver.get('https://www.google.co.in')
driver.quit()
和 {{1}} 实例如下:
{{1}}