Like us on Facebook

LightBlog

October 2, 2018

Automatic download and management of Selenium WebDriver binaries (Driver.exe files)

October 02, 2018 17
In this post we will see how to avoid downloading driver.exe file and setpath for browser binary.

As you guys already know in order to use chrome, firefox or edge browsers, first we need to download a binary file (driver.exe) and need to set path which allows Webdriver to handle browsers.



Below is example how to set path:


By adding a small dependency in your POM.xml (Assuming you are using maven project) we can avoid downloading binary files and set path. In addition, we have to check manually when new versions of the binaries are released. WebDriverManager will do this job for us automatically


How it works:

WebDriver Manager actually gets your browser version and download the compatible browser binary by itself to make you run your code without interruption.

So now, rather than setting the browser binaries, you just need to add below line of code and you’re done


The line WebDriverManager.chromedriver().setup(); WebDriverManager does magic for you:

  1. It checks for the latest version of the WebDriver binary.
  2. It downloads the WebDriver binary if it’s not present on your system.
  3. It exports the required WebDriver Java environment variables needed by Selenium
By default downloaded binary files (driver.exe) files will be stored in .m2 folder. By using below commands you can get the downloaded version and path of binary file.


Below is sample code:



Video is available here: