'how to resolve this problem cannot convert from ChromeDriver to WebDriver

public static void main(String[] args) {

    String browserName = "chrome";

    WebDriver driver = null;

    if (browserName.equalsIgnoreCase("chrome")) {

        driver = new ChromeDriver();

    } else if (browserName.equalsIgnoreCase("edgebrowser")) {

        driver = new EdgeDriver();

i write exactly but still am getting mismatch error



Solution 1:[1]

  1. rename your class
  2. add import org.openqa.selenium.WebDriver
  3. add property webdriver.chrome.driver

Code:

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class Gayatri {

    public static String chromedriverPath = System.getProperty("user.dir") + "\\resources\\chromedriver.exe";   

    
    public static void main(String[] args) {
        String browserName = "chrome";

        WebDriver driver = null;

        if (browserName.equalsIgnoreCase("chrome")) {

            System.setProperty("webdriver.chrome.driver", chromedriverPath);
            driver = new ChromeDriver();

        } else if (browserName.equalsIgnoreCase("edgebrowser")) {

            driver = new EdgeDriver();

        }
        
        driver.get("https://www.stackoverflow.com");
        System.out.print(driver.getTitle());
        driver.quit();
        
    }

}

Output:

Starting ChromeDriver 100.0.4896.60 (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896@{#875}) on port 19334
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Kv? 02, 2022 8:15:46 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Stack Overflow - Where Developers Learn, Share, & Build Careers

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pburgr