How to verify text in a hyperlink?


#1

Hey
I am trying to verify text in a hyperlink has anyone tried this?


#2

you can use getAttribute


#3

Sure. WebUI.getText() is your friend here.

What did you try? What happened?


#4

I tried the gettext and it work however is it verify the text on the whole page or the results


#5

this is the error im getting

groovy.lang.MissingPropertyException: No such property: attribute for class: Script1570204081222


#6

WebUI.getText targets the element (and/or subelements) of the element you specify. In the example you gave, it should return the text contained in the link ( element).


#7


#8

What is attribute? (From that minuscule example, all I can say is it sounds like a misnomer).

Also, verifyMatch is not getText.

I think you need to state clearly what you want to achieve and what you have tried.


#9

Hey Russ
Are you talking about this?

result = WebUI.getText(findTestObject('link_Register'))

#10

Loosely speaking, yes. You asked about hyperlinks - HTML <a> elements. So if link-Register is a Test Object representing an <a> element, you can use getText just like in your example and result should contain all innerText from the link.


#11

Russ
This is what Im trying to verify
the word ipad


#12
result = WebUI.getText(findTestObject('link_Register'))
if(result.contains("IPAD")) {
  println("Cool. Everything in the world is fantastic!")
} else {
  println("Help! It's broken!!!")
}

#13

This not working

result = WebUI.getText(findTestObject(‘link_Register’))
if(result.contains(result)(“IPAD”)) {
println(“Cool. Everything in the world is fantastic!”)
} else {
println(“Help! It’s broken!!!”)
}

in fact doesnt println either


#14

That code will work IF you have Test Objects defined as you specified.

You should be sharing everything. We’re working almost blind here.


#15

ok i know

this helpful?


#16

I just noticed you changed the code I gave you. It’s broken.


#17

the contains when i paste it gets crossed out


#18

ignore it.


#19

this is the error log whe I ignore the contain strike out

Test Cases/Spending Search/Keyword Search FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to get text of object

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.execute(GetTextKeyword.groovy:67)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:888)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$5.call(Unknown Source)

at Keyword Search.run(Keyword Search:45)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1570478092295.run(TempTestCase1570478092295.groovy:23)

Caused by: java.lang.IllegalArgumentException: Object is null

at com.kms.katalon.core.helper.KeywordHelper.checkTestObjectParameter(KeywordHelper.java:33)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.doCall(GetTextKeyword.groovy:76)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.call(GetTextKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

… 16 more


#20

Which tells me (and you) link_Register is null. That is, it does not refer to any web element. Check your Test Object definition.