This works fine in previous versions of API but since I’m testing in a different device now appium seems not to finding my elements correctly. Here is a photo from the inspector window that shows that I’m using the correct class to find the fields.
Hi Guys, Did anyone get a solution for datepicker issue?
I am working on mobile web application and not able to select the date from android native calendar.
This is my first reply to someone/something on this forum XP
I will put the code that works for me (in the most simple way in Ruby).
arg1="2016"
picker = find_element(xpath: "//*[@index='2' and @class='android.widget.NumberPicker']")
picker.textfield(1)
picker.send_keys(arg1)
The index=2 is for the “year” part of the date (for that reason arg1=“2016”), so you can use index=0 to the day and index=1 do the month part. That works if you have 3 elements with the class android.widget.NumberPicker in the date picker.
currentMonthElement is the WebElement that represent the month field in the datepicker. you can use the find by xpath or whichever way you like to find this element. The below code can be reused to enter value for date and year elements. In the place of currentMonthElement variable, please pass the date and year elements.
//This while loop is required since sometimes the month “Aug” was not successfully entered at the first attempt.
while(!currentMonthElement.getText().equals(monthstr)){
driver.getKeyboard().sendKeys(“Aug”);
}
//click on the ok button after setting the date, month and year using the above code.
driver.findElement(By.id(“button1”)).click();