WebDriverManager:
Why use WebDriverManager:
Manages various
driver executable files like chromedriver.exe, edgedriver.exe, geckodriver.exe, etc.
chromedriver.exe
edgedriver.exe
geckodriver.exe...etc
WebDriverManager
is an open-source jar file that:
- Downloads all necessary
driver executable files automatically.
- Ensures the drivers are
always the latest version.
- Manages the driver
executable files efficiently.
When you
use WebDriverManager to download chromedriver.exe, it
typically downloads the driver executable files to a default cache location in
the user's home directory. The exact location can vary based on the operating
system and the version of WebDriverManager being used. By default, the path is
usually something like:
- Windows: C:\Users\<YourUserName>\.cache\selenium
- Mac/Linux: /home/<YourUserName>/.cache/selenium or /Users/<YourUserName>/.cache/selenium
Changing the Cache Location
If you want to change the default location where WebDriverManager downloads
the driver executables, you can do so by configuring the wdm.cachePath system property. Here is
how you can set a custom location:
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CustomCachePath {
public
static void main(String[] args) {
//
Set the custom cache path
System.setProperty("wdm.cachePath",
"C:\\custom\\path\\to\\cache");
//
Automatically download the latest version of chromedriver.exe to the custom
path
WebDriverManager.chromedriver().setup();
//
Create an instance of ChromeDriver
WebDriver driver = new ChromeDriver();
//
Navigate to a website
driver.get("https://www.example.com");
//
Your test code here
//
Close the browser
driver.quit();
}
}
Checking the Downloaded Files
After running the code, you can navigate to the specified directory to
verify that the chromedriver.exe
file has been downloaded. This can help ensure that the WebDriverManager is
functioning correctly and managing driver versions automatically as expected.
Add below
depenedency in pom.xml :
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
-->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
-->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.5.2</version>
</dependency>
package com.birla;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class WebDriverManagerBasics1
{
public static
void main(String[] args) {
// System.setProperty("webdriver.chrome.driver",
"C:\\Users\\Lenovo\\Downloads\\chromedriver_win32
(8)\\chromedriver.exe");
// download chromedriver.exe
manually and write above statement in code
// if
browser version changes -- we have to download same version of driver.exe
// ex: chrome browser Version 110.0.5481.178 --->
chromedriver.exe 110
//
chrome browser Version 112 --
---> chromedriver.exe 112
//
download chromedriver.exe file with WebdriverManager
// WebDriverManager.chromedriver().setup();
//
download specific version
WebDriverManager.chromedriver().browserVersion("126.0.6478.63");
//2 create obj for ChromeDriver- Class
WebDriver
driver = new ChromeDriver();// open
chrome browser with empty url
driver.get("file:///C:/brahma/Practise/SelniumPractiseNew/SampleWebpage.html");
//
click Electronics, Computers
checkbox
WebElement ElectronicsCheckBoxele= driver.findElement(By.id("eleId"));
ElectronicsCheckBoxele.click();
WebElement ComputersChkboxEle= driver.findElement(By.id("cid"));
ComputersChkboxEle.click();
}
}
EdgeDriver Setup:
package WebdriverManagerBasics;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.edge.EdgeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class EdgeBrowserBasics2 {
public static
void main(String[] args) {
// System.setProperty("webdriver.edge.driver",
"C:\\Users\\Lenovo\\Downloads\\edgedriver_win64
(3)\\msedgedriver.exe");
//
download edgedriver.exe file
// WebDriverManager.chromedriver().setup();
//
download latest edgedriver.exe in run
time
// download
specific version
// WebDriverManager.edgedriver().browserVersion("117.0");
// if we want to download specific version of
browser- we can download by specifying verison no
WebDriver driver=
new EdgeDriver();
driver.get("file:///C:/brahma/Practise/SelniumPractiseNew/SampleWebpage.html");
//
click 'Electronics', 'Computers'
checkbox
WebElement ElectronicsCheckBoxele= driver.findElement(By.id("eleId"));
ElectronicsCheckBoxele.click();
WebElement ComputersChkboxEle= driver.findElement(By.id("cid"));
ComputersChkboxEle.click();
}
}
-
HW Geckodriver
setup with help of Webdriver manager ?
HW IE driver
setup with help of Webdriver manager ?
download latest chromedriver.exe file and add to the project
download latest chromedriver.exe
in run time using webdrivermanager
No comments:
Post a Comment