I have a web app that has a combo in it. In my UiPath project
I want to select the last element from that combo. Elements in that combo is dynamic and so, can not not be specified in ‘Select Item’ activity. Can anyone help me out regarding this topic? i am using cross-platform as compatibility.
Welcome to the community
First you can use get text or get attribute and get all the available values in the list…then split that list with any delimiter you see and get the last item and pass to select item
Str.split(","c).Last
Cheers
Hey @Rageeb_Intisar
try use Find Children activity to retrieve all the items in the combo box.
- Target property - use the selector for the combo box.
- Filter property - set it to retrieve only the selectable items. This can usually be done by setting the filter to
<webctrl tag='OPTION'/>
or a similar value depending on the HTML structure. - Scope property - to
FIND_DESCENDANTS
to get all items within the combo box. - To retrieve last item you can use:
childrenElements.Last()
Thanks for your suggestions.
I have extracted the options available with ‘get Attribute’ activity, with Attribute = ‘innerHTML’. and have separated the option from the list and stored it in a variable as a text.
The html for representing all the options : < option value=“0” > --Select Contact Person-- < / option > < option value=“2389” > Mr. John < / option > < option value = “5678” > Mr. William < / option >
After separating the last option, the text is : < option value = “5678” > Mr. William < / option >.
I have stored it in a variable. Now, I can not figure out how to use it to select the option that represents it.
Thanks for your suggestions.
I have extracted the options available with ‘get Attribute’ activity, with Attribute = ‘innerHTML’. and have separated the option from the list and stored it in a variable as a text.
The html for representing all the options : < option value=“0” > --Select Contact Person-- < / option > < option value=“2389” > Mr. John < / option > < option value = “5678” > Mr. William < / option >
After separating the last option, the text is : < option value = “5678” > Mr. William < / option >.
I have stored it in a variable. Now, I can not figure out how to use it to select the option that represents it.
@Rageeb_Intisar
do not missmatch different approaches:
Find children Approach:
- retrieve a collection of UiElements
- take the last Element - myLastUIE = myUIElementSet.Last()
- retrieve the text myUIE.Get(“text”).toString
and use it within the select item
Parsing the inner/outer html:
- we would not recommend processing it with regex/string methods
As an alternate for inner/outer html processing we can work with https://html-agility-pack.net/
- read in the HTML snippet and parse it
- fetch the last option
- fetch the text from the last option
As an alternate to above
Assign activity:
strOptionSelectText = XElement.Parse(strLastOptionText).Value
and use strOptionSelectText within the select item Activity
I guess you can use innertext also
or after getting last get the part between the tags and that is to be assigned to select item
cheers
Use this Get Attribute activity to get all the options within the combo box
Select Item // Use the ‘Select Item’ activity to select the last item from the combo box
Item: comboOptions(comboOptions.Count - 1) // Select the last item
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.