0

Selenium installed using pip.

Trying to run below code :

import selenium from selenium import webdriver \#driver = webdriver.Chrome() driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver') time.sleep(5) driver.quit() 

What I get:

python 5formscrape-selenium.py

Traceback (most recent call last):

File "5formscrape-selenium.py", line 5, in driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver')

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in init self.service.start()

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 81, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

$PATH contains /usr/bin/chromedriver

chromedriver file is in /usr/bin with privileges

sudo chmod a*x chromedriver 

So what I'm missing here?

1 Answer 1

0

chromdriver needs to be in PATH means the directory in which it is present should be in PATH and not the whole PATH itself. Change

$PATH=/usr/bin/chromedriver:.... 

to

$PATH=/usr/bin/:.... 

Remove chromedriver, so selenium can search for chromedriver in /usr/bin

Sign up to request clarification or add additional context in comments.

7 Comments

In your script add this and tell me the output `import os; import sys; import subprocess; print(sys.path); print(os.getenv('PYTHONPATH')), print(subprocess.check_output(["which", "chromedriver"]));"
['/sdcard/3python2', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-arm-linux-gnueabihf', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7'] None /usr/bin/chromedriver
as you can see your path doesn't have the /usr/bin directory. Make sure you are using export to export your PATH variable. export PATH=/usr/bin:$PATH before running your script
I see! But using export doesn't change my PATH. If I print it from the terminal: # echo $PATH /usr/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
add this to top of your code os.environ["PATH"] += os.pathsep + "/usr/bin" and see if that helps
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.