Selecting values when dropdown items change based on input value

Hi all,

I’m a beginner in UiPath and I’m having a bit of trouble implementing 3 scenarios.

so it starts like this: on the web page, User puts a reference code e.g 1234APK in the search bar and then clicks search; one of 3 things are expected to happen -

To put this into perspective; The items in the dropdown change dynamically sometimes based on input value, if the ref code above (1234APK) gives cat, dog, rat in the dropdown for example, a different ref code; say 1245LKO may give fish, chicken, rat. Rule of thumb is always to choose ‘rat’. ‘Fish’ is always the secondary option.

  1. Logic is: if ‘rat’ is present in dropdown, (irrespective of ‘fish’ being present or not) then ‘rat’ should always be chosen,

  2. if ‘rat’ isn’t available, choose ‘fish’

  3. else i.e. if ‘rat’ nor ‘fish’ isn’t found in the dynamic dropdown items, terminate process.

Not sure if I was able to convey this clearly but I would appreciate any form of help

Thanks.

hi @ceceliaa34,

  1. After you paste the Data in the search Bar.
  2. Read all the Contents of the Dropdown . refer to the link below on how do we read all dropdown items .
  1. Now you have a Array of Strng havng all items from the DropDown. say ListItems.

  2. Take a string variable say item.this will hold the value to select

  3. Take a If Condition and check if the List has Rat , If Yes - Assign the value RAT - Else assign FISH .

  4. use thi item to select the value from dropdown . sample shown below


Mukesh

1 Like

Hi Mukesh,

Thanks for your feedback. I believe the above solution works for a dropdown that contains everything.

In my case, input A may only contain just rat, dog, chicken in the dropdown, while input B may only contain just cat, pig, fish.

In the example above, they are assuming a single dropdown should contain everything but in my case there can be up to 3 different versions of dropdowns containing distinct items.

If we have different values … then the array of String will have different values in each run.

Then it will depend on your if condition how exactly you handle the outputs.


Mukesh

Sorry but could you elaborate further? I’m a beginner at this…

Here - These three values will be in the array of String - rat dog chicken

Here - array of String will have cat pig fish

Now the if condition will work irrespective of the above 2.

If list contains (Fish)
Item : Fish
Else
If list contains (rat)
Item : Rat

We can write nested if statement here

Sorry Mukesh but would it be possible to see a visual process of the array of String conditions in uipath? Because now I have 3 types of ListItems, do I name them ListItems1, ListItems2, ListItems3? It would be incredibly helpful to see this visually in uipath. Thank you

hi @ceceliaa34 ,

For Demo - I am using the below Website in Chrome -

  1. As you see in the screenshot below - I am reading the Friend DropDown
    image

  2. So I am Getting all the Items in a List of String.

  3. Next I am Checking this List of String for the values i want and Based on it I am setting the item Variable… That will be again used to select the item,

  4. I am attaching code for your reference.

DropDownSample.zip (17.3 KB)

Thanks so much Mukesh. I just opened the file now but the 1st and 3rd activities are unable to open on my machine. Compatibility issues I guess… do you mind sending a screenshot? Thanks a million!

image

  1. Attach Browser -
    2.Inside Attach Browser - We have find Children

image

  1. Next we have a For each Loop -
    Inside foreach we have Get attribute and Add to Collection activity

Next we have If and Select Item.

Hi Mukesh, thanks for sending the screenshots. Do you mind if I see the properties tab for ‘Get Attributes activity’? I think I may have missed out on some important elements as I’m still having issues. Thanks for your patience

Also, how was the ListString variable derived? And the Output.Trim item in the “Add to Collection” properties section. Pardon my questions but I’m a total beginner at this. :frowning:

Let me try to explain what is happening in the Flow -

  1. We Attach the Browser and Point it to the page where we have the DropDown
  2. We use Find Children and point it to the Dropdown. This Result is a List of UI Elements called Child… Now Child will have 5 Ui Items Assuming we have 5 element in dropdown
    3.Now we have to extract the item information from each of ui element from child - hence we use a foreach loop and loop items in child.
  3. Inside Foreach we have used the get attribute and defined innertext meaning - the name we want is in the attribute innertext - The output is stored in variable called Output.
  4. Now we have created a List of String - This list of string will be holding all the 5 items from the dropdown’.
  5. Hence - Add to Collection is used - Output.Trim is used just to remove the extra spaces that might come.
  6. After the for each loop completes, we would have a list of string consisting of all the items from Dropdown.
  7. Next we validate the List of Strings for our Condition.


Mukesh

1 Like

Thanks so much Mukesh! Works like a charm!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.