0

I am using Page Object Model (POM)for automating an application

I have identified elements using @FindBy annotation which has List of elements. Now, I want to iterate through all the elements. How can I do that.

DanielBarbarian
  • 5,093
  • 12
  • 35
  • 44
RamaKrishna
  • 101
  • 2
  • 15
  • Use a for loop or while loop to iterate... for(WebElement elem : listElements) {} – Grasshopper Sep 15 '16 at 07:38
  • Thanks Grasshoper, Here, I want to loop along with passing a variable to xpath for each iteration. I want to know how to pass the variable into xpath – RamaKrishna Sep 15 '16 at 08:22
  • You should add some code,makes things clear. You can pass any variable to xpath expression by simple string concatenation. – Grasshopper Sep 15 '16 at 09:04
  • `@FindBy(xpath=".//*[@class='TN GLujEb']//*/a[i]")` `public List ind_leftpane;` //here 'i' in xpath is the parameter i want to pass to the xpath in runtime – RamaKrishna Sep 15 '16 at 09:08

1 Answers1

0

Create a string array with the list of xpaths. Loop through the array and pass the xpath at (i) into the Find by variable.

Moser
  • 287
  • 2
  • 12
  • Thanks for answering @Moser! Sorry to say this that i did not get what you are trying to say. Can you please ellaborate with an example here Thanks again!! – RamaKrishna Sep 19 '16 at 06:46