3

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.

Prakash P
  • 419
  • 1
  • 8
  • 18
  • Can you tell me which language r u using???? – Om Prakash Jun 03 '16 at 10:43
  • @PrakashP : does the answer help? – Naman Jun 06 '16 at 06:02
  • @nullpointer No. My question is different. 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. – Prakash P Jun 06 '16 at 07:25
  • @PrakashP : instead could you please add this explanation to the question and update – Naman Jun 06 '16 at 07:59
  • 1
    @nullpointer I did that. As of now I have a taken a different approach using driver.findelement – Prakash P Jun 08 '16 at 05:09
  • @nullpointer Sorry for the late reply. – Prakash P Jun 08 '16 at 05:10
  • could you update an answer here – Naman Nov 26 '16 at 14:32

1 Answers1

4

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.

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353