Katalon Unable to read Element Text after Span

I’ve done everything I can think off, but I have been unable to get Katalon to successfully verify text that appears after a span tag or even within a span tag for that matter. I have a couple locations in the source I can grab some text and neither one is working for me.

The 1st location that actually shows up on the page where I am trying to verify element text is after a span tag. Annotation%202019-07-23%20110720

When using Katalon’s VerifyElementText, it cannot find the TestObject based off the XPath of //*[@id=‘v-hotel’]/div[1]/div[2]/span[@class=‘b’]/following-sibling::text()[1]. When using JavaScript document.evaluate it comes back with resultType 4

The other location where I can grab this text is within a span. Annotation%202019-07-23%20111951 The XPath for that element is //span[@class=‘at-hotel-confirmation-number’]. JavaScript document.evaluate on this element also comes back as resultType 4.

I was using the following post to use the document.evaluate Execute xpath functions from Katalon Studio - #12 by karuselkina7 to get around Katalon not being able to find the text element and not making any headway.

Try this css selector in your test object:

#v-hotel div.hidden-xs > span

Now try verifyElementText on that test object.

After finally being able to test with that as what to look for for my test object, it failed. It sees “Hotel Confirmation:”, not the 1234.

Try this CSS selector:

span.at-hotel-confirmation-number

I hope that’s unique enough in the context of the page.

That is the only location with that CSS selector, I sure hope so. I will report back my success or fail.

Another failure:
Actual text ‘’ and expected text ‘1234’ of test object ‘Object Repository/BookIt Funnel_OR/Hotel Confirmation Number’ are NOT matched.

Try this. Load up the page in the browser, open the devtools console and paste this code then hit Return:

document.querySelector("span.at-hotel-confirmation-number").innerText;

If that doesn’t work, you’re not posting the correct HTML in your posts.

If it works, your test case is trying to access that element before it is built/populated.

Screenshot%20from%202019-07-24%2009-40-42

That returned a result

So the selector works. Your test is not working. Are you waiting long enough for the element to be populated?

I can increase this line

// Make sure voucher page is loaded
WebUI.waitForPageLoad(10)
def conf_no =  findTestObject('Object Repository/BookIt Funnel_OR/Hotel Confirmation Number')
WebUI.waitForElementVisible(conf_no,10)

WebUI.delay(1) // you may need to adjust this value

WebUI.verifyElementText(conf_no, '1234')

I increased the timeout on the waitForElementVisible to 40 seconds and that particular span with the CSS selector we are using is actually never visible on the page (at least in a desktop environment). At least that is what I am assuming when I see the following warning

Object 'Object Repository/BookIt Funnel_OR/Hotel Confirmation Number' is not visible after 40 second(s)

Check for presence instead of visibility:

def conf_no =  findTestObject('Object Repository/BookIt Funnel_OR/Hotel Confirmation Number')
WebUI.waitForElementPresent(conf_no,10)

WebUI.delay(1) // you may need to adjust this value

WebUI.verifyElementText(conf_no, '1234')

Still a no go… This element is really being a pain…

Increasing timeout on delay to 35 seconds and testing…

35 seconds still text mismatch…

I’m assuming, you can see the 1234 in the element if you inspect it?

Yes, I can see the 1234 in the element if I inspect it. Even after a whole minute delay, text mismatch of empty to 1234.

This is batshit crazy.

Have you considered witing your own verification step? Something like…

def conf_no =  findTestObject('Object Repository/BookIt Funnel_OR/Hotel Confirmation Number')
WebUI.waitForElementPresent(conf_no,10)

// Perhaps a short delay here

String num = WebUI.getText(conf_no)

if(conf_no != "1234") {
  KeywordUtil.markFailedAndStop("broken")
}

With you posting that, I’m first curious to see what is returned back from getText()

With a delay set before the getText() of a minute, the getText returns empty so that won’t work either.

1 Like

Earlier, I said…

Did you also try this in the console?

document.querySelector(“span.at-hotel-confirmation-number”).innerText;

If that works in the console I’m strongly suspecting your Test Object is broken some way. Go back and change it to use CSS (not Attributes) and enter this in the field:

span.at-hotel-confirmation-number

Then we could try using JS…

def conf_no =  findTestObject('Object Repository/BookIt Funnel_OR/Hotel Confirmation Number')
WebUI.waitForElementPresent(conf_no,10)

// Perhaps a short delay here

String js = 'return document.querySelector("span.at-hotel-confirmation-number").innerText;'

String num = WebUI.executeJavaScript(js, null)

if(num != "1234") {
  KeywordUtil.markFailedAndStop("broken")
}

Check for typos!

JavaScript is the answer for everything!

1 Like