How can sent the date in a datepicker appium (Android API 19, version 1.2.4.1)


#1

Hello,

I have a problem in setting the date from a date picker in Appium. I’m trying to set the date by sending keys in the fields in this way:

List<WebElement> pick = driver.findElements(By.className("android.widget.EditText"));           

        pick.get(0).sendKeys("21");
        pick.get(1).sendKeys("Mar");
        pick.get(2).sendKeys("1989");

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.enter image description here

Any ideas?Thanks!!


#2

@Panos Did you find any solution for this problem ?

My app users Google date widget which has same id for month , date and year. ( id: android:id/numberpicker_input )

I tried using send_keys but it’s not working as expected.

If you can please share your solution , it’ll be helpful

Thanks,
Vikram


#3

@Panos : same question as Vikram -> did you find a solution ?

Thanks


#4

Hi guys, did you find the solution to this issue? I am using appium and I am not able to set the date.


#5

Not really. But have you try with a swipe ?


#6

haven’t tested it myself. but take a look at this discussion: https://github.com/appium/appium/issues/4104


#7

Check if this helps

driver.FindElement(By.Id("com.eos.eos_du_su:id/ed_manufdate")).Click();
((AndroidElement)(driver.FindElement(By.XPath("//android.widget.NumberPicker[@index='0']//android.widget.Button[@index=0]")))).Tap(1, 2);

((AndroidElement)(driver.FindElement(By.XPath("//android.widget.NumberPicker[@index='1']//android.widget.Button[@index=0]")))).Tap(1, 2);

((AndroidElement)(driver.FindElement(By.XPath("//android.widget.NumberPicker[@index='2']//android.widget.Button[@index=0]")))).Tap(1, 2);

driver.FindElement(By.Id("android:id/button1")).Click();

#8

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.

Thanks in advance.


#9

Hi.

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.

I hope it works for you dudes!!


#10

sendKeys() is not working for the date picker. Is there anyone who has found a solution for this?


#11

I resolved this the below way in appium-java client:

Android emulator API level: 28
Android emulator version: 9
Appium java client version: 5.0.4

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.

touchAction.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(currentMonthElement))).release().perform();
driver.getKeyboard().sendKeys(Keys.DELETE);
String monthstr = “Aug”;

//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();


#12

Who uses UiAutomator is best solution. thank you