Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selenium not running firefox
#1
so i was trying out a simple code like this:
from selenium import webdriver
browser = webdriver.Firefox()
and it returned me a huge error message:
Error:
Traceback (most recent call last): File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start stdin=PIPE) File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 756, in __init__ restore_signals, start_new_session) File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1155, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\Automate the Boring Stuff with Python Course\seleniumwebdriver.py", line 2, in <module> browser = webdriver.Firefox() File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 157, in __init__ self.service.start() File "C:\Users\MSI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
so what does this say? and what do i have to do to fix it?
Reply
#2
not sure where your geckodriver is located on windows, but once you know where it is located, you have to add it to the system path.
this can be done in software:
see: https://stackoverflow.com/questions/2895...pt-windows

you can also use:
browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"yourpathto/geckodriver")
Reply
#3
I have setup in Web-scraping part-2
As both FireFox and Chrome has a headless(not loading Browser),it's okay to also have that setup.
Here a teste that it still work.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time

#--| Setup
options = Options()
options.set_headless(headless=False)
caps = webdriver.DesiredCapabilities().FIREFOX
caps["marionette"] = True
browser = webdriver.Firefox(firefox_options=options, capabilities=caps, executable_path=r"C:\cmder\bin\geckodriver.exe")
#--| Parse
browser.get('https://www.python.org/')
time.sleep(2)
t = browser.find_element_by_xpath('//*[@id="dive-into-python"]/ul[2]/li[1]/div[1]/pre/code/span[1]')
print(t.text)
time.sleep(10)
browser.quit()
Output:
# Python 3: Fibonacci series up to n
If have 64-bit FireFox use 64-bit geckodriver.
options.set_headless(headless=False) Now it's loading browser,True not.
geckodriver.exe in Windows Path Environment Variables Path.
I have cmder in Path,so i use that folder.
Reply
#4
If memory serves me right, I once had success by having the geckodriver in same location as the Python script that uses it.
Though adding it to path is probably a better choice.
Reply
#5
I've been using snippsat's inline solution with success.
Recently, I added it to my path so it was always visible.
Reply
#6
(Aug-31-2018, 09:05 PM)j.crater Wrote: If memory serves me right, I once had success by having the geckodriver in same location as the Python script that uses it.
Though adding it to path is probably a better choice.
Yes can work and not with Firefox.
Firefox setup is more difficult they have messed it more than Chrome.
Example stuff that can make trouble, DesiredCapabilities, marionette, Path, FireFox binary placement and 32/64 bit.

So Chrome always work with simple setup like this.
With cromedriver.exe is same folder as script.
from selenium import webdriver

browser = webdriver.Chrome()
url = 'https://nordic.ign.com/'
browser.get(url)
Just to do a test,to make sure it work,no Path is used here just cromedriver in same folder.
from selenium import webdriver
import time

browser = webdriver.Chrome()
url = 'https://nordic.ign.com/'
browser.get(url)
time.sleep(5)
close_cookie = browser.find_elements_by_css_selector('#_evh-ric-gc')
close_cookie[0].click()
top_storie = browser.find_elements_by_css_selector('#blogroll > li:nth-child(1) > article > h3 > a')
print(top_storie[0].text)
time.sleep(5)
browser.quit()
Output:
Wolverine's Whereabouts Revealed as the X-Men Meet a Deadly New Enemy
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,270 Apr-20-2023, 05:27 PM
Last Post: farshid
  Connect to existing Firefox session with Selenium euras 0 5,462 Feb-11-2021, 02:54 PM
Last Post: euras
  error when running headless selenium julio2000 2 4,585 Feb-01-2020, 12:41 PM
Last Post: julio2000
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 2,555 Aug-04-2019, 11:10 AM
Last Post: pjn4
  Selenium Web Driver Exe not running in other PC's Utkarsh29 2 4,498 Feb-28-2019, 05:48 PM
Last Post: snippsat
  Firefox Selenium (open new tab) oneclick 1 7,768 Dec-29-2018, 06:59 AM
Last Post: hbknjr
  selenium - chrome crashes when chrome is running. RvBVakama 4 15,312 Dec-16-2018, 06:32 PM
Last Post: metulburr
  Proxy Variable in Selenium wont work with FireFox Profile Proxy Setting. MIPython 0 8,531 Jul-13-2018, 05:43 PM
Last Post: MIPython
  How to geckodriver anonymous firefox mariolopes 5 7,221 Feb-10-2018, 10:58 PM
Last Post: mariolopes
  Selenium with headless firefox is slow mgtheboss 4 14,994 Jan-13-2018, 09:03 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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