SeeTestAutomation- setPickerValues
Please note that this tool is classified as a Legacy tool. We recommend transitioning to our updated solutions to maintain optimal performance and security in your workflows. For more information on this matter, please reach out to technical support .
SetPickerValues(zoneName, elementName, index, wheelIndex, value)
Description
Designed command to set values for pickers.
Parameters
- ZoneName - Select Zone
- Element - Select Element (XPath is supported for the picker identifier)
- Index - Picker index
- WheelIndex- Wheel index at the selected picker
- Value - The value to be set
Note: wheelindex is only relevant for iOS, because a picker in iOS might have multiple wheels.
There are two ways to use this command:
- By setting the "Value" to the desired value
- By moving the picker's wheel desired steps
Usage:
Scenario 1: Instrumented
In the following examples, we will set a picker using the UICatalog Test application.
iOS:
Step 1: Get the picker's Native xpath.
How to find the picker's Native properties?
Usually, it can be found behind its components properties:
-
Open Object Spy.
-
Click on one of the picker's components.
-
In the element tree, search for the picker element. The element will have in its 'class' or 'knownSuperClass' the word picker and will surround the whole element.
Copy the xpath of an element.
Step 2: Set the requested wheel index (count starts from 0 left to right) and its value .
In the given example we set the wheel index to 1 and its value to be 4.
Result:
Android:
-
Get the picker locator:
2. Run:
-
-
client.setPickerValues("NATIVE", "xpath=//*[@class='android.widget.TimePicker']", 0, 0, "time:11.5");
-
3.Result:
Scenario 2: Non-Instrumented
In the following example, we will set a picker using the Clock application.
iOS:
Step 1: Get the picker's Native XPath.
How to find the picker's Native properties?
Usually, it can be found behind its component properties:
-
Open Object Spy.
-
Click on one of the picker's components.
-
In the element tree, search for the picker element. The element will have in its class' or 'knownSuperClass' the word picker and will surround the whole element.
Copy the XPath of the element.
Step 2: Set the requested wheel index (count starts from 0 left to right) and its value.
In the given example we set the wheel index to 0 and its value to be 6.
Result:
Android:
Supported for android.widget.NumberPicker class pickers
-
Get the wheel picker locator:
****
-
Set the indexes:
-
Set the index parameter of the picker, taken from the Object Spy
-
Set the wheel index to 0 (not relevant in Android)
-
-
Run:
-
-
client.setPickerValues("NATIVE", "xpath=//*[@class='android.widget.NumberPicker']", 0, 0, "text:15");
this means, set the picker value to text=15.
-
4. Result:
Scenario 3: Web
In the following example, we will set a picker using Safari in Wikipedia page.
Step 1: Get the picker's Web xpath.
How to find the picker's Web properties?
The Web picker is represented by a Web element and a Non-instrumented element.
The Web element is the field where the selection is shown. The Non-instrumented element is the Picker that opens when clicking the field.
-
Open the Object Spy.
-
Click on the language field
-
Web picker will always have a node called 'SELECT'.
Get the xpath of the 'SELECT' element.
Step 2: Set the requested wheel index (count starts from 0 left to right) and its value.
In the given example we set the wheel index to 0 and its value to be 'Eesti'
Result:
We could have get the same result by using the element xpath=//*[@knownSuperClass='UIPickerView'] in Zone Native
Code Example
// UICatalog
client.setPickerValues("NATIVE", "xpath=//*[@class='UIPickerView']", 0, 1,"1");
// Wikipedia page
client.setPickerValues("WEB", "xpath=//*[@id='searchLanguage']", 0, 0, "Eesti");
Move Picker Wheel:
Another way to set your picker value, is by moving the wheel N steps (Instead of assigning a specific value to the picker).
Usage:
Scenario 4: Instrumented
In the following scenario, we will set the picker value by moving the picker on the UICatalog Test application.
To know how we chose the xpath in this scenario, please see scenario 1.
Example 1:
-
In this example we set the wheel index to 0 and we will move the wheel 2 steps, choosing the third element in the picker.
-
Set Properties:
Result:
Example 2:
- In this example we will change the rating for John Appleseed from 6 to 2.
- Set properties:
Result:
Scenario 5: Non-Instrumented
In the following scenario, we will set a picker value by moving the picker index in the Clock application.
To know how we chose the xpath in this scenario, please see scenario 2.
Example 1:
In this example we will change the hour from 17:30 to 10:30
- Set Properties:
Result:
Example 2:
In this example we will change the minutes from 10:30 to 10:40 in the above image.
- Set properties:
Result:
Android:
In this example we will set the picker by swiping down 15 times in the picker
-
get the wheel picker locator:
****
-
Set the indexes:
- Set the index parameter of the picker, taken from Object Spy
- Set the wheel index to 0 (not relevant in Android)
-
run:
-
client.setPickerValues("NATIVE", "xpath=//*[@class='android.widget.NumberPicker']", 0, 0, "down:15");
-
this means, scroll 15 steps down the list.
4.result:
Note if you set the picker value to an index that does not exist, an exception will be thrown.
Code Example
// UICatalog
client.setPickerValues("NATIVE", "xpath=//*[@class='UIPickerView']", 0, 1, "down:4");