尝试使用下一个简单脚本从Pycharm IDE或Terminal启动firefox时:

from selenium import webdriver
a = webdriver.Firefox(firefox_binary='/usr/local/bin/geckodriver')


没有打开浏览器会话,我遇到了这个问题:

Traceback (most recent call last):
  File "/Users/avihaiezaguy/Desktop/a.py", line 2, in <module>
    a = webdriver.Firefox(firefox_binary='/usr/local/bin/geckodriver')
  File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 150, in __init__
    keep_alive=True)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 104, in check_response
    status = value["status"]
KeyError: 'status'


当从终端程序调用没有二进制文件的webdriver时,浏览器打开,我得到:

Traceback (most recent call last):
  File "/Users/avihaiezaguy/Desktop/a.py", line 2, in <module>
    a = webdriver.Firefox()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 150, in __init__
    keep_alive=True)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 180, in start_session
    self.session_id = response['sessionId']
KeyError: 'sessionId'


另一方面,Chrome可以正常运行。

谁能帮助解决这个问题?

最佳答案

看过之后:https://github.com/mozilla/geckodriver/releases

将硒从3.0.2升级到3.3.1


  pip install -U硒


现在工作了!

关于python - 在Mac OS上从python运行Firefox Selenium Webdriver无法启动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42970530/

10-11 19:03