How to Select value from a UIAPickerwheel in iOS

Hi, I want to Select time in iOS.
there is a three XPATH for selecting hour, minute and time format i.e (AM or PM).
Using XPATHS and sendKeys method i am able to select minute and time format i.e (AM or PM) but while selecting hour i am unable to select because in that list two times values is present i.e when we scroll down the value starts from 1 2 3 … to 12 for AM format and after that another values is coming i.e 1 2 3 4 … to 12 for PM format.
While using sendKeys() method it is not working because duplicate values are present over there.
Please give a appropriate suggestion, how to select a particular value from a duplicate values?

Can you share the UIA Hierarchy screenshot ?

example with iOS datePicker:

@iOSFindBy(accessibility = "datePicker") // this is done in client code. datePicker has this id
private List<WebElement> datePicker;

String year = "2001";

I wan to select hour and in that list duplicate values are present. then how sendKeys() method will work?

You will have to use XPATH as the locator and then use index, indicating that you want the second hour element.

Hi Rohal,

I also have same situation and m also not able to select the value because having duplicate value in UIAPicker.

have u got solution of your problem. if You found solution , please suggest me.

Yes, I got the soulution .
You have use tap method provided by driver.
You have to take x axis and y axis of XPATH and dimension of XPATH and then tap on it and read the values according to your expected value.
If you still have issue please share ur screen shot

Hi rohal,

can u provide the code of this. I am still not able to scroll.

Point p1=testCase.getDriver().findElement(By.xpath(“XYZ”)).getLocation();
Dimension d1 = testCase.getDriver().findElement(By.xpath(“XYZ”)).getSize();

testCase.getMobileDriver().tap(1, p1.getX()+ d1.getWidth(), p1.getY() + d1.getHeight() -100, 500);

depending whether you have to move towards down side then -100 OR
towards upperside then make +100

the size of XPATH may be vary, so accordingly you have to adjust the x axis and y axis.
Please try above code and let me know . If it is working or not.
if it is not working then please share your screen show with details

I just encountered this as well, after much searching, I came up across two solutions. One I found, one I made. With both, I created a ‘wheel_select’ method and passed in the xpath to the wheel and value I was looking for.

First solution:
find_element(:xpath, wheel).send_keys new_value
selected_value = find_element(:xpath, wheel).value
#puts find_element(:xpath, wheel).value.to_s
#wheel = find_element(:xpath, ‘//UIAPickerWheel[1]’)
selected_value = find_element(:xpath, wheel).value

This was really slow in selecting.

Here’s what I ended up using.
execute_script(" while(UIATarget.localTarget().frontMostApp().mainWindow().popover().pickers()[0].wheels()[#{wheel}].value() != \"#{new_value}\") { UIATarget.localTarget().frontMostApp().mainWindow().popover().pickers()[0].wheels()[#{wheel}].tapWithOptions({tapOffset:{x:0.5, y:0.60}});UIATarget.localTarget().delay(0.4);} ")

Here I pass in the index of the Wheel (which is happening in a popover), and the value I’m looking for.

Thanks rohal,

Now I am able to select value from UIAPicker by code given by you.

Also Thanks to Rockwig, I also try your suggested solution.

Thanks both of you.