Active Hack
Active Hack

Reputation: 11

WebDriver cannot be resolved to a type for Selenium 3.5.3

I am using a Linux Ubuntu studio 16.10 I have a selenium webdriver 3.5.3 I have an eclipse jee-oxygen Eclipse Java EE IDE for Web Developers.

Version: Oxygen Release (4.7.0)
Build id: 20170620-1800

I have Java 1.8 I have GeckoDriver 0.16

Firefox 54.0

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
    public class XYZ {  


            {  

                System.setProperty("webdriver.firefox.bin","/usr/bin/firefox"); 
                System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
                WebDriver driver = new WebDriver();

                DesiredCapabilities dc = DesiredCapabilities.firefox();

I am getting the following errors in the Problems tab:

    Description Resource    Path    Location    Type
DesiredCapabilities cannot be resolved  XYZ.java    /AXYZ/src   line 23 Java Problem
DesiredCapabilities cannot be resolved to a type    XYZ.java    /AXYZ/src   line 23 Java Problem
The import org.openqa.selenium.firefox cannot be resolved   XYZ.java    /AXYZ/src   line 2  Java Problem
The import org.openqa.selenium.remote cannot be resolved    XYZ.java    /AXYZ/src   line 3  Java Problem
The import org.openqa.selenium.WebDriver cannot be resolved XYZ.java    /AXYZ/src   line 1  Java Problem
WebDriver cannot be resolved to a type  XYZ.java    /AXYZ/src   line 21 Java Problem
WebDriver cannot be resolved to a type  XYZ.java    /AXYZ/src   line 21 Java Problem

How do I fix all this?

Upvotes: 0

Views: 8684

Answers (6)

programmer dreamer
programmer dreamer

Reputation: 173

Maybe you added the JAR files at wrong path like me. I'm using the latest Eclipse IDE on Ubuntu 16.04.

When I right-click my Project > Build Path > Configure Build Path, the "Add External JARS" button is disabled. I need to either click "Modulepath" or "Classpath" first before I can click the button. At first I added those JAR files under "Modulepath" and the error occured. Problem solved by moving those files under "Classpath".

You can refer the screenshot below:

enter image description here

Upvotes: 0

John Mburu
John Mburu

Reputation: 11

Am using Eclipse here 1. Download testng jar file

http://www.java2s.com/Code/Jar/t/Downloadtestng685jar.htm

  1. Copy the file to your workspace [project folder] - I have a JarFiles folder in my project

  2. Right-click your Project > Build Path > Configure Build Path

  3. Click on Add External JARS

  4. Select the testng jar file you copied
  5. click on Apply and Close

I hope this Helps :)

Upvotes: 0

Manoj Lonar
Manoj Lonar

Reputation: 11

Even if you are using Maven, you still need to add Selenium Standalone server .jar file to your project folder. It worked for me. Hopefully it will work for you too.

Steps: 1. Download Selenium Standalone Server jar file to your local folder 2. Launch Eclipse 3. Right click on your Maven project > Properties > Java Buildpath > Libraries tab 4. Click on Add External jar button 5. Browse to the folder where the jar is saved > upload 6. Apply and close 7. Refresh or Restart you eclipse.

Hope this should work

Upvotes: 1

Kushal Bhalaik
Kushal Bhalaik

Reputation: 3384

I think what you are trying to do is following:

DesiredCapabilities dc = DesiredCapabilities.firefox();
WebDriver driver = new FirefoxDriver(dc);

Upvotes: 0

iamsankalp89
iamsankalp89

Reputation: 4739

Add the jars

Right click on project-->Build path->Add external Archives-->add jars here

Upvotes: 0

You need to add the jar file containing the selenium classes to your build path.

If you don't use Maven, copy the jar to your project, right click it and choose "Add to build path" (precise wording and location depends on Eclipse version). This should make the situation better.

Upvotes: 0

Related Questions