Using WebDriverWait wait getting a NullPointerException

595 views
Skip to first unread message

SeleniumMember

unread,
Jul 16, 2015, 5:17:35 PM7/16/15
to seleniu...@googlegroups.com
I am getting NullPointerException error while using the WebDriverWait. I don't know what I am doing wrong here. I am able to launch the Firefox browser. Can anyone tell me what am I missing or setting it incorrect here ?

Method
public LoginLogoutMethod login(String username, String password) {
        String userLocator = "input[name='username']";
        String passLocator = "input[name='password']";
        String submit = "input[type='submit']";
        WebDriverWait wait = new WebDriverWait(driver, 20);
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(userLocator))).sendKeys(username);
        }
        catch(Exception e) {
            System.out.println("Username textbox not found");
        }
        try {
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(passLocator))).sendKeys(password);
        }
        catch(Exception e) {
            System.out.println("Password textbox not found");
        }
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(submit))).clear();
        return this;
    }

Test - Extends LoginLogoutMethod
    @Test
    public void testLogin() {
        LoginLogoutMethod login = new LoginLogoutMethod ();
        login.login("admin", "admin");
    }

Jim Evans

unread,
Jul 16, 2015, 5:21:31 PM7/16/15
to seleniu...@googlegroups.com
You've only provided the method body here, but I strongly suspect that your 'driver' variable is what's null. That would be the first thing I would check.

SeleniumMember

unread,
Jul 16, 2015, 11:13:39 PM7/16/15
to seleniu...@googlegroups.com
Oops, I forgot to add rest of the code. I did the following. And now, its typing in the username and password.

From - WebDriver driver = new FirefoxDriver(); 
Changed to - driver = new FirefoxDriver(); 

Thanks again. 
Reply all
Reply to author
Forward
0 new messages