0
votes

I am getting this error while running program

Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from FirefoxDriver to WebDriver

at selenium.FirstSelenium.main(FirstSelenium.java:11)

1.I have extracted all selenium jar files (using version -3.141.59)

2.I have downloaded geckodriver and given path is correct(geckodriver-v0.24.0-win64) 3.Also Imported import org.openqa.selenium.WebDriver; and import org.openqa.selenium.firefox.FirefoxDriver;

still getting the error.

import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver;

public class FirstSelenium {

public static void main(String[] args) {

    System.setProperty("webdriver.gecko.driver", "D:\\Drivers\\geckodriver.exe");
    WebDriver driver= new FirefoxDriver();
    driver.get("https://yahoo.com");

}

}

1

1 Answers

0
votes

Most probably you have a problem with your project CLASSPATH or suffering from a form of a Jar Hell

The easiest solution would be just changing this line:

WebDriver driver= new FirefoxDriver();

to this one

FirefoxDriver driver = new FirefoxDriver();

However I would recommend switching to a build/dependency management tool like Apache Maven. Even if you don't plan to use it later on you could at least use Maven to retrieve selenium-java jar along with all dependent jars.

  1. Create pom.xml file somewhere on your hard drive with the following content

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
    
        <groupId>com.example</groupId>
        <artifactId>selenium-java</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <dependencies>
            <dependency>
                <groupId>org.seleniumhq.selenium</groupId>
                <artifactId>selenium-java</artifactId>
                <version>3.141.59</version>
            </dependency>
    
        </dependencies>
    
    </project>
    
  2. Navigate to the folder where the pom.xml lives and execute the dependency:copy-dependencies command

    mvn dependency:copy-dependencies
    
  3. That's it, the correct set of .jar files will be downloaded to target/dependency folder

See Selenium Webdriver Tutorial with JAVA: How to set up a TestNG maven based project from scratch article for comprehensive instructions on how to properly set up the project allowing building and executing your test using Maven.