Handling Get Attribute Activity error in UIPath

Good day!

Hi Team, I’m a beginner UiPath user and exploring its functionalities for our possible next test automation tool, I would kindly ask for help on handling the Get Attribute activity. I have issues on Web UI elements with attribute that returns boolean or int32. For example I use Get Attribute activity to get the attribute: visibility which returns 0 or 1, and relativeVisibility which returns True or False. Every time I use this I encounter an error:

I also tried setting the variable to int32 or boolean but a different error was displayed:

I also tried setting the output variable to generic value but I still encountered the first error.

It seems that the error was encountered when handling non-string attribute values

Hi @fanta32

Define the output variable as string and store the result in that.

Alternatively, you can also go through below video tutorial in same.

Hi @sonaliaggarwal47,

Thank you for your response on this, I have tried your suggestion by defining the output variable to string and follow the instructions from the video that you referred. But during run time an error was encountered.

Can you zoom out abit, is this inside of a verify activity? I think thats part of your issue here and you need to configure things slightly differently.

Hi @Jon_Smith,

Thank you for your time checking this, here is the full screenshot:

I hope its not too small for viewing. Its under a Main Sequence > Use Application/Browser > Do. Please tell me if you need a much clearer picture or other details that I can provide.

Ah ok, I think I see why you have an issue then, the stuff you put on the tests threw me off.

Try this.

Delete the variable you have there already, and remove it from the properties pane.
Now go to the properties pane where you have the ‘Attribute Value’ out argument. Press ctrl + k and type out the variable name and press enter.
This will make a new variable with the data type of that property. I think that should solve your issue.
The attribute will be an enum, rather than a string.

it returns Enum…
could be 0 or 1 or 2.. so you need to type cast it using Cint or string.

to get like a number in string format : CInt(result).ToString
OR
to get the actual result as string : result.ToString

do not change the type of the result. it should be by default type NVisibilityLevel

You dont have to cast, you can just use the enums as they are intended and compare the enum returned to the enum you want, no turning it into ints or strings.

I tried what you recommended, delete the existing variable then I set a new one (via ctrl+k). I created a new variable but with String data type.

Ok, then its a string data type on that attribute. Not an Enum apparently. You can confirm by hovering over the argument in the property pane.

What you have shown so far is a verification issue, not a runtime error, so you need to show us where you are verifying this value and the code to read the attribute looks fine.

Here is the run time error I encountered when I let the variable retain the string data type:

StringConverter cannot convert from System.Int32

I also thought the attribute value is already in String since the created variable is automatically in String (data type), I don’t understand why it has an error converting from int32.

The returned value is neither string nor int32, its called ENUM and is of the type NVisibilityLevel, you should not create a variable of type string and pass it to the Attribute value field.
remove your string variable from Attribute value textbox and press “ctrl” + “K” and then give the name of the new variable, and when you see the type of new variable under datamanager->Variables, it should be NVisibilityLevel.

Regards
SG.

Hi @fanta32 Welcome to the community

Remove the existing variable in the get attribute field

then create the new variable , now you can see the variable type as NVisibiltylevel

Refer the below image

Regards,
Gowtham K

Can you refresh that attribute, it the activity seems messed up and thinking its a string when its an Enum then.

What version of the UiAutomation activity pack are you using also?

Hi @Jon_Smith,

I tried refreshing the attribute in the activity but I still get the same issue. Here are the dependency versions I’m currently using:

Im currently also using modern design.

Hi @golla.sandeep,

Thank you for responding on my inquiry. I also tried to removed the variable and created a new one. But upon creation, the new variable data type defaults to String. You may kindly refer to my previous reply to Jon.

Manually changing the data type to NVisibilityLevel also causes an issue.

Hi @Gowtham_K115,

Thank you for responding on my inquiry, I also tried to remove the existing variable then created a new one, but the newly created variable data type always defaults to String, manually updating the Data Type to others causes an issue. You may refer on my previous replies to Jon.

May I ask on how do you get the Save to field in your activity? My Get Attribute activity has only Attribute field, I can try that Save to to see if it can resolve my issue.

Interesting how the Attribute value is typed as as visibility without any double quotes, in your get attribute activity…
it takes string inputs whatever attribute name you mention, has to be typed with double quotes.
Pls don’t tell me, its another variable.. :stuck_out_tongue:

so i think what you need to do is put another Get attribute activity and “SELECT” the attribute type as Visibility from the dropdown and then goto your attribute value property and press “ctrl+K”(to create a new variable) and give it a name…
it should then populate the correct return type.

FYI…

Attribute “visibility” is an ENUM, while Attribute “Visible” is a Bool.
there’s no other attribute related to visibility that returns a string.