Get UiElement from datatable

Hi guys,
I collect UiElements using Find Children Activity and add them to datatable. After that problem is how to get UiElements from datatable:

  • datatable with 2 columns: Element Name(string), Element(UiPath.Core.UiElement)

ElementsTable.Rows(0).Item(1) returns Object instead UiElement.
ElementsTable.Rows(0).Item(1).ToString returns string

Do you have idea how to pull UiElement to use it for example with click activity?

Regards,
Maciej

Try this

declare a variable of type UiElement (say myElement)

myElement = ElementsTable.Rows(0).Item(1) //using assign activity

As I wrote:
ElementsTable.Rows(0).Item(1) returns Object instead UiElement.
“disallows implicit conversion from ‘Object’ to ‘UiPath.Core.UiElement’”

Did you ever find a solution to this? I’m running into the same problem trying to store a UiElement in a Dictionary(of string, object) and getting it back out as a UiElement to use in a Click activity.

Unfortunately I didn’t.

I found that using DirectCast(MyDict(“Some Key”), UiPath.Core.UiElement) worked, although for my purposes it was a less than desirable solution so I just stored the UiElement in a variable separate from the dictionary.

1 Like

Ugh, this was difficult to find info on. However, I did find a working solution.

Side note: using the Build Datatable activity wouldn’t work to store a UiPath.Core.UiElement datatype; I had to use the activity Add Data Column – just FYI.

Retrieving the UiElement from the datatable is done by assigning it to a variable in a For Each Row in Data Table activity before using it – if you create the variable using the Ctrl+K shortcut, be sure to open the Variables panel and change the type to UiPath.Core.UiElement:


Note that in the Assign activity I had to wrap the saved UiElement data from the datatable with CType, which casts it back to the UiElement datatype from how it’s stored in the datatable.

I save the UiElement into the datatable the same way you’d save anything in a datatable:


#storeUiElements #saveUiElements save UiElements store UiElements

2 Likes

Buuuuuut my above solution comes up against many problems.

TL;DR: Solution = Save the UiElement’s Selector instead of the entire UiElement; then use that as the Strict Selector when you need that UiElement.

I can always extract the first UiElement from the datatable, but I’m lucky if the 2nd doesn’t come out without a “!” for its Attributes or Selector properties, or “null” for its ImageBase64 or _cachedSelector/_cachedAttributes properties.

Seems the reason is due to a large amount of data stored in the Attributes and Selector properties. I tried a number of things, but the best turned out to be saving the Selector to the datatable (since my use-case is to use the elements in the next step of my automation, almost immediately, and hence not much chance for change, and knowing my scraped elements won’t change until a page refresh). I use that saved Selector String in my Click activity’s Strict Selector property, and it picks it right up.

FYI, my research indicates saving UiElements is at the limit of retrieval on Windows machines, in large part because UiPath needs to maintain compatibility with many 32-bit programs. As such, the message pipes a 32-bit program is limited to means we can use the absurdly large amount of data it takes to pass just one UiElement as part of a datatable’s row – it’s just too much.