XPath query

Ask general questions here.
manustar47
Posts: 14
Joined: Mon Jul 27, 2015 2:17 pm

XPath query

Post by manustar47 » Sun Aug 23, 2015 6:52 pm

Hi, could somebody tell me the difference between xpaths /form/*/button[1] and /form/?/button[1]. am bit confused.

Thanks & Regards,
Manu

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: XPath query

Post by odklizec » Mon Aug 24, 2015 7:59 am

Hi,

* character in the xpath means any adapter, ? character means optional adapter.

In other words, this path:

Code: Select all

/form/*/button[1]
will find button[1] no matter if the adapter behind the "form" is container, form, div, list, or anything else. So the element could be found on path like any of these...

Code: Select all

/form/container/button[1] 
/form/form/button[1] 
/form/table/button[1] 

Path like this:

Code: Select all

/form/?/button[1]
means that the button[1] will search for button[1] right after form and/or any immediate adapter behind the form. So the button could be found on path like this...

Code: Select all

/form/button[1] 
or this:

Code: Select all

/form/container/button[1]
or both!

You can find some examples with explanation here:
http://www.ranorex.com/support/user-gui ... xpath.html

BTW, you should use the 'optional' character with caution, because it could increase the search time and make your tests noticeable slower! Plus, if the GUI you are testing is "messy" and contains multiple elements with non-unique name, it can find multiple elements, which could ruin your test ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: XPath query

Post by krstcs » Mon Aug 24, 2015 1:52 pm

Note: Ranorex ALWAYS returns the FIRST ELEMENT it finds that MATCHES THE RXPATH. This can be a nice shortcut, or a bad thing, depending on what you need. As Pavel indicated, it is almost always better to have a more specific RXPath than a more generic one, both for speed and for getting the exact match.
Shortcuts usually aren't...

manustar47
Posts: 14
Joined: Mon Jul 27, 2015 2:17 pm

Re: XPath query

Post by manustar47 » Tue Aug 25, 2015 1:55 pm

Thank you guys :)