0
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?

2
  • how you are passing driver instance? also instead of list, just try find element to see what exception it will throw Commented Oct 14, 2023 at 3:08
  • I passed driver through page factory constructor.'public BasePage(WebDriver driver) { this.driver= driver; PageFactory.initElements(this.driver, this); }' I tried with find element too and still got size as 0. Commented Oct 19, 2023 at 1:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.