Unable to Verify if Text is present

Hi,
I’m currently working on a script where I need to verify if the text exists but somehow I couldn’t figure out what needs to be added or edited.

Scenario:

  1. Check if “No data available in table” text is present if yes Close Browser
  2. If statement number 1 is not present, Check if “Ref” text is present if yes Close Browser

Here is my script:

WebUI.click(findTestObject(‘Object Repository/7. Transactions/td_No data available in table’))
if (WebUI.verifyTextPresent(findTestObject(‘No data available in table’,true), 1, >FailureHandling.OPTIONAL)){
WebUI.closeBrowser() {
}}
else (WebUI.verifyTextPresent(findTestObject(‘Ref’,true), 1, FailureHandling.OPTIONAL)){
WebUI.closeBrowser()
}


I got this error:
image

sorry for the trouble but I’m not really sure what to do now. It’s highly appreciated if someone can help me.
Thanks in advance!

WebUI.click(findTestObject('Object Repository/7. Transactions/td_No data available in table'))

if(WebUI.verifyTextPresent('No data available in table', false, FailureHandling.OPTIONAL)){
  WebUI.closeBrowser()
} else {
  if(WebUI.verifyTextPresent('Ref', false, FailureHandling.OPTIONAL)) {
    WebUI.closeBrowser()
  }
}

Hello Russ,

I have the same problem.
I’d like to verify if the Text “John” “Hamish” and “Tito” are present on the webpage.

It verifies that John is present but not Hamish. My script should only fail when finding “Tito” in the webpage.

I really have no idea how to fix this now. Kindly help

Thank you!

While you are waiting for Russ to respond, you could add another verify option such as trying:

WebUI.verifyMatch(WebUI.getAttribute(findTestObject(‘LName’), ‘value’), ‘Hamish’, false)

1 Like

Hello I’ll look into this. I’ll let you know how it works!

Verify Text Present expects to find the text somewhere in the page source. It will not find it if it exists only as a value in an <input> element or <select> element etc (I believe).

1 Like

Woohoo! It works!

One more question tho, how do I do it if for example Hamish is a variable and the data would come from an excel file? What should I place in “Hamish”?

What you are doing is comparing the element’s “value” attribute to a specific text. Whether the text is “Hamish” or a String variable wouldn’t matter. I do this quite regularly.

Compare the text to a String variable:
WebUI.verifyMatch(WebUI.getAttribute(findTestObject(‘LName’), ‘value’), sLastName, false)

1 Like

Okay got it! Thank you so much for your help!