Python Forum
Trouble Setting Up Selenium with FireFox (Python 3 on Windows 10))
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble Setting Up Selenium with FireFox (Python 3 on Windows 10))
#1
I have a script that used to work with Python 2 and I have upgraded to Python 3. I have been going in circles trying different suggestions for solving my problem but nothing has worked. I get the error:

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

Here is my current attempt:

.
.
.
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options as FirefoxOptions
.
.
.
options=FirefoxOptions()
service=Service(r"c:\cygwin64\geckodriver.exe")
options.add_argument("-headless")
driver=webdriver.Firefox(service=service,options=options)
Can someone help me through this? TIA.
Reply
#2
Print the entire error message including the trace information.
Reply
#3
Thanks for the reply:

Traceback (most recent call last):
File "C:\cygwin64\home\MyID\spamcop.pyw", line 28, in <module>
driver=webdriver.Firefox(service=service,options=options)
File "C:\Users\MyID\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\firefox\webdriver.py", line 196, in __init__
super().__init__(command_executor=executor, options=options, keep_alive=True)
File "C:\Users\MyID\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\MyID\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\MyID\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "C:\Users\MyID\AppData\Roaming\Python\Python311\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, 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

This is line 28:

driver=webdriver.Firefox(service=service,options=options)
Reply
#4
Selenium is unable to find the Firefox binary,set corrct path to your firefox.exe binary.
Here is working test that i run.
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.by import By

# Specify the Firefox binary path
options = FirefoxOptions()
options.binary_location = r"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" # Update with your correct path
options.add_argument("-headless")  

service = Service(r"C:\cmder\bin\geckodriver.exe")
driver = webdriver.Firefox(service=service, options=options)
url = "https://www.schneider-group.com/en/about/contacts/"
driver.get(url)
heading = driver.find_element(By.CSS_SELECTOR, '#bx_3218110189_13 > p')
print(heading.text)
Output:
Business Center "Yerevan Plaza", Grigor Lusavorich str. 9, Yerevan, 0015, Armenia
Reply
#5
Thanks for the reply. Python 2 did not require the location of firefox itself. I didn't know that was needed for python 3. That seems to have gotten me over that hump.
Reply
#6
It's usually because Selenium can't locate Firefox properly. Check the geckodriver path and that it matches your system setup. You can explicitly set the path to the Firefox binary.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with installing python domingo251 2 1,363 Sep-23-2023, 12:03 AM
Last Post: ICanIBB
  A question about setting up Python JanOlvegg 1 1,128 Feb-20-2023, 10:21 PM
Last Post: deanhystad
  Setting up new Python kernel for JupyterLab Desktop on M1 Mac daler6 0 1,875 Jun-20-2022, 03:45 AM
Last Post: daler6
  file icons have Firefox icon Ricvourn 4 2,368 Mar-31-2022, 11:40 PM
Last Post: Ricvourn
  Setting permanent user variables in Windows coder420 2 2,150 Jan-04-2022, 10:42 AM
Last Post: Larz60+
  New to python, having trouble with an exercise Salkay 3 3,019 Feb-18-2020, 01:42 AM
Last Post: Salkay
  Trouble Setting a Variable True basing on an Imput VictorVictus 5 3,892 Aug-02-2019, 08:14 PM
Last Post: VictorVictus
  More Python Embedding Trouble jibarra 3 3,822 Jul-11-2019, 09:25 PM
Last Post: Gribouillis
  Advice on Setting Up the Python Environment punksnotdead 1 3,114 May-15-2019, 04:29 PM
Last Post: snippsat
  Coding a logger for firefox history kpiatrou 2 3,791 Dec-25-2018, 06:42 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020