Page factory for dynamic locators

Guys,

I have newly implemented page factory in my project wherein I came across a situation where I need to create xpath at runtime depending upong the product id generated.
Is it possible to make FindBy annotations dynamic

For eg
@FindBy (xpath=’//a[text()=’"+PRODUCT ID HERE+"’])
Private WebElement Product;

Is it possible to achieve this.

1 Like

Why not make it a method? Something like:

public static WebElement findElementWithProductId(productId) {
   return @FindBy (xpath='//a[text()='productId'])
}
1 Like