Exception in thread "main" java.lang.Error: Unresolved compilation problems: WebDriver cannot be r

6,875 views
Skip to first unread message

Bj Ahn

unread,
Sep 12, 2015, 2:07:32 AM9/12/15
to Selenium Users
I am new to Selenium and was following one the on-line tutorial to run the following script from Eclipse:

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

public class Gmail_Login {
    /**
     * @param args
     */
    public static void main(String[] args) {
       
        // objects and variables instantiation
        WebDriver driver = new FirefoxDriver();
        // FirefoxDriver driver = new FirefoxDriver();
        String appUrl = "https://accounts.google.com";
       
        // launch the firefox browser and open the application url
        driver.get(appUrl);
       
        // maximize the browser window
        driver.manage().window().maximize();
       
        // declare and initialize the variable to store the expected title of the webpage.
        String expectedTitle = " Sign in - Google Accounts ";
       
        // fetch the title of the web page and save it into a string variable
        String actualTitle = driver.getTitle();
       
        // compare the expected title of the page with the actual title of the page and print the result
        if (expectedTitle.equals(actualTitle))
        {
            System.out.println("Verification Successful - The correct title is displayed on the web page.");
        }
        else
        {
            System.out.println("Verification Failed - An incorrect title is displayed on the web page.");
        }
       
        // enter a valid username in the email textbox
        WebElement username = driver.findElement(By.id("Email"));
        username.clear();
        username.sendKeys("TestSelenium");
       
        // enter a valid password in the password textbox
        WebElement password = driver.findElement(By.id("Passwd"));
        password.clear();
        password.sendKeys("password123");
       
        // click on the Sign in button
        WebElement SignInButton = driver.findElement(By.id("signIn"));
        SignInButton.click();
       
        // close the web browser
        driver.close();
        System.out.println("Test script executed successfully.");
       
        // terminate the program
        System.exit(0);
    }
}


However I am getting the following error:

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

    at Gmail_Login.main(Gmail_Login.java:13)


Can anyone help me with what I am missing here?

Thanks

Krishnan Mahadevan

unread,
Sep 12, 2015, 2:09:22 AM9/12/15
to Selenium Users
You havent told us what tutorial you were following.
But looks like you are having a problem with your CLASSPATH missing jars. So you should grab the required selenium jars and add them up to your CLASSPATH.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3e190c81-5e67-450c-a273-cf82ee646e1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

anemuday

unread,
Sep 12, 2015, 1:45:48 PM9/12/15
to Selenium Users
If you have java installed and using the latest selenium jars,

can you just try,

WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com")

and check whether google site is opening or not?

Thanks,
Uday
Free Selenium WebDriver Videos

Bj Ahn

unread,
Sep 24, 2015, 2:44:27 PM9/24/15
to Selenium Users
The tutorial page is http://www.softwaretestinghelp.com/selenium-webdriver-tutorial-10/
I am running it using eclipse..... 

Do I need to set up CLASSPATH as environment variable explicitly?

Thanks for your help.
BJ

Quang Chanh Phan

unread,
Sep 28, 2015, 11:02:04 AM9/28/15
to Selenium Users
Can you show all text console?
ChanhPQ

Vào 01:44:27 UTC+7 Thứ Sáu, ngày 25 tháng 9 năm 2015, Bj Ahn đã viết:

Bj Ahn

unread,
Sep 28, 2015, 8:19:16 PM9/28/15
to Selenium Users
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
WebDriver cannot be resolved to a type
FirefoxDriver cannot be resolved to a type
WebElement cannot be resolved to a type
By cannot be resolved
WebElement cannot be resolved to a type
By cannot be resolved
WebElement cannot be resolved to a type
By cannot be resolved

at Gmail_Login.main(Gmail_Login.java:13)


The above is the error message that I am getting.....

Any help will be greatly appreciated since I have not been able to go further.

BJ

Bj Ahn

unread,
Sep 28, 2015, 10:23:38 PM9/28/15
to Selenium Users
Fixed the issue.... apparently I need to include jar files from the main directory too along with the ones from lib sub-directory.

Quang Chanh Phan

unread,
Sep 29, 2015, 11:08:08 PM9/29/15
to Selenium Users
Exactly!

Vào 09:23:38 UTC+7 Thứ Ba, ngày 29 tháng 9 năm 2015, Bj Ahn đã viết:

Quang Chanh Phan

unread,
Sep 29, 2015, 11:08:13 PM9/29/15
to Selenium Users
I've run your code and it ran well. I've think the path of libraries is not right. For fix this issue, i think you check again the path of selenium libraries.
ChanhPQ


Reply all
Reply to author
Forward
0 new messages