In some of my tests I have to confirm that some select2 dropdowns are disabled when certain flags are set. To confirm this I found that the strategy below seemed to work:
Assert.True(element.GetAttribute("disabled").Equals("true"));
When I inspect the element I see disabled="disabled"
. My question is why does the string returned from GetAttribute = "true"
not "disabled"?
The getAttribute() method of the Element interface returns the value of a specified attribute on the element. If the given attribute does not exist, the value returned will either be null or "" (the empty string); see Non-existing attributes for details.
It returns the value of the HTML element's attribute as a string. If a value is not set for an attribute, it will return a NULL value. For attributes with Boolean values, getAttribute() will return either "True" or NULL. The attribute is passed as a parameter to the method.
isEnabled() To verify if an element is enabled or disabled on web-page. Returns "ture" if element is enabled and returns "false" if an element is disabled. Examples: Mostly used with button elements, locked/disabled text input elements.
As the name suggests, the getAttribute method gets the value of a given HTML attribute. On the other hand, getText() returns the inner text of a given element. The term “inner text” means the text located between the opening and closing tags of the element.
https://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html
Certain attributes seem to only return Boolean values, whether the actual value is "true" or "false". Disabled is one of them. Linked page lists all the attributes considered to be Boolean values, any other attribute should return the attribute's value.
Quoting the most relevant part of the linked page :
"The following are deemed to be "boolean" attributes, and will return either "true" or null: async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, spellcheck, truespeed, willvalidate ". [Selenium : WebElement.getAttribute()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With