How do I let the bot choose between two clickable options?

I want the bot to click one option of the two clickable options on a website with a randomized chance of clicking either one. How do I do this? Thanks.

Hi @Uri22, welcome to the Community.

If you want to click the same absolute button everytime regardless of its position, you must have to make the selector dynamic by passing the variable & removing potential idx from the selector.

If you want to click any one of them, at that time you can use the idx attribute.

Hope this helps,
Best Regards.

I thought using the “SelectMultipleItems” included in the UiPath.UiAutomation.Activities would fix it but It doesn’t find the clickable options on the website. I do not understand exactly what you mean with the Idx attribute, where can I find it?

Hi @Uri22

idx attribute comes to picture when there are simmilar elements structure so to identify it , idx serves as index there, so to make it click randomly, i would recommend to create a random number and then use that in idx (make sure random number generated within limit like b/w 1 and 2 like that )

This would help to make bot click randomly :slight_smile:

Hope it helps :slight_smile:

@Uri22

Select multiple items is to choose multiple options from a dropdown which allows multi selection of fields…

If you want to click on different buttons and if you need it to be random…

Then use two click activities and use if condition and pass true or false as a boolean variable to the if condition using any logic that you want something like Random.Next(0,2).Equals(0)…this statement randomly gives 0 or 1 as output

Hope this helps

Cheers

Hi @Uri22

  1. Generate a random number using the “Random” class in UiPath. You can use the “Next” method of the “Random” class to generate a random integer within a specified range. For example, you can generate a random number between 1 and 2 using new Random().Next(1, 3).

  2. Store the generated random number in a variable using the “Assign” activity in UiPath. You can create a variable of type “Int32” to store the random number.

  3. Use a “Flow Decision” activity in UiPath Studio to check the value of the random number against your desired probability. For example, if you want a 50% chance of clicking option 1 and a 50% chance of clicking option 2, you can use the condition randomNumber = 1 to represent option 1 and randomNumber = 2 to represent option 2.

  4. Based on the result of the “Flow Decision,” use “Click” activity to click on the selected option. You can use “Element Exists” activity to check if the selected option is present on the web page before attempting to click on it.

Thanks!!

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