How to have a reusable method that find all the webelements using WebElement type parameter in page factory model

92 Views Asked by At

I have an automation framework that is driven using page object model using page factory

@FindBy(xpath = "xpathValue")
private WebElement notificationIcon;

I want to have an reusable utility to find all the Webelements. For that I traditionally use findElements methods which takes By parameter. How can I achieve the same using page factory?

I know that I can use the below approach, but I do not want to write for all webelements like this.

@FindBy(xpath = "xpathValue")
private List<WebElement> notificationIcon;

Hence, please find me a solution for this to find all the WebElements using a WebElement type parameter?

1

There are 1 best solutions below

4
undetected Selenium On

The replacement for findElements() in Page Factory can be either of the following:

  • Using FindBy:

    @FindBy(xpath = "xpathValue") 
    private List<WebElement> notificationIcon;
    
  • Using how:

    @FindBy(how = How.XPATH, using = "xpathValue") 
    private List<WebElement> notificationIcon;