Short:
Having read Controlling the Browser with the selenium Module at https://automatetheboringstuff.com/chapter11, I am trying to run the Selenium Chrome driver in a virtual environment from PyDev. I have managed to do it from outside PyDev, but from within, I get:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
Long:
I'm using Linux Debian 3.10.11-1.
Following https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/, before even starting with PyDev, I . . .
Set up a virtual environment with virtualenv
Installed virtualenv
pip install virtualenv
Made a directory for my project
cd ~/temp/
mkdir my_project
cd my_mproject
Created a virtual environment called env
virtualenv env
Activated it.
source env/bin/activate
Went into Python's interactive mode to tell myself which version of Python I was using
python
Python 2.7.12rc1 (default, Jun 13 2016, 09:20:59) [GCC 5.4.0 20160609] on linux2
Exited out of the interacive mode and installed the Selenium stuff
First the module
pip install selenium
Following suggestion at https://groups.google.com/forum/#!topic/obey-the-testing-goat-book/Ty4FQoV3S0Q, installed chromedriver
cd env/bin/
wget http://chromedriver.storage.googleapis.com/2.22/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
Wrote a little script to see if it would work
from selenium import webdriver driver = webdriver.Chrome()
Ran it. A Chrome web-browser window opened. Great.
Now to try it in PyDev:
Roughly following https://www.caktusgroup.com/blog/2011/08/31/getting-started-using-python-eclipse/ . . .
Installed Eclipse (Neon)
Installed PyDev
From within Eclipse, created a new project (File menu > New Project > General > Project, entered a Project Name and clicked Finish).
Back at the command prompt (because I haven't yet found out how to do this from within Eclipse and PyDev): cd
'ed into my new project's root directory and created a virtual environment.
As before, still at the command prompt, I activated the new project's virtual environment and installed the Selenium module and then the chromedriver
executable file that came up of the chromedriver_linux64.zip
file.
Back in Eclipse, I signed up my project to use the virtual environment, which I guess in PyDev lingo is called not a virtual environment, but rather an interpreter:
Window menu > Preferences > PyDev > Interpreters > Python Interpreters > Add.
Gave the interpreter a name.
For Interpreter Executable, I selected the python2.7
file in my project's virtual environment's bin
directory
Right-clicked on my project, select Properties > PyDev - Interpreter/Grammar > Under Interpreter selected my new interpreter > OK.
Gave my project the same script . . .
from selenium import webdriver driver = webdriver.Chrome()
and ran it by clicking on the Run menu > Run As > Python Run.
Now, though, instead of a Chrome web-browser window opening, I get only a message in Eclipse's console:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
To get the web browser window to open as it does when I run the same scrip from a command prompt, I have tried:
adding the the virtual environment's bin
folder (because that's where the chromedriver
file is) to the interpreter.
deleting the interpreter and creating it new.
copying the chromedriver
into the same directory where my script is. No difference.
adding the chromedriver_linux64.zip
file that I downloaded to the interpreter. Still the same error.
I been continuing by writing my script in PyDev, then turning to the command prompt to run it. Just wish I could run it in PyDev's debug mode.
How can I get this 'chromedriver' in the "PATH
" in PyDev so I can run the script from Eclipse?
To solve the Selenium error "WebDriverException: Message: 'chromedriver' executable needs to be in PATH", install and import the webdriver-manager module by running pip install webdriver-manager . The module simplifies management of binary drivers for different browsers.
Go to the terminal and type the command: sudo nano /etc/paths. Enter the password. At the bottom of the file, add the path of your ChromeDriver. Type Y to save.
getting java lang IllegalStateException The path to the driver executable must be set by the webdriver chrome driver system property. WebDriver driver = new ChromeDriver(); System. setProperty("webdriver.
Not sure if this is the best thing to do, but I have found something that seems to work: I have added to my interpreter the already available variable named PATH, and I have edited that variable's value to include the relative path to my project's virtual environment's bin
directory (ie, the directory where I have the chromedriver
executable file saved).
More precisely:
Window menu in Eclipse > Preferences > PyDev on the left > Interpreters > Python Interpreters.
Selected the interpreter that I had created earlier for my project (as descibed in the question above)
Switched from Libaries to Environment in the bottom half of the Preferences window
Clicked on the Select... button on the right.
A list of Environment Variable appeared.
Scrolled down through the list and found one named PATH. Selected it and click on the OK button.
It and its value (/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
) appeared in the otherwise empty list.
I selected it and clicked on Edit...
Its name and value became editable.
To the right-hand end of the value I added :env/bin
(ie, the relative path from the directory holding my script to my project's virtual environment's bin
directory).
Clicked OK to get back to the Preferences window > Apply in the Preferences window > OK to close the Preferences window.
Ran the program from within Eclipse (selected the script file > Run menu > Run As > Python Run).
A Chrome (well, Chromium - this is Debian) window opened just as had been happening when I was running my program from the command prompt.
Great.
If all attempts to put chromedriver in your PATH fail, you can also hand the executable path to webdriver.Chrome() like so:
chromedriver_loc = '/path/to/chromedriver'
driver = webdriver.Chrome(executable_path=chromedriver_loc)
This was my eventual solution when trying to run chromedriver from a virtualenv.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With