OR condition in XPath

Best practices, code snippets for common functionality, examples, and guidelines.
prasoon.jmit
Posts: 18
Joined: Mon Dec 09, 2019 1:37 pm

OR condition in XPath

Post by prasoon.jmit » Thu Dec 19, 2019 12:01 pm

Hi,

Can I use OR condition in XPAth?

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

Re: OR condition in XPath

Post by odklizec » Thu Dec 19, 2019 12:14 pm

Hi,

Yes, you can use conditions in Ranorex xpaths. For example like this:

Code: Select all

element//container/button[@accessiblename='Close' or @accessiblename='' and @accessiblerole='PushButton' and @visible='true']
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

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: OR condition in XPath

Post by mrt » Fri Jan 12, 2024 1:24 pm

How is the combine logic for which condition (and, or) is evaluated first?
Usually one would control this by using brackets, but they are automatically removed from RxPath.

These are not the same:

Code: Select all

A or B and X

Code: Select all

(A or B) and X

Code: Select all

A or (B and X)
thanks!

melodican
Posts: 37
Joined: Fri Nov 04, 2016 12:50 pm

Re: OR condition in XPath

Post by melodican » Mon Jan 22, 2024 8:36 am

Interesting question! Would also like to hear an answer from Ranorex.

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: OR condition in XPath

Post by mrt » Fri Jan 26, 2024 9:30 am

Hello,
the support told me it is evaluated from left to right (so 1st attribute together with 2nd, then the result together with 3rd and so on.)

I do not know what I did wrong before,
but now I can enter round brackets in the RxPath to group and/or clauses as needed like:

Code: Select all

//tag[@id='5' or (@tagname='abc' and @label='asdf')]

Marie143
Posts: 30
Joined: Tue Jul 26, 2022 5:20 pm

Re: OR condition in XPath

Post by Marie143 » Mon Feb 12, 2024 9:26 am

odklizec wrote:
Thu Dec 19, 2019 12:14 pm
Hi,
drywall contractor services drywall services quotes
Yes, you can use conditions in Ranorex xpaths. For example like this:

Code: Select all

element//container/button[@accessiblename='Close' or @accessiblename='' and @accessiblerole='PushButton' and @visible='true']
thanks for the info,