Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided using GeckoDriver

selenium 在使用 Firefox 時, 遇到的問題, firefox 是在官方網站上面取得並安裝,但selenium 似乎沒有取得Firefox預設路徑.

解法:
https://stackoverflow.com/questions/65318382/expected-browser-binary-location-but-unable-to-find-binary-in-default-location

This error 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.

…implies that the GeckoDriver was unable to find the Firefox binary at the default location. Additionally you haven’t passed the moz:firefoxOptions.binary capability.


Solution

Possibly within your system firefox is installed in a custom location and these cases you need to pass the absolute path of the Firefox binary through the moz:firefoxOptions.binary capability as follows:

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

options = Options()
options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
driver = webdriver.Firefox(executable_path=r'C:\WebDrivers\geckodriver.exe', options=options)
driver.get('http://google.com/')

References

You can find a couple of relevant detailed discussion in:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *