Monday, 9 September 2013

Why is a null pointer being returned instead of the info captured from driver.findElement(By.name())

Why is a null pointer being returned instead of the info captured from
driver.findElement(By.name())

Im trying to place constructors in a main class by themselves to be able
to be reused in several tests. However when I try running my cases java is
returning a null pointer exception. Below is my code for both classes. I
am very new to java and could use a suggestion as to what Im doing wrong.
Please excuse my lack of terminology in advance.
java.lang.NullPointerException
public class Constants {
static WebDriver driver = null;
public static WebElement checkout(){
WebElement checkout = driver.findElement(By.name("Checkout"));
return checkout;
}
}
public class Test{
private WebDriver driver;
@Test
public void test1() {
driver.get(baseUrl);
Constants.checkout().click();
}
}

No comments:

Post a Comment