RE: Getting NullPointerException error using WebDriverWait wait = new WebDriverWait(driver, 20);

I am new to WebDriver. I am trying to write a reusable method to enter text on a page which has multiple text fields. HTML looks like this <input name=”username”>, <input name=”password”>.

Below is the method I wrote to reuse
public class EnterTextMethod {

public static WebDriver driver;
public EnterTextMethod enterText(String inputField, String text) {
String inputLocator = “input[name='” + inputField + “‘]”; ( I am doing this to reuse this method. Does  WebDriver allow this?)
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(inputLocator))).sendKeys(text);
return this;
}

@Test –  Below is my test where  I am trying to enter text

login.enterText(“username”, “amazon”);
login.enterText(“password”, “Prime25”);

When I run my test method, I keep getting NullPointerException error at <WebDriverWait wait = new WebDriverWait(driver, 20);>so I might be doing something wrong here. I can’t seem to figure out what is the root cause.

Has anyone run into this issue ? I am not sure what I am doing wrong here. Stuck here from couple of days..

Thanks

Add Comment
5 Answers

public EnterTextMethod enterText(String inputField, String text)
what for you need to return EnterTextMethod object?

I think problem in this method

Reviewer Answered on July 21, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.