chromedriver has one job in life and that is running Chrome for Selenium. It is tied tightly to Chrome and is versioned with Chrome. In other words you need chromedriver version 75 to run Chrome 75. If you ever upgrade Chrome for your tests then you will need to upgrade chromedriver too.
To use chromedriver you will need to include it in the source code when you invoke the Chrome constructor. Or you will need to include it in your PATH variable that is used in the environment of your script.
I will show examples of both.
Here is how you would use the path to chromedriver in your source code.
cpath = "e:\\projects\\headless\\chromedriver.exe"
driver = webdriver.Chrome(cpath)
And here is how you would set the PATH up and do the same thing. Assume chromedriver.exe is in the directory e:\projects\headless
This is done at the command prompt or in the bat file you are using to run your test. (WINDOWS ONLY BATCH FILE HERE)
set PATH=e:\projects\headless;%PATH%
If you are running in Linux or OSX you will use this syntax in bash.
export PATH=/home/yourhome/projects/headless:$PATH
And this is the code you will use to start Chrome in that case.
driver = webdriver.Chrome()
The Python language binding for Selenium needs to know where chromedriver is located. You can tell the binding explicitly or implicitly. Either will work.
I have a tendency to use the PATH based one when I writing scripts initially for myself.
Top comments (0)