Home > Software engineering >  InvalidArgumentException: Message: binary is not a Firefox executable error in Python linuxmint envi
InvalidArgumentException: Message: binary is not a Firefox executable error in Python linuxmint envi

Time:08-30

I test selenium python and I have these errors with firefox and I can't find the solution. Here my code

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'/usr/bin/firefox')

driver = webdriver.Firefox(executable_path= r'./scrap/geckodriver', options=options) 
driver.get("http://www.google.com") 
print (driver.page_source.encode('utf-8') )
driver.close() 

My error message python linuxmint :

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

I've been searching the forum for a few days, but I can't find a solution for linux mint.

CodePudding user response:

This is an example of working selenium/Firefox setup on Debian, which should also work on Mint, given it's essentially the same os:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as Firefox_Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import time as t
import pandas as pd

firefox_options = Firefox_Options()

# firefox_options.add_argument("--width=1280")
# firefox_options.add_argument("--height=720")

driverService = Service('chromedriver/geckodriver') ## path where you saved geckodriver

browser = webdriver.Firefox(service=driverService, options=firefox_options)

Selenium docs: https://www.selenium.dev/documentation/

CodePudding user response:

As an alternative to options.binary = FirefoxBinary() you can use the binary_location option as follows:

options = Options()
options.binary_location = r'/usr/bin/firefox'
  • Related