尝试使用下一个简单脚本从Pycharm IDE或终端启动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工作正常。
任何人都可以帮忙解决这个问题吗?
答案 0 :(得分:4)
看了之后:https://github.com/mozilla/geckodriver/releases
使用
将硒从3.0.2升级到3.3.1pip install -U selenium
现在它正在工作!