What is the difference between WebDriverManager.chromedriver().setup();
and System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
when do we use either of the code. I'm a newbie. Please explain.
-
1What have you found out so far with your own research?– shadowspawnCommented Sep 7, 2019 at 4:06
2 Answers
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
The above statement is used to set the driver binaries of chromedriver, for this you need to download the chromedriver.exe file and then accordingly mention the path of chromedriver.exe in the System.setproperty statement, if your chrome version is updated, then you will have to again download the appropriate chromedriver.exe file again and then set the driver binaries to proceed further, similarly for firefox you will have to download firefoxdriver.exe and then use System.setProperty to set the driver binaries.
WebDriverManager.chromedriver().setup()
This is an efficient way to set driver binaries without having to actually download the driver binaries, you can just add the webdrivermanager dependency in your maven project (pom.xml) file and then set the driver binaries using the above statement.
Webdrivermanager does the follwoing:
- It checks the version of the browser installed in your machine (e.g. Chrome, Firefox).
- It checks the version of the driver (e.g. chromedriver, geckodriver). If unknown, it uses the latest version of the driver.
- It downloads the WebDriver binary if it is not present on the WebDriverManager cache (~/.m2/repository/webdriver by default).
WebDriverManager resolves the driver binaries for the browsers Chrome, Firefox, Opera, PhantomJS, Microsoft Edge, and Internet Explorer. For that, it provides several drivers managers for these browsers. These drivers managers can be used as follows
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
To use any specific version of chromedriver, use the below statement:
WebDriverManager.chromedriver().version("2.26").setup();
What is the difference between
WebDriverManager.chromedriver().setup();
andSystem.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
WebDriverManager.chromedriver().setup()
That will automatically download (or update) the appropriate chromedriver
/chromedriver.exe
for you. (It is not part of Selenium, so you must install WebDriverManager
to use it).
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
That sets a property with the location of chromedriver.exe
. Selenium client will use this to find the binary on your system. It assumes it already exists in that location.