# getAttribute("tag") always returning null

**URL:** <https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [December 3, 2018, 9:04pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569 "2018-12-03T21:04:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taylor\_Russi](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/taylor_russi/32/812_2.png) [@Taylor\_Russi](https://forum.katalon.com/u/Taylor_Russi)\
**Post date:** [December 3, 2018, 9:04pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569/1 "2018-12-03T21:04:22Z")

</div>

Hi all,

I’m trying to collect some attributes from basic fields within my script. This code correctly gets the type and id of my objects, but always gives “null” for the tag.

```auto
thiselement = fields.get(x).getAttribute("type")thiselement += " "thiselement += fields.get(x).getAttribute("tag")thiselement += " "thiselement += fields.get(x).getAttribute("id")System.out.println(thiselement)

```

Object spy shows that all of my elements have tags, so I’m a bit baffled. Does getAttribute not work for all the attributes displayed in the object repository? Is there a different way to get the tag within a script?

Thanks for any help! (and please consider me a newb in your replies)

---

<div class="post-metadata">

**Author:** ![luis.contreras](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@luis.contreras](https://forum.katalon.com/u/luis.contreras)\
**Post date:** [October 16, 2019, 3:15pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569/2 "2019-10-16T15:15:00Z")

</div>

Hello

I have the same problem that happens to @Taylor_Russi.

I try to save an attribute called “text” in a variable, and then use the variable later. But it saves “null”

can you help us please 🙂 @Brandon_Hein @Russ_Thomas  
Thanks so much guys…

.

 ![222](https://europe1.discourse-cdn.com/katalon/original/2X/4/43c42f6d5e43e137b50904860b77486db001667b.jpeg)

![333](https://europe1.discourse-cdn.com/katalon/optimized/2X/2/21d59ee2a1331a9097778b5c7c33adccefad0839_2_690x60.jpeg)

 ![111](https://europe1.discourse-cdn.com/katalon/original/2X/5/5dfa2d980bb854d12793a6f63607754d647f6de7.jpeg)

---

<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:** [October 16, 2019, 3:23pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569/3 "2019-10-16T15:23:52Z")

</div>

Very few HTML elements have a text attribute (HTML OPTION elements do, but I can’t think of another).

I think you should be using `WebUI.getText()`

> **[\[WebUI\] Get Text](https://docs.katalon.com/katalon-studio/docs/webui-get-text.html)**
>
> Description   Get the visible (i.e. not hidden by CSS) inner text of the web element, including sub-elements, without any leading or trailing whitespace. Parameters   Param Param Type Mandatory Description...

---

<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:** [October 16, 2019, 4:02pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569/4 "2019-10-16T16:02:54Z")

</div>

This is a common misconception.

`text` is (almost) never an attribute of an element, but is instead usually a separate node. Therefore, trying to use WebUI.getAttribute(…, ‘text’) will (almost) never work. Let me try to demonstrate the difference between a text **attribute** and a text **node** :

1.) A text **attribute** would look something like this:

`<div text="some_text"></div>`

In this scenario, you could use WebUI.getAttribute(…, ‘text’) to retrieve the value “some\_text”, because `text` is an attribute within the `<div>` element. However, I don’t think I’ve ever seen a `text` attribute like this. As Russ mentioned, maybe you would find it in an `<option>` element on occasion.

2.) A text **node** would look something like this:

`<div>some_text</div>`

This is typically how text is presented. Since you haven’t shared any HTML, I’m assuming this is what you’re really after. If so, then again as Russ has shared, you should locate the containing element (the `<div>` in my example), then use WebUI.getText() on that element.

Hopefully that makes a little more sense 🙂

---

<div class="post-metadata">

**Author:** ![luis.contreras](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@luis.contreras](https://forum.katalon.com/u/luis.contreras)\
**Post date:** [October 23, 2019, 12:45pm UTC](https://forum.katalon.com/t/getattribute-tag-always-returning-null/14569/5 "2019-10-23T12:45:47Z")

</div>

thanks bro, you are amazing =)
