Page 1 of 1

XPath, differentiating between two similar links

Posted: Wed Apr 01, 2015 2:17 pm
by Fergal
Hi,

[Ranorex 5.2.2 on Windows 7]

I have an XPath which ends with the following:
a[@innertext='Delete']
It works perfectly to find a link on a web page, with the anchor text "Delete".

When thereis more than one link, with the same "Delete" anchor text, I want the XPath to identify the first one on the web page. How can I do that?

Thanks!

Re: XPath, differentiating between two similar links

Posted: Wed Apr 01, 2015 3:29 pm
by krstcs
First, without seeing a snapshot of your application and the structure of your repository above this element it would be hard to know what you are working with. Please post those or send them to [email protected].

Second, Ranorex always finds the first match for a given RanoreXPath, so as long as you always want the first link, you should be able to leave it the way it is. You could also add '[1]' to the end of your current path.

Code: Select all

a[@innertext='Delete'][1]
But, again, that depends on how you have structured the repository and how the AUT is structured.

Re: XPath, differentiating between two similar links

Posted: Thu Apr 02, 2015 8:50 am
by Fergal
Thanks very much krstcs.
...as long as you always want the first link, you should be able to leave it the way it is...
My issue with that is that when the XPath identifies two elements for the same XPath, within say a click action, it doesn't know which one to click, so it doesn't click on either of them.
You could also add '[1]' to the end of your current path
That seems to be exactly what I'm looking for and I will try that next time I encounter the issue.

Thanks again!

Re: XPath, differentiating between two similar links

Posted: Thu Apr 02, 2015 9:04 am
by CookieMonster
Hi Fergal,

Please ask your web developer to add an unique id to the a tag, so you are language independent and you don't have to use indexes and makes the XPath robust.

But may you can use the href property to differentiate the a tags!?!?


Regards
Dan