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);
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..


Add Comment
5 Answers

Thanks to all

I thought I posted my reply,  apparently  not. I am extending multiple classes, which is why the webdriver was set to null. I initialized the variable and got it is working.

Train Answered on July 30, 2015.
Add Comment

Your Answer

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