Prakash P
Prakash P

Reputation: 441

@Findby using xpath with index

Can I use @Findby and pass certain values as parameter?

@FindBy("//div[contains(@class,'gallery_grid_image_caption gallery_grid_image_caption_padding')]"[$INDEX])

I know I can do this while using findElement. Kindly let me know if there is a solution/work around.

What I want to do it is let's say there is a for loop and there is a list of elements in a page. Now let's say the only thing that is changing among these fields is the bit of the xpath. //div/1, //div/2 .... What I want to do is represent one element for all these elements and pass the ending values as parameter.

Upvotes: 3

Views: 21355

Answers (1)

Naman
Naman

Reputation: 32028

I believe what you are trying to do is something like this :

@FindBy(xpath = "//div[contains(@class,'gallery_grid_image_caption gallery_grid_image_caption_padding')]")
public WebElement yourElement;

SO-9028757 should provide you more context.

Upvotes: 4

Related Questions