DEV Community

Tony Colston
Tony Colston

Posted on

chromedriver role in the world

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)
Enter fullscreen mode Exit fullscreen mode

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%
Enter fullscreen mode Exit fullscreen mode

If you are running in Linux or OSX you will use this syntax in bash.

export PATH=/home/yourhome/projects/headless:$PATH
Enter fullscreen mode Exit fullscreen mode

And this is the code you will use to start Chrome in that case.

    driver = webdriver.Chrome()
Enter fullscreen mode Exit fullscreen mode

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.

Discussion (0)