2

In Workfusion I am iterating all elements in a HTML page that are to be found by xpath:

//*[starts-with(@id,"FormView1_hidRevElement")][${i}]

When ${i} = 1 I get what is expected but not when ${i} > 1.

In the HTML page I have elements like:

id="FormView1_hidRevElement12636"

id="FormView1_hidRevElement12637"

id="FormView1_hidRevElement12642"

etc,

Error thrown: ...

  Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[starts-with(@id,"FormView1_hidRevElement")][2]

...

What is wrong?

Community
  • 1
  • 1
Feliks
  • 33
  • 7

1 Answers1

6

The XPath which you have created is wrong because

//*[starts-with(@id,"FormView1_hidRevElement")]

will return the matching count as 3 for the below id's

id="FormView1_hidRevElement12636"

id="FormView1_hidRevElement12637"

id="FormView1_hidRevElement12642"

And the each id match equals to 1 then obviously >1 condition will throw an error because it doesn't exist.

Try this XPath:

(//*[starts-with(@id,"FormView1_hidRevElement")])[${i}]

Community
  • 1
  • 1
Ali
  • 1,689
  • 1
  • 5
  • 12
  • @Feliks click that check mark near the answer to further appreciate Ali's help ;) (https://stackoverflow.com/help/someone-answers) – Andrey Jan 22 '19 at 22:45