True/False attributes always returned with value of True when using getAttributes or verifyElementAttributeValue methods

I am working on a script that checks the attributes of the element highlighted in the screenshot below. In my script, the ‘readonly’, ‘disabled’, and ‘checked’ attributes are all being returned as True in Katalon, but they are appearing as False when i inspect them from chrome. The Object i’m testing in my script uses the xpath shown in the screenshot below, and the associated attributes of the element I’m interested in are also shown.

When I run the script, Katalon is consistently returning a value of True for element attributes that appear as False in the browser. In the output below, the if statement at line 37 fails with a message that the ‘readonly’ attribute appears as True, even though in the browser it appeared as False (See screenshot above and test output below)

Based on the highlighted section of the first screenshot, i was not expecting the if statement at line 44 to even execute, as chrome is showing the ‘readonly’ attribute as False. When i print out all the attributes to the console in Katalon the ‘class’, ‘name’, and ‘tabindex’ attributes appear correctly, while the ‘disabled’, ‘readonly’, and ‘checked’ attributes are being returned as True regardless of how they appear within the browser.

The Enabled Switch object in my code uses the same xpath as in the first screenshot.

I’ve tried adding delays and toggling the switch element on and off before reading its attributes, but the discrepant behavior has remained consistent. As you can see from the code snippets above the behavior is consistent whether i use the getAttributes or the verifyElementAttributeValue methods within Katalon.

This is pretty confusing and annoying to me, as it is unclear why Katalon is consistently producing different attribute values than what is displayed in Chrome, but only for certain attributes! Any insight on what may be going on here, and how i can mitigate it to get consistent behavior between Katalon and my browser would be greatly appreciated. Thanks.

From the HTML spec:

2.5.2 Boolean attributes

A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute’s canonical name, with no leading or trailing whitespace.

The values “true” and “false” are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

IOW, setting a boolean attribute to “false” is meaningless, or, worse, confounding. You should point this out to the page developers and tell them to read the specs because they’re doing it wrong.


Ahh, gonna have to follow up with the devs on this one. Very helpful, thanks Russ.

1 Like

If this gets addressed at all by the developers, it seems like its a lower priority and it won’t be for a while. Until that happens, is there some way of disabling this boolean check so that Katalon simply returns whatever string is assigned to that attribute??

The extra intelligence around boolean variables is nice, but I feel like there has to be some workaround i can implement in Katalon which will allow me to continue testing, without having to redesign the logic of the entire AUT (which honestly, may not be a realistic option at the moment).

Is there a selenium command i could insert into my script that would be less discerning?? I feel like there has to be some way to write a command which is dumb enough to ignore the boolean nature of the attribute, and will simply return whatever string value has been assigned to it.

Yes. Try WebUI.getAttribute

Then you can build the logic you need around that.

Funny aside:

I was about to show you a little demo using the HTML of this forum page by using the “Solution” button. This JavaScript/CSS selector will return all button element that are disabled:


It returns a list with length 2. I got curious and checked out which buttons were disabled. Turns out this forum software is getting it wrong too. :upside_down_face:

But the point remains - the devs cannot rely on standard DOM queries to retrieve current statuses of elements. Both of those buttons are, as far as the dom is concerned, disabled.

Yea WebUI.getAttribute wasn’t working for me. I had that in my code snippets above, it returned true for all the boolean attributes that were assigned the false string.

Then build it using JavaScript like I did above.

String js = "return document.querySelector('#my-button').getAttribute('disabled');"
String val = WebUI.executeJavaScript(js, null)
if(val == "true") {...} else {...}