# Get Attribute as null while there is value?

**URL:** <https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [February 18, 2019, 8:34am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532 "2019-02-18T08:34:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yan\_Jun](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@Yan\_Jun](https://forum.katalon.com/u/Yan_Jun)\
**Post date:** [February 18, 2019, 8:34am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/1 "2019-02-18T08:34:35Z")

</div>

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?**

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/e/e7cf985f55885e7a274e59f3760c1cd22503f1f8.png)

Would like to ask for help from anyone who might know what happened there.

Thank you.

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [February 18, 2019, 8:50am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/2 "2019-02-18T08:50:32Z")

</div>

Hello,  
can you also post snippet of HTML you are trying to adress?

---

<div class="post-metadata">

**Author:** ![Yan\_Jun](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@Yan\_Jun](https://forum.katalon.com/u/Yan_Jun)\
**Post date:** [February 18, 2019, 9:31am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/3 "2019-02-18T09:31:25Z")

</div>

Hi, thanks for the prompt reply. You mean this?

`<div class="k-spreadsheet-cell" style="color: rgb(48, 48, 48); font-family: Arial; font-size: 12px; white-space: pre; overflow-wrap: normal; left: 201px; top: 1px; width: 199px; height: 19px;"><div class="k-vertical-align-bottom">janice</div></div>`

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [February 18, 2019, 9:45am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/4 "2019-02-18T09:45:54Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [February 18, 2019, 5:39pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/5 "2019-02-18T17:39:00Z")

</div>

Some other approaches are:

`WebUI.getAttribute(findTestObject(“Page_Works Order Master File/div_janice”), "textContent");`

or

`WebUI.getAttribute(findTestObject(“Page_Works Order Master File/div_janice”), "innerText");`

Either of these will do what you’re trying to do here.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [February 18, 2019, 6:53pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/6 "2019-02-18T18:53:27Z")

</div>

Neither of which are attributes 🙄

#JustSayin

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [February 18, 2019, 7:42pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/7 "2019-02-18T19:42:49Z")

</div>

> [@Russ\_Thomas](#):
>
> Neither of which are attributes

Indeed. Although Se doesn’t make any distinction between “attribute” and “property” either, so it’s really not a fault of the Katalon API…

---

<div class="post-metadata">

**Author:** ![Yan\_Jun](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@Yan\_Jun](https://forum.katalon.com/u/Yan_Jun)\
**Post date:** [February 19, 2019, 12:48am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/8 "2019-02-19T00:48:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Yan\_Jun](https://avatars.discourse-cdn.com/v4/letter/y/91b2a8/32.png) [@Yan\_Jun](https://forum.katalon.com/u/Yan_Jun)\
**Post date:** [February 19, 2019, 1:03am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/9 "2019-02-19T01:03:25Z")

</div>

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>`

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [February 19, 2019, 4:19am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/10 "2019-02-19T04:19:08Z")

</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.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [February 19, 2019, 4:50pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/11 "2019-02-19T16:50:55Z")

</div>

This post sums up the difference between attribute and property fairly well:

> <https://stackoverflow.com/questions/6003819/what-is-the-difference-between-properties-and-attributes-in-html/6004028#6004028>

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:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/c/c3051bbc9144799efc2eaf6d5e3cd58ffba1d261.png)

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:

![image](https://europe1.discourse-cdn.com/katalon/original/2X/5/52955b75b3c58399f5847e6ba8d81353251ade94.png)

All of the extra data you see after the “input” tag (class, name, type, etc.) are considered **attributes**.

When Russ says:

> [@Russ\_Thomas](#):
>
> Neither of which are attributes 🙄
> 
> #JustSayin

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 `class` **attribute** value, but I can also use it to get the `textContent` **property** 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:

```
WebElement element;
element.getAttribute("class");
element.getAttribute("textContent");

```

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`.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [February 19, 2019, 4:59pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/12 "2019-02-19T16:59:34Z")

</div>

Excellent post (as usual) Brandon.

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.

And that, my friends, **is bad**.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [February 19, 2019, 5:39pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/13 "2019-02-19T17:39:55Z")

</div>

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:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/1/145dca2515e2f836be2fc0fd599b2faf4a5e9716.png)

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:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/e/e833c6ab5ee994ed70132a60a22c42b8c86a0332.png)

against the “value” map entry in the attribute property:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/1/16103ede788d537101ce0427e9600706b586fa7b.png)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [February 19, 2019, 5:51pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/14 "2019-02-19T17:51:45Z")

</div>

Interesting.

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:

```auto
<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.

And that too, my friends, **is bad**.

Anyway, like I said, moving on… 😉

---

<div class="post-metadata">

**Author:** ![kevinquinn1918](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kevinquinn1918](https://forum.katalon.com/u/kevinquinn1918)\
**Post date:** [June 11, 2019, 3:02pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/15 "2019-06-11T15:02:22Z")

</div>

I’m new to web applications and Katalon but I think I’m following this conversation. Right now, I’m trying to change the href attribute on an anchor tag . I’m doing this because I don’t want to go to the actual site, I want to go to a test site instead. I believe that all my code is correct, but when I enter the following command, it does not modify the ‘href’ attribute…

newObject=WebUI.modifyObjectProperty(oldObject, ‘href’, ‘equals’, newUrl, false)

The explanations above completely explains why. As a workaound, Instead of clicking the element, I’m just going to navigate to the newUrl.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [June 11, 2019, 3:13pm UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/16 "2019-06-11T15:13:23Z")

</div>

Hi Kevin

Be aware, we’re talking about raw HTML elements and their attrs/props. Don’t confuse that with Katalon’s TestObject wrappers.

Not saying this issue is not your issue… but I’m surprised you’re having problems with `modifyObjectProperty`.

Advice: Post a new Topic in Web Testing.

---

<div class="post-metadata">

**Author:** ![roopa.yedire](https://avatars.discourse-cdn.com/v4/letter/r/e495f1/32.png) [@roopa.yedire](https://forum.katalon.com/u/roopa.yedire)\
**Post date:** [November 20, 2019, 10:36am UTC](https://forum.katalon.com/t/get-attribute-as-null-while-there-is-value/19532/17 "2019-11-20T10:36:56Z")

</div>

`WebUI.getAttribute(testObject, "textContent");` worked for me; Thanks
