3

Here is my code:

package seleniumTutorials;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class BasicsSelenium {

public static void main(String[] args) {
    boolean status;
    status=true;
    boolean newstatus = false;

    System.out.println("My Old status was "+status);
    System.out.println("My new status was "+newstatus);
    System.setProperty("webdriver.chrome.driver", "F:\\Samraj\\MavenAutomation\\Jar Files\\Selenium Java\\chromedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--start-maximized");
    WebDriver driver = new ChromeDriver(chromeOptions);
    driver.get("dev.findmyfare.io");
    System.out.println(driver.getTitle());
 }
 }

Below is the error message which am getting after declaring webdriver concept:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
WebDriver cannot be resolved to a type   ChromeDriver cannot be resolved to a type
    at seleniumTutorials.BasicsSelenium.main(BasicsSelenium.java:13)

Note: I can able to execute simple java program.

Screenshot of my Eclipse

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Samraj
  • 137
  • 2
  • 4
  • 12
  • You seem to be missing some jars for the Selenium project. Have you added Selenium in the build path and added the jars? – demouser123 May 01 '18 at 05:46
  • Also `driver.get("dev.findmyfare.io")` will throw an error. Please use `http` or `https` before the url – demouser123 May 01 '18 at 05:47
  • I had added Junit jar which was missing and still am facing the same issue. I had changed the directing url as well to https://dev.findmyfare.io. – Samraj May 01 '18 at 07:04
  • I had this problem with Eclipse but with NetBeans I didn't have any problems I think this can help you https://stackoverflow.com/questions/59361521/opening-chrome-in-selenium-issue/59361910#59361910 – Wassim Al Ahmad Dec 29 '19 at 17:43

5 Answers5

0

There is no issue with your code. I created a simple Selenium project and added this code and I was able to run this code without any problem.

Please see that in your External Jars you need to have the following jar files

  • client-combined-3.11.0.jar
  • client-combined-3.11.0-sources.jar
  • byte-buddy-1.7.9.jar
  • commons-codec-1.10.jar
  • commons-exec-1.3.jar
  • commons-logging-1.2.jar
  • gson-2.8.2.jar
  • guava-23.6-jre.jar
  • httpclient-4.5.3.jar
  • httpcore-4.4.6.jar
  • okio-1.13.0.jar
  • okhttp-3.9.1.jar

Edit 1 : Also remove ChromeDriver from the Referenced Libraries.

demouser123
  • 4,108
  • 9
  • 50
  • 82
0

This error message...

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

...implies that WebDriver and ChromeDriver wasn't resolved at compiletime.

As per the snapshot you have shared your main issue is the presence of multiple similar binaries within your project space as follows :

  • You have included selenium-server-standalone-3.11.0 as a dependency.
  • Additionally you have included the Java Client JARs from selenium-java-3.11.0 as a dependency.

As a result it is pretty much possible that you have resolved the WebDriver and ChromeDriver from one JAR resource (i.e. either selenium-server-standalone-3.11.0 or selenium-java-3.11.0 JARs) but compiletime the Classes are trying to get resolved from the other JAR. Hence you see java.lang.Error: Unresolved compilation problems

Solution

  • Either keep only selenium-server-standalone-3.11.0 JAR as an external JAR.
  • Or keep only selenium-java-3.11.0 JARs as an external JARs.
  • Remove all the other Selenium Java Client JARs.
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • Take a System Reboot.
  • Execute your @Test.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

I had the same error while working with IntelliJ IDEA, and the solution was to update my Gradle file "build.gradle" to include

dependencies {
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'}

test {
useJUnitPlatform()}
ahmedibrahim085
  • 365
  • 5
  • 11
0

in eclipse, while adding the jar files , we have two options first one is modulePath and second one is classPath, so you need to add all the required jar files in classPath not in ModulePath it works for me

0

In older Eclips we didn't had option to add jars under class path or Module path.

Now we have an options, so if you add all valid jars in module path and still if you are getting error then it is because of adding jars in Module path.

Remove the jars and add under Classpath

Attached screenshot for reference

Screenshot to fix ChromeDriver cannot be resolved to a type erro