1

Here's my code

browser = webdriver.Firefox('C:\\Users\\ojadi\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe')
browser.get('https://www.google.co.uk/')

Here is the error i keep getting

The directory name is invalid: 'C:\\Users\\ojadi\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe'

This is where I put the driver

C:\Users\ojadi\Downloads\geckodriver-v0.26.0-win64

Please help me,

Samuel Okasia
  • 95
  • 1
  • 6
  • Does this answer your question? [Setting path to firefox binary on windows with selenium webdriver](https://stackoverflow.com/questions/25713824/setting-path-to-firefox-binary-on-windows-with-selenium-webdriver) – Alexey R. Mar 03 '20 at 17:25

3 Answers3

2

The first, unnamed parameter when using webdriver.Firefox() is firefox_profile, which takes either a FirefoxProfile object or a string. If it's a string, you're telling the Python language bindings what directory you want to use as the template for the anonymous profile used when launching Firefox.

Other answers may have you attempting to use the firefox_binary argument. This is incorrect, as that is the argument specifying the path to the Firefox binary, not the geckodriver binary.

The argument you actually want to use is executable_path, which is the argument that refers to the location of the geckodriver binary. To wit, you want something like the following:

browser = webdriver.Firefox(executable_path='C:\\Users\\ojadi\\Downloads\\geckodriver-v0.26.0-win64\\geckodriver.exe')

Now, if you also need to specify a path to a specific Firefox binary installation, you can specify both firefox_binary and executable_path.

JimEvans
  • 27,201
  • 7
  • 83
  • 108
0

try to replace your line with this one bellow:

browser = webdriver.Firefox(r'C:\Users\ojadi\Downloads\geckodriver-v0.26.0-win64\geckodriver.exe')
yehezkel horoviz
  • 198
  • 3
  • 10
0

I just ran this code.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys


driver = webdriver.Firefox(executable_path=r'C:\Selenium\geckodriver.exe')
driver.set_page_load_timeout(60)
driver.get("https://www.msnbc.com/")

continue_link = driver.find_element_by_tag_name('a')
elems = driver.find_elements_by_xpath("//a[@href]")
for elem in elems:
    print(elem.get_attribute("href"))

I got this result.

https://www.msnbc.com/
https://www.msnbc.com/listen
https://www.msnbc.com/live
https://www.nbcnews.com/
https://www.today.com/
https://www.msnbc.com/
https://www.msnbc.com/rachel-maddow-show
https://www.msnbc.com/morning-joe
https://www.msnbc.com/deadline-white-house
https://www.msnbc.com/mtp-daily
https://www.msnbc.com/the-beat-with-ari-melber
https://www.msnbc.com/all

etc., etc., etc.

https://www.msnbc.com/
https://www.nbcnews.com/pages/about-nbc-news-digital
https://www.msnbc.com/help
https://www.nbcunicareers.com/
https://www.msnbcstore.com/?cid=MSNBCSTRE
https://www.nbcuniversal.com/privacy/?brandA=MSNBC&intake=MSNBC
https://www.nbcuniversal.com/privacy/notrtoo/?brandA=MSNBC&intake=MSNBC
https://www.msnbc.com/terms-of-service
https://www.msnbc.com/closed-captioning
https://www.msnbc.com/transcripts
https://www.msnbc.com/advertising-and-partnerships
http://info.evidon.com/pub_info/1196?v=1
https://www.nbcnews.com/
https://www.msnbc.com/
https://www.today.com/

Make sure you download the appropriate (32-bit or 64-bit) geckodriver from the link below.

https://github.com/mozilla/geckodriver/releases

ASH
  • 20,759
  • 19
  • 87
  • 200