InvalidArgumentException:消息:使用GeckoDriver Firefox Selenium和Python,二进制文件不是Firefox可执行文件错误 [英] InvalidArgumentException: Message: binary is not a Firefox executable error using GeckoDriver Firefox Selenium and Python

查看:215
本文介绍了InvalidArgumentException:消息:使用GeckoDriver Firefox Selenium和Python,二进制文件不是Firefox可执行文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到与FireFox二进制文件有关的硒错误.

I am having trouble with a selenium error related to a FireFox binary.

我使用反斜杠将C:/Users/Mack/AppData/Local/Programs/Python/添加到PATH并重新启动.我在这里下载了我认为正确的文件 https://github.com/mozilla/geckodriver/releases 我将文件放在连接PATH的目录中.

I added C:/Users/Mack/AppData/Local/Programs/Python/ to PATH using backslashes and rebooted. I downloaded what I thought is the correct file here https://github.com/mozilla/geckodriver/releases I put the file in the directory connected to PATH.

要解决此问题:我尝试使用两个反斜杠

To remedy this: I tried using two backslashes

binary = FirefoxBinary("C:\\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27.0-win64\geckodriver.exe")

会引发相同的错误

我尝试使用一个反斜杠

binary = FirefoxBinary("C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27.0-win64\geckodriver.exe")

它抛出:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Traceback (most recent call last):
  File "C:\Users\Mack\Desktop\hacker-stories\Trends.py", line 32, in <module>
    browser = webdriver.Firefox(**firefox_binary=binary**)
  File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Mack\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

代码Test.py

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary("C:/Users/Mack/AppData/Local/Programs/Python/Python38-32/geckodriver-v0.27.0-win64/geckodriver.exe")
print(binary)
browser = webdriver.Firefox(firefox_binary=binary)

options = Options()
options.set_preference("browser.download.folderList",2)
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir","/Data")
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream,application/vnd.ms-excel")
driver = webdriver.Firefox(firefox_options=options)

非常感谢您理解此错误.

Any help understanding this error is much appreciated.

推荐答案

此错误消息...

selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

...表示您作为 FirefoxBinary()的参数传递的 binary 文件不是有效的

这篇关于InvalidArgumentException:消息:使用GeckoDriver Firefox Selenium和Python,二进制文件不是Firefox可执行文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆