XPath Wildcard syntax help


#1

Hi all:
I need a little assistance with a wildcard issue in an xpath. I want to insert a wildcard into the xpath so if part of the tag changes, the beginning of the text in the tag will still be found. For example, here is the text of the xpath in question:
/html//div[@id=‘rightColumn’]/div[@class=‘row’]/div//h5[.=‘Project Summary: Titan Rev1’]

I want to be able to still find the element in an assert if the text after the “:” changes. So something like ‘Project Summary:*’

Please let me know if this is possible. Thanks!


#2

Hello @micheleaz

Yes, this is indeed possible, and can use wildcards with XPath selectors using one of the available XPath functions:

contains()                [contains(@tag,”something”)]
starts-with()             [starts-with(@tag,”something”)]
ends-with()               [ends-with(@tag,”something”)]

In your case particularly, you can modify your selector like this

/html//div[@id=‘rightColumn’]/div[@class=‘row’]/div//h5[contains(text(),”project:”)]
Here you are basically searching for a h5 element that contains the provided text.

Best way to do this is to test your selector in the Ranorex Selocity playground first, to make sure it works, like in the example below the link containing the “Home” text


Afterwards, just send the selector to Ranorex Webtestit and you are all set :slight_smile:

And if you are curious about more XPath wildcards and functions, take a look at this post.