Page factory model Selenium Java - WebElement List returns empty list whereas Page object returns size

57 views Asked by At
Page object model and using driver.find elements

int noOfLinks = driver.findElements(By.xpath("//p[@class='_78mc9p']")).size();
        System.out.println(noOfLinks);

Prints the size as "6" which is expected

whereas in page factory I use findby and pass the same xpath and it return size as zero.

Pagefactory and using findBy
    @FindBy(xpath = "//p[@class='_78mc9p']")
    public List<WebElement> noOfLinks;

Page factory method
 public int countLinks(){
     return noOfLinks.size();
   }

Test
        ObjName.countLinks();
        System.out.println(ObjName.countLinks());

Compared to page object model to Page factory - the same xpath isnt returning the value. Does FindBy work different?

0

There are 0 answers