1

Trying to find a partial attribute value. Full value is no problem.

I have h1 class="a b c" and want to find out, whether this h1 has a as a class attribute.

Trying WebUI.verifyMatch(findTestObject('mytest/mytest-h1'),'a', 'a.*', false, FailureHandling.STOP_ON_FAILURE) and fails on finding.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
Evgeniy
  • 2,337
  • 2
  • 28
  • 68

3 Answers3

2

Also answered via this Katalon Forum post (Apologies if the link is broken, in the future).

As per Mate Mrše's answer you can also try the following:

def attribute = WebUI.getAttribute(findTestObject('mytest/mytest-h1'), 'class')
boolean doesAttributeExist = attribute.contains('a')

if (!doesAttributeExist) {
    // Add some logic/interaction
}

Since you added FailureHandling.STOP_ON_FAILURE the test will fail regardless of the condition.

Should you want the test to continue rather use FailureHandling.OPTIONAL

JP Roussel
  • 155
  • 8
1

Try this:

def attribute = WebUI.getAttribute(findTestObject('mytest/mytest-h1'), 'class')
assert attribute.contains('a ')
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

Alternatively, create an object using the CSS class as the locator and verify the element exists:

assert WebUI.verifyElementClickable(findTestObject('mytest/mytest-h1-a')) == true
theHands
  • 373
  • 1
  • 3
  • 8