Test Object with xpath selector using matches() function never works

Updates? Do you expect matches() to work in future? Do don’t think it will happen.

1 Like

Don’t know why this bug is not fixed. But anyway, matches() seems like a very common use case.

OK, let’s wait for @Katalon team to respond to us.

1 Like

Any update on this @Katalon_team ? This is indeed a very common use case, especially when I have to test 3rd-party integrations, and have no control over the code. Regex is a needed fallback.

I think Katalon Studio would never be able to support XPath matches() function. I explained the reason above.

1 Like

You can live without the matches() function in XPath2.0. It is possible to implement “grep” with string pattern over a text content of a HTML element with XPath1.0 expression. The following comment shows how to:

1 Like

Hi @kazurayam,

I understand your point on removing options in Katalon… But I am a bit disapointed as Xpath is a powerful way to handle HTML documents and, to speed-up test creation and execution.
Hence, I would rather pledge for an update to Xpath2.0 and a little clean up of the attributes detection interface. There is really interesting functions in the v.2.0.

WebUI.verifyElementPresent(findTestObject(    'Page_Discussion 7609/td_Latin_alphabet - text matches'),
    3, FailureHandling.CONTINUE_ON_FAILURE)

where the Test Object has a XPath defined as

//td(matches(text(), 'IVAN'))

When I run the test case, Katalon Studio calls org.openqa.selenium.WebDriver.findElement(By.ByXpath). The string //td(matches(text(),'IVAN')) is transferred from Katalon Studio to browser (for example, Chrome). Chrome browser interprets the string //td(matches(text(),'IVAN')) as XPath, and evaluate it against the DOM of a Web page.

The thing is, it is browsers (Chrome, Firefox, etc) who evaluates the string //td(matches(text(),'IVAN')) as an XPath expression. Katalon Studio does not know if the string is an expression conformant to XPath1.0 or XPath2.0. All Katalon Studio does is saving the string and transferring it to browsers. It depends on Browser’s capability if it supports XPath 2.0 or not. According to https://stackoverflow.com/questions/25455351/does-chrome-use-xpath-2-0 , Chrome uses libxml which supports XPath 1.0 but not XPath 2.0.

If you want to use XPath 2.0 expression in Katalon Studio, then you need to convince the Browser vendors (Google, Mozzila, Microsoft, Apple) to hear your wishes. I believe that Katalon Team has very little they can do for changing Chrome and Firefox.

And I guess, Browser vendors will not be interested in XPath2.0 support; they are serious about CSS and JavaScrit, but not about XPath features any longer.

1 Like

In KSE 7.2.1, the “matches regex”, “not matches regex”, and “ends with” conditions provided for selecting objects by attributes do not work. If this is dependent on browser support, and none of the browsers Katalon uses support XPath 2.0, why are the options still present in Katalon?

1 Like


I would propose this to Katalon Team again.

Yes I agree that it is misleading that these do not work. Either they should be removed or fixed. I am running into this issue with mobile… with this is a selector: //*[ends-with(@resource-id, ‘child_start_button’)]
@ThanhTo @duyluong

This has to be a bug, when i select this for regex selection by resource-id for mobile android, i see the following in the logs:

e[35m[HTTP]e[39m e[90m{“using”:“-android uiautomator”,“value”:“new UiSelector().resourceId("child_start_button")”}e[39m
Katalon should be calling resourceIdMatches: UiSelector  |  Android Developers

I need this to work too, I need to match the current month / year and many other cases on a text of a testObject, and regex seems to be the closest to what I need that would not involve a lot of workarounds… Ideally I would like to match the current month or year on a text of testObject(s) but that involves coding and reorganizing a lot of repository objects and consequent adjustments. We need the simplest solution for our needs.

All I can do is to show you some workaounds.

Alternative to the XPath2.0 matches() function:

Alternative to the XPath2.0 ends-with() function:

In many cases (simple cases), the contains function of XPath 1.0 is useful, can be an alternative to matches function of XPath 2.0:

The following article describes how to live with XPath1.0, without regular expression and ends-with which were added at XPath 2.0

Just for your interest, I made a demo project where I verify if today’s date is displayed in a web page. I used XPath contains() function. I did not need matches() function at all.

I will check it out thank you !

Of course I also try

  • with ‘^’ and ‘$’
  • with ‘/’ and ‘/g’

Issue exist for mobile too :roll_eyes:

  • No parent
  • Selection method: Attributes
  • Simple regex to handle a popup in multi language:
    (Not Now|Plus tard)