无法在pycharm - mac上运行简单的webdriver

时间:2017-12-06 13:13:36

标签: python macos selenium firefox pycharm

我在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

请指教,谢谢!

1 个答案:

答案 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}}