leonidessaguisagjr / webdriverdownloader

Python module to facilitate downloading and deploying WebDriver binaries. Currently supporting geckodriver, chromedriver and operachromiumdriver.
https://pypi.org/project/webdriverdownloader/
MIT License
20 stars 17 forks source link

Not adding in PATH when running #6

Closed ramonmedeiros closed 4 years ago

ramonmedeiros commented 4 years ago

Hey,

first of all, amazing job with this project. I have been using chromedriver_binary, but as I searched for firefox, I ended up seeing your project.

I saw this behaviour:

from webdriverdownloader.webdriverdownloader import GeckoDriverDownloader
from selenium import webdriver

GeckoDriverDownloader().download_and_install()
b = webdriver.Firefox()
b.close()

~/git_ramon/webdriverdownloader/.env/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

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

So, should I do something more to put on path?

leonidessaguisagjr commented 4 years ago

Hello @ramonmedeiros this is expected behavior. As I mention at the top of the README, if you are running as root it will download and install the webdriver binaries into /usr/local/bin, otherwise it will be under $HOME/bin. For most users, the $HOME/bin directory will not be in your PATH by default. I will update the README to better highlight the fact that modifications to the PATH should be explicitly done by the end user as I personally would be very concerned about security if a tool or library I was using made changes to the PATH.

What you can do if the downloaded webdriver is not in the path is capture the return value of either the download() or download_and_install() methods and pass the path to the binary to the webdriver constructor. Here's the link to the documentation for the Firefox driver. You'll want to use the executable_path parameter:

https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver

So something like this should get you what you are looking for:

downloader = GeckoDriverDownloader()
_, geckodriver_path = downloader.download_and_install()
driver = webdriver.Firefox(executable_path=geckodriver_path)

Hope that helps!

ramonmedeiros commented 4 years ago

Amazing. Sorry for not reading the docs