0

I've been struggling with this for 2 days. I'm a beginner learning Python, going through Automate the Boring Stuff chapter on web scraping using Selenium. I tried PIP3 install for Selenium (as well as geckodriver). That didn't work so I tried some suggestions I found on this and other sites manually changing the PATH using a few different methods. All failed. The only way I was able to launch the browser was by entering the full path to the geckodriver executable:

browser = webdriver.Firefox([Full-Path-Here])

and a specific website using:

(webdriver.Firefox([Full-Path-Here])).get('https://google.com')

but I was unable to work with it using other selenium commands.

A couple of people recommended using Homebrew for package installation since it makes sure to install proper versions and create the corresponding PATH's. So I gave up on the manual approach, installed Homebrew and then used it to re-install Selenium and Geckodriver. Still not working. I thought it may be a problem with Firefox, so I also installed Chromedriver, but am getting a similar error that chromedriver executable can't be found. All of the Homebrew installations were successful and I saw where the appropriate PATHs were created and permissions were granted, but just can't get this to work.

The only thing I can think of that may be an issue is that I'm still on Mac OSX High Sierra, since I understand my MS Office will stop working if I upgrade, but this shouldn't stop me from using Selenium (at least I haven't found anything about this not being supported by Selenium).

Below is the error I am receiving when trying to use a Selenium command without specifying the full path. Any help or suggestions would be greatly appreciated

>>> from selenium import webdriver
>>> browser = webdriver.Chrome()
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    browser = webdriver.Chrome()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
jon
  • 1
  • 1
  • @DebanjanB this is not a duplicate, I checked before posting. – jon May 22 '20 at 17:52
  • Can you update the question how the error you are seeing _selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH_ is different from the dup marked questions? – undetected Selenium May 22 '20 at 18:14
  • For the benefit of others that are having the same problem as me, I did get a partial solution from another forum. This is unrelated to chromedriver or geckodriver. When Launching IDLE with the desktop icon / Spotlight, it wasn't finding all of the PATHs (specifically the one my drivers are located). When I launch IDLE from the Terminal command line, `print(os.getenv('PATH'))` returned the PATH my drivers are stored and the Selenium commands now work properly. Open issue: how can I get Selenium to work by launching outside of the Terminal? – jon May 22 '20 at 18:27
  • @DebanjanB re: "Can you update the question how the error you are seeing selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH is different from the dup marked questions?" - you do not provide a solution, just a workaround in this post. Entering the path every time you use a selenium function is not viable and doesn't work with every function. I tried and explained in my original question that I've used this approach. There should be no need for me to modify my question. – jon May 22 '20 at 18:38
  • @DebanjanB title is updated, please reopen – jon May 22 '20 at 21:03

0 Answers0