How to Verify Element Attribute Value

Hi All,

I am looking for the option where I can Verify Element Attribute Value using Boolean. For example title=“Hazard” or href=“www.test.com” I just want to verify if there is any attribute value present and using Boolean. How can I do that? I am using manual mode. Thank you so much!

1 Like

Not sure what you mean by Bool? as in you want the title or url to be true?

maybe you’re looking for something like this? to verify the title matches?

WebUI.openBrowser('https://google.com')

title = WebUI.getWindowTitle()
println title

assert title == "Google"

keyword version:

You can use WebUI.getUrl the same way

1 Like

You have to use one of the attributes of your element. Your can’t just go willy nilly. Done right, the Verify Element Attribute Value returns a boolean if the specific text of the attribute is correct/exists or not.
As an example, in the first one below I am wanting to confirm the <value> attribute and in the second I want to confirm the <title> attribute:

WebUI.verifyElementAttributeValue(findTestObject('myPage/input_DateSDMAcctReceived'),  "value", "${gScreenFormattedDate}", 10)


WebUI.verifyElementAttributeValue(findTestObject('myPage/textarea_SDMAcctReviewDetails'), "title", "Choose the appropriate value based on information received", 10)


I am stuck here for attributevalue because this value will change and cannot be empty so I need true or false to validate it. Thanks

Leave it blank if the app will allow it. You can “fill” the contents of the parameter at run time.

If you notice my “attributeValue” in my first statement above, I use a variable to validate the contents of the attribute. In my case, this is the current date, but you can use a variable to hold your contents. I don’t know how or where you are going to GET the value:

myTitle = "..."
WebUI.verifyElementAttributeValue(findTestObject('...'),  "title", myTitle, 10)

So you’re just trying to see if there’s a window title in the page as a bool? What grylion said should work…
or maybe the below code is what you looking for… I don’t have a website where I can have the Window title as blank and test it.
Do you think this will work @grylion54

WebUI.openBrowser('https://google.com')
boolean title = WebUI.getWindowTitle()

correct. I want to verify this title to make sure it is never empty.

How about like the below?

myTitle = WebUI.getAttribute(findTestObject('...'), "title")
WebUI.verifyNotMatch(myTitle, "", false)

I tried both false and true both passes my test not sure why

So that Title is a button attribute…not even a window title. It’s not even the button text. But this code should work… if the “title” is null/false, the test will fail.

import com.kms.katalon.core.util.KeywordUtil

WebUI.openBrowser('your website')

boolean myTitle = WebUI.getAttribute(findTestObject('your testObj'), 'title')

if (myTitle != true ) {
    KeywordUtil.markFailed()
}

Personally, you should NOT use true for your “isRegex” unless you want to make a wild card similar comparison instead of a standard comparison. Since you do not have any wild cards in your text, it can only lead to some problems latter, especially if you are unfamiliar with Regular Expression components, like “$” or “]”

Since the return value of the attribute is not a boolean but a String, instead, maybe:

if (myTitle == "") {
    KeywordUtil.markFailed()
}

and don’t forget:
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil

since it’s wrapped with a boolean, it should return true if there’s a value there… false if there isn’t. if you console log (or print) myTitle, it should return true/false depending on if there’s a value set on title attr. (not the actual string)
I mean it’s a weird test req, but this is what the OP wants to do.

I am validating the value not the attribute. I may not an expert in Katalon. Thanks

@smistry don’t give up. try the codeblock I posted.

the way to test it is to hack the HTML in dev console… and remove the string/value inside the title attr and run the test from that specific test step in the same browser instance without refreshing the page (if you want to verify if the code works or not)

Just for your info: the attribute we are looking at is the <title>, so getAttribute gets the “value”/“information”/“String” that is within the associated <title> attribute, which in your image above is “Sign in to online account”, so:

myTitle = WebUI.getAttribute(findTestObject('...'), "title")
println myTitle

will output, Sign in to online account

@ashraf.madina takes the fact there is content within the variable and does a cast to a boolean which may be true; and I just do a comparison to the String variable being empty. Either / or.