Feliks
Feliks

Reputation: 33

Cannot get Web Element by xpath collection (Workfusion)

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?

Upvotes: 2

Views: 437

Answers (1)

Ali
Ali

Reputation: 1689

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}]

Upvotes: 6

Related Questions