XPath - Contains()

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
rba
Posts: 1
Joined: Wed Apr 24, 2019 3:44 pm

XPath - Contains()

Post by rba » Wed Apr 24, 2019 3:47 pm

Hello,

I have this kind of XPath that I would like to convert into Ranorex:

Code: Select all

//div[@data-internalname='0_cell' and contains(.//span,'Logistics')]
It seems that Ranonrex does not support the contains() function. Is there a way to select a div that contains a span having some text in a "ranorex way"?

Thanks and best regards,

Raphaël

qwertzu
Posts: 232
Joined: Wed Jan 25, 2017 11:08 am

Re: XPath - Contains()

Post by qwertzu » Thu Apr 25, 2019 2:06 pm

Hi Raphael,

So, if I understand you correctly, you're trying to find a RanoreXPath to a specific span tag below a div tag?
What path does Ranorex Spy give you when tracking the element?
Please post a Ranorex Snapshot of this element so the community can help you.

regards, qwertzu

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

Re: XPath - Contains()

Post by odklizec » Tue Apr 30, 2019 12:40 pm

Hi,

I think you are looking for xpath relationship operators. If the span tag is located under div tag you want to localize, you can use something like this:
//span[@innertext='Logistics']/ancestor::div[@data-internalname='0_cell']
But as mentioned by qwertzu, it would be much easier to provide sensible answer with available Ranorex snapshot ;) For more RanoreXPath tips and tricks, follow this blog post:
https://www.ranorex.com/blog/ranorexpat ... nd-tricks/
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

Jewell26
Posts: 1
Joined: Fri May 03, 2019 6:47 am

Re: XPath - Contains()

Post by Jewell26 » Tue May 14, 2019 6:08 am

1 Overview. The contains() function tests whether a string attribute contains a specific string (case-insensitive) as a sub-string.
2 Example. This query returns all the customers from which the name contains the string an : //Sales.Customer[contains(Name, 'an')] Java. Copy.
Last edited by Jewell26 on Wed May 15, 2019 12:47 pm, edited 1 time in total.

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

Re: XPath - Contains()

Post by odklizec » Wed May 15, 2019 7:53 am

Jewell26 wrote:
Tue May 14, 2019 6:08 am
2 Example. This query returns all the customers from which the name contains the string an : //Sales.Customer[contains(Name, 'an')] Java. Copy.
As mentioned, 'Contains' is currently not supported by Ranorex xpaths. However, the same could be achieved by regex, which is supported by Ranorex. The xpath in Ranorex could look like this:

Code: Select all

//elementtofind[@name~'an']
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