简体   繁体   中英

I am having trouble getting Firefox to work with Selenium (Python) as it doesn't seem to be able to find geckodriver.exe

For a bit of context I am on a 64-bit, Windows 10 operating system and my python version is 3.9.7. I have Firefox version 96.0.2 installed and geckodriver 0.30.0

Every time I try and run webdriver.Firefox() I get the exception: 'geckodriver' executable needs to be in PATH.

I have extracted the geckodriver executable (For want of anywhere better I put the executable in the Mozilla Firefox folder in C:\Program Files and tried to add it to PATH by doing the following:

  • On Windows system right click on My Computer or This PC.

  • Select Properties.

  • Select advanced system settings.

  • Click on the Environment Variables button.

  • From System Variables select Path.

  • Click on Edit button.

  • Click New button.

  • Paste the path of GeckoDriver file.

So now at the bottom of the list in the Path environment variable I have 'C:\Program Files\Mozilla Firefox'. I have also tried 'C:\Program Files\Mozilla Firefox\geckodriver.exe'. In both cases I still get the same error message about geckodriver needing to be in PATH.

Can anyone please tell me what is going on and how to fix it?

You can set executeble path inside the "Firefox" function

from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox\geckodriver.exe")
driver.get('http://test.com')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM