0

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 Answer 1

0

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;
    
Sign up to request clarification or add additional context in comments.

4 Comments

As I said in question, I do not want this approach, Since I have n number of webelements in n pages, It is taking more time to write same webelement two times, one for findElement and one for findElements. Let me if there is any possibility using WebElement parameter.
@NoNoNo You don't need to write same webelement two times. That why Page Factory. You simply need a getter.
@FindBy(xpath = "xpathValue") private WebElement notificationIcon; I do not understand how we can write a getter for List<WebElement> for this?
@NoNoNo 1) You can't find all the WebElements withreturn type WebElement. 2) You will need a customized getter as the elements won't be readily available and you need a waiter.

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.