当我尝试在Selenium中创建Firefox示例时,我收到以下错误:
Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
我用的是Ubuntu 20.04
如有任何建议,我们将不胜感激。
browser = webdriver.Firefox()
Traceback (most recent call last):
File "key.py", line 10, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
2条答案
按热度按时间8ljdwjyq1#
此错误消息...
...表示GeckoDriver在尝试启动/生成新的 * Browsing Context *(即 * Firefox Browser * 会话)时无法找到 * firefox * 二进制文件。
原因
此错误的可能原因可能是以下原因之一:
溶液
可能的解决方案有:
Options()
示例传递 * firefox * 二进制文件的 * 绝对路径 *,如下所示:参考文献
您可以在以下内容中找到一些相关的详细讨论:
kpbpu0082#
它通过传递FirefoxBinary()选项对我起作用。
我的工作代码是-
从selenium. webdriver. firefox. firefox_binary导入Firefox二进制文件
从 selenium 导入webdriver
火狐二进制=火狐二进制()
驱动程序= Web驱动程序. Firefox(火狐二进制=火狐二进制)"""
上面的代码肯定对每个人都有效。