Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
InvalidArgumentException:Message:binary不是使用GeckoDriver Firefox Selenium和Python的Firefox可执行文件错误_Python_Selenium_Selenium Webdriver_Firefox_Geckodriver - Fatal编程技术网

InvalidArgumentException:Message:binary不是使用GeckoDriver Firefox Selenium和Python的Firefox可执行文件错误

InvalidArgumentException:Message:binary不是使用GeckoDriver Firefox Selenium和Python的Firefox可执行文件错误,python,selenium,selenium-webdriver,firefox,geckodriver,Python,Selenium,Selenium Webdriver,Firefox,Geckodriver,我遇到了与FireFox二进制文件相关的selenium错误 我使用反斜杠将C:/Users/Mack/AppData/Local/Programs/Python/添加到路径中,然后重新启动。我在这里下载了我认为正确的文件 我将文件放在与路径连接的目录中 要解决这个问题:我尝试使用两个反斜杠 binary = FirefoxBinary("C:\\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27

我遇到了与FireFox二进制文件相关的selenium错误

我使用反斜杠将C:/Users/Mack/AppData/Local/Programs/Python/添加到路径中,然后重新启动。我在这里下载了我认为正确的文件 我将文件放在与路径连接的目录中

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

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

非常感谢对理解此错误的任何帮助。

您的exe路径看起来不正确

“/”(斜杠)在类unix系统中经常用于表示目录结构

窗口使用反斜杠


将字符串更改为使用两个反斜杠而不是正斜杠。

将二进制文件更改为您获得的firefox.exe以及geckodriver的可执行路径

options = Options()
binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
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")
options.binary = binary
driver = webdriver.Firefox(r'C:/Users/Mack/AppData/Local/Programs/Python/Python38-32/geckodriver-v0.27.0-win64/geckodriver.exe',options=options)
此错误消息

selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
…表示作为参数传递给
FirefoxBinary()
二进制文件不是有效的可执行文件

您似乎已将
geckodriver.exe的绝对路径作为导致错误的
FirefoxBinary()
的参数传递给了它


解决方案 您需要传递firefox.exe的绝对路径,而不是
geckodriver.exe
。此外,
firefox\u options
现在已被弃用,您必须使用
options
,您可以使用以下解决方案:

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

options = Options()
options.binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
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(executable_path=r'C:/Users/Mack/AppData/Local/Programs/Python/Python38-32/geckodriver-v0.27.0-win64/geckodriver.exe', options=options)

工具书类 您可以在以下内容中找到一些相关的详细讨论:


在使用Firefox Portable时,似乎无法识别FirefoxPortable.exe文件,相反,在创建二进制路径时,指向“FirefoxPortable\App\firefox64”下的Firefox.exe文件(在我的例子中)。如果Gecko驱动程序正常工作,上述内容是有效的-因此,输出的前几行(在异常之前)如下所示:

[RemoteTestNG] detected TestNG version 7.3.0
1611580278948   geckodriver INFO    Listening on 127.0.0.1:18391
此问题在此处描述的问题之后出现: 因此,它们不是同一个问题——如某些堆栈注释中所示


祝你好运

你确定那是firefox二进制文件吗?正如@arundeepchohan提到的,你对
FirefoxBinary
的论点看起来不正确。这不应该是firefox.exe的路径而不是geckodriver的路径吗?下面是一个正确方法的示例。这不起作用。。。binary=FirefoxBinary(“C:\\Users\Mack\AppData\Local\Programs\Python\Python38-32\geckodriver-v0.27.0-win64\geckodriver.exe”)
[RemoteTestNG] detected TestNG version 7.3.0
1611580278948   geckodriver INFO    Listening on 127.0.0.1:18391