java - Webelement defined by @FindBy annotation returns null pointer -
for reason, when call method spage.editexbutton(int id), error saying webelement first null. why null? have defined using @findby annotation. have explicitly define element using findelement(by.id("xxx")) in order able click on it. why unable call using @findby notation?
public class spage extends gpage<spage> { public spage() { super(); } public spage(string pagetype) { super(pagetype); } @findby(id = "xxx") webelement first; public webelement ebutton(int id) { first.click(); string tmp = id + "-edit"; webelement edit = getdriver().findelement(by.id(tmp)); return edit; } public epage cedit(int id) { ebutton(id).click(); return new epage(getbasepagetype()).openpage(epage.class); } }
i calling method this:
static epage epage; static spage spage; @test public void edit_exception() { epage = spage.cedit(idbefore); }
you need call (preferably in constructors):
pagefactory.initelements(getdriver(), this);
more information: https://code.google.com/p/selenium/wiki/pagefactory
Comments
Post a Comment