Importing a function that uses selenium with ipynb not working on Windows

Issue

I wrote a function for scraping data from a website in a Jupyter Notebook. The function works perfectly fine when running in that notebook and when I use ipynb to import the functions from that notebook it imports them successfully. Then when I run the function in the second notebook I get: WebDriverException: Message: 'chromedriver' executable needs to be in PATH.. The weirdest part is that this works fine on my MacBook but not on my PC. Has anyone encountered this and found a solution?

The import I use is: from ipynb.fs.full.my_notebook import my_function. I then create a dataframe using df = my_function(x, y, z), which is where I get the error.

Solution

It’s possible to set the path to chromedriver executable instead of using the one in the PATH.

from selenium.webdriver.chrome.service import Service

service = Service(executable_path='/Users/<user_name>/Downloads/chromedriver')

...

Answered By – lepsch

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published