How to get driver path in selenium-java 4.10.0

Sameera De Silva
1 min readJun 18, 2023

--

Since below code is not working this version due to we need to pass type as “Capabilities” lets see the fix for this .

        String chromeDriverPath = SeleniumManager.getInstance().getDriverPath("chromedriver");

A reason why we need to pass Capabilities instead of String is now, is getDriverPath methods needs

  public String getDriverPath(Capabilities options) {

So below code contents how to get driver path for Edge,Chrome and firefox.

public class ExtraSpecialLocators {

WebDriver driver;

@BeforeClass
public void setDriver() {
// Create ChromeOptions object and set the desired capability
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("goog:chromeOptions", true);
// These codes are optional

ChromeOptions ChromeOpt = new ChromeOptions();
// Pass the ChromeOpt option it takes as a type of Capability.
String chromeDriverPath = SeleniumManager.getInstance().getDriverPath(ChromeOpt);
System.out.println("chromeDriverPath--" + chromeDriverPath);
// These codes are optional

// Create EdgeOptions object and set the desired capability
EdgeOptions edgeOptions = new EdgeOptions();
String edgeDriverPath = SeleniumManager.getInstance().getDriverPath(edgeOptions);
System.out.println("EdgeDriverPath--" + edgeDriverPath);


// Create FirefoxOptions object and set the desired capability
FirefoxOptions firefoxOptions = new FirefoxOptions();
String fireFoxDriverPath = SeleniumManager.getInstance().getDriverPath(firefoxOptions);
System.out.println("fireFoxDriverPath--" + fireFoxDriverPath);
// These codes are optional


// Only this code is needed to setup driver , above codes are just to get driver paths.
ChromeOpt.addArguments("--start-maximized");
driver = new ChromeDriver(ChromeOpt);
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
}

--

--

No responses yet