Hi. Just wondering why does the “Get Attribute” method returns: Attribute ‘text’ of object ‘Object Repository/Page_Works Order Master File/div_janice’ is: ‘null’
02-18-2019 04:10:56 PM getAttribute(findTestObject(“Page_Works Order Master File/div_janice”), “text”)
Elapsed time: 4.055s
Attribute ‘text’ of object ‘Object Repository/Page_Works Order Master File/div_janice’ is: ‘null’
when the element itself has text as its attribute?
yes, that was what i wanted…
i think you are trying to get text in div by using getAttribute?
something like: WebUI.getAttribute(TO, 'text')
is actually looking for attribute named text and will return ‘myText’ in following case: <div text='myText'>Content Text</div>
to get ‘Content Text’ use WebUI.getText(TO)
Sorry. I am not from a too technical background. Do you mind to explain the the difference between attribute and property you and Brandon_Hein were talking about?? I thought the text retrieved in the image I attached above is one of the HTML attribute? Is it not?
I see. Thank you. I did not realize the difference between text and content text. I manage to verify it using “Verify Element Text”. I suppose this keyword is to verify the content text then. While "Verify Element Attribute Value: text: is to verify the myText in <div text= /myText' >Content Text</div>
just one remark, you dont need to check for text, since in definition of TO is text as a part of final XPATH. if you expect also other text then janice, uncheck “text equals janice” in TO definition.
This post sums up the difference between attribute and property fairly well:
The idea is that when a browser parses HTML code, it creates objects to represent each node that it finds in the HTML. These objects have a bunch of properties that define the state of the node that they represent. You can easily see this using your browser console. Here’s an example for the Google search field element:
And this list goes on for a while. These are all properties. In my solution from above, “textContent” and “innerText” are both properties in this list as well.
Now for attributes. Attributes are the key-value pairs that you see in element nodes. Here’s the element that represents the same search field as my example above:
All of the extra data you see after the “input” tag (class, name, type, etc.) are considered attributes.
When Russ says:
He’s pointing out that the WebUI.getAttribute() method is a misnomer, because it can be used to get BOTH attributes and properties. For instance, I can do something like:
WebUI.getAttribute(testObject, "class");
which gets the classattribute value, but I can also use it to get the textContentproperty value as well:
WebUI.getAttribute(testObject, "textContent");
However, the WebUI methods are actually based in part on another library called Selenium, which also does not make a distinction between getting property values and attribute values:
As to your question about “getting the text from an element”, it works a bit differently. Lets take the HTML snippet you gave above:
<div class="k-vertical-align-bottom">janice<div>
When you see text in the HTML (‘janice’ from the above code), it’s not actually a property OR an attribute of the <div> that it lives in. Text is generally handled as a separate text node in it’s own right. So when you were trying to do:
WebUI.getAttribute(findTestObject(“Page_Works Order Master File/div_janice”), “text”)
… it failed of course, because, as @Andrej_Podhajsky pointed out, this code will look for an attribute (or a property) called ‘text’, and try and get it’s value. Since the <div> does not have such an attribute, it returned null.
One difficulty this smudging of attr/prop presents is with the value attribute. Katalon will ALWAYS retrieve the property, NEVER the attribute. If you want to verify the attribute, tough, you’ll need to write your own keyword to get at it.
Why would you want to access the attribute verbatim? To test (for example) whether form.reset is functioning correctly. Katalon can only tell you the current value of the value property, not the value of the attribute as set by the original http request of the server.
Wow, that is definitely a problem… I’ve always thought that if it were going to be just one method, they should have called it getProperty() instead, because attribute key-value pairs are stored as a property anyway:
In fact, I’m pretty sure that getAttribute() operates solely against properties, and just checks the “attributes” property to find attribute values for a node. Maybe this is what you’re already doing, but I wonder if you could check the true value property:
My approach is (as you know), move on, it is what it is, call JS where I need to, yada yada…
The other thing that makes this stand out is the masking of the value attribute when it’s undefined:
<form...>
<input name="fred" type="text" and nothing else>
</form>
fred does not HAVE a value attribute. And web interface APIs have well known, published standards for how that should behave. Again, you can’t verify that OTB in KS.
You and I know, submitting that form would NOT send fred to the server. But based on results from KS, implied by those result, you might expect the value-pair to be fred="". Wrong.