getAttribute("tag") always returning null

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.

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)

1 Like

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 :slight_smile: @Brandon_Hein @Russ_Thomas
Thanks so much guys…

.

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

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 :slight_smile:

3 Likes

thanks bro, you are amazing =)