Home > Mobile >  How can I find out the XPath if getting the 3 same Weblocators
How can I find out the XPath if getting the 3 same Weblocators

Time:05-27

WebElements in HTML:

<a href="javascript:procWirelineSubscribe()" >Order</a>
<a href="javascript:procWirelineSubscribe()" >Order</a>
<a href="javascript:procWirelineSubscribe()" >Order</a>

Xpath I'm using:

//*[contains(@href,'javascript:procWirelineSubscribe()')]

However, it will always result up in ending 3 weblocators and because of this my script getting failed with

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element:

Can someone help here me please?

CodePudding user response:

'NoSuchElementException: no such element: Unable to locate element:' means the element is not found. If it would result in 3 weblocators, it would click the first element it could find.

It may be because of parsing errors. Try using only a part of the href like this:

//*[contains(@href,'procWirelineSubscribe')]

CodePudding user response:

To reduce your three matches to one, try adding a [1] to the end of your expression. This error may occur because the result is a list instead of an item.

//*[contains(@href,'javascript:procWirelineSubscribe()')][1]

Then only one of the three (seemingly identical) elements will be selected.

  • Related