0

I trying to use selenium in jupyter notebook on Firefox. I have installed the geckodriver in /usr/bin directory .When I run my code it says:

WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

if I run the command %env PATH following output is displayed:

$PATH:/usr/bin/
from selenium import webdriver

browser = webdriver.Firefox()

I have even tried

browser=webdriver.Firefox(executable_path=r'/usr/bin/geckodriver')

Can somebody help me solve this?

Prophet
  • 32,350
  • 22
  • 54
  • 79
HackerMan
  • 47
  • 1
  • 8
  • please check https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path if it is useful – nevergiveup May 19 '21 at 06:52

2 Answers2

2

I hope you are working with geckodriver on the local machine and providing the absolute path for the driver to run, This can be done automatically using webdriver-manager python

Advantages of using it are-

  1. You don't have to give the path every time to run code.
  2. Makes the code portable and easy to run on any machine without checking for geckodriver or chromedriver.

pip install webdriver-manager

Now the above code in the question can be changed to work simply with,

from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())

If the above doesn't help, try doing this.

autoinstaller for geckodriver- pip install geckodriver-autoinstaller

from selenium import webdriver 
import geckodriver_autoinstaller 

geckodriver_autoinstaller.install() #checks for driver or install it. driver = 
webdriver.Firefox() driver.get("python.org")  

this worked fine for me, otherwise, try to give a full path after downloading the latest geckodriver binary file.

0

Try to implement this with a Maven project so you can add dependencies in the pom.xml file. so you dont have to give the path each time. Refer this article here.Its in java but will help.