gpt4 book ai didi

python - 在 mac OS 上从 python 运行 firefox selenium webdriver 无法启动

转载 作者:太空宇宙 更新时间:2023-11-04 10:02:08 52 4
gpt4 key购买 nike

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

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

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

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

将 selenium 从 3.0.2 升级到 3.3.1

pip install -U selenium

现在可以了!

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

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com