Banner background image
UI Automation Activities
Last updated Apr 26, 2024

Creating Variables From Selector Attributes

This tutorial demonstrates how to create a variable out of attributes found inside selectors. The example used in this tutorial shows how to create a variable out of the idx attribute.
The given scenario shows how to select multiple images that are on the same device screen, using a single Tap activity. This is achieved by creating a variable out of the idx attribute.

The tutorial uses a demo UiPath application. You can download the app here.



  • Install Mobile.Automation version 22.10, or higher.
  • Create a Mobile Testing Project.
  • Create an application where you have to select multiple images that are on the same screen, or page.
  1. Add a Tap activity inside your main workflow.
  2. Click Indicate Target, and select the first photo on the device screen.

    For this example, the Selector method has an idx attribute. In other cases, the Fuzzy selector method can have this attribute as well.

  3. Right-click the value of the idx attribute. For this example, right-click '2', and then click Use variable (Ctrl + K).

    A configuration panel opens.

  4. In the Variable Name field, type the name that you want for the new variable, and click Confirm. For this example, the variable name is photoIdx.

    A new variable is created inside the Variables panel. You can now use this variable inside your workflow, with other activities.

  5. In the Selection Options window, click Confirm to save the configuration of the target.
  6. Add a For Each activity into your main workflow.
  7. Add an Assign activity inside the For Each activity.

    7.1. In the To variable field, input the variable created from the selector. For this example, input the photoIdx variable.
    7.2. In the Set value field, type the following expression: currentItem.toString.
    This expression determines the For Each activity to iterate through each image using the photoIdx variable.
  8. Go to the For Each activity. Inside the List of items field, input the list of images that you want to iterate through, using the following method: Enumerable.Range(2, 6).
    For this example, we want to iterate through six images in total, where the first image has the value of the photoIdx variable as 2.
  9. Drag the previous Tap activity inside the body of the For Each activity, and place it after the Assign activity.
  10. For this example, tapping an image prompts you to tap an OK button. Therefore, add another Tap activity inside the body of the For Each activity, that taps the OK button after each image tap.

Sample workflow

To check the complete workflow or to have a future reference, download the XAML example

  • Tutorial
  • Sample workflow

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.