@AjayB, could you please share the solution. How creating nested helped in solving the problem.
If I am not wrong, I am experiencing the same issue. Here is what I am trying to achieve.
I have two classes ;
1. Base Class , here I have instantiated all the stuff,
example WebDriver driver = new FirefoxDriver();
Similarly I have instantiated Page Factory elements , this looks like this...
public static Define page = PageFactory.initElements(driver,Define.class);
@CacheLookup
@FindBy(id = "user_name")
public static WebElement name;
@CacheLookup
@FindBy(name = "user_email")
public static WebElement lastNameTextbox;
All this inside one class which BaseClass
2. CreateUser Class extends BaseClass
Test Method create{
name.clear(); =======>> doesn't work
name.sendKeys("xyz"); ===========> doesn't work
}
Error that I get on running CreateUser is :
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(DefaultElementLocator.java:59)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:34)
I don't understand this error. I have already initialized everything in Base Class, and used it extended in CreateUser class. So why null pointer exception.
@All, Ajay , Krishnanan, Please let me know what I am missing.