aasifghanchi
aasifghanchi

Reputation: 112

WebDriver cannot be resolved to a type error using Selenium ChromeDriver and Chrome through Java

I have issue in my selenium script might be issue in Eclipse i tryed all possible aspect with adding all JAR library with different version but i faild to run script expert please look where i stuck

package Test;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;


public class Test {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver","C:\\Chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        String baseUrl = "https://www.facebook.com/";
        driver.get(baseUrl);
        WebElement email = driver.findElement(By.id("email"));
        WebElement password = driver.findElement(By.id("pass"));
        WebElement login = driver.findElement(By.xpath("//*[@id='loginbutton']")); 
        email.sendKeys("[email protected]");
        password.sendKeys("abcd123");
        login.click();
        System.out.println("Login Done with Click");    
    }
}

Error :

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
WebDriver cannot be resolved to a type

at Test.Test.main(Test.java:15)

This is my JAR library structure:

This is my JAR library

Upvotes: 0

Views: 3012

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193108

This error message...

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
WebDriver cannot be resolved to a type

...implies that there were compilation issues in your program.

It is pretty evident from the snapshot you are using Selenium v3.6.0 but I don't see any error as such in your code block. However you can follow the below mentioned steps to solve the issue:

  • The Package name i.e. Test and the Class name i.e. Test needs to be different. You can't use the same name for the package and the class.
  • Upgrade JDK to recent levels JDK 8u202.
  • Upgrade Selenium to current levels Version 3.141.59.
  • Upgrade ChromeDriver to current ChromeDriver v2.46 level.
  • Keep Chrome version between Chrome v71-73 levels. (as per ChromeDriver v2.46 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.

You can find a couple of relevant discussions in:

Upvotes: 1

Brian
Brian

Reputation: 3131

You need selenium-java on your classpath. The latest version at time of writing is 3.141.59.

selenium-java 3.141.59 (direct download)

All versions

Upvotes: 0

Related Questions