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

In Selenium RC,  it worked fine. So, I thought of using it in WebDriver as well.  Maybe Selenium WebDriver doesn’t allow, not sure.

Train Answered on July 21, 2015.
Add Comment

Your Answer

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