Select date with android datepicker appium

This post explains burning question – How to pass /select date in date picker in android application. Many guys tried to do with swipe but that is kind of passing hardcoded coordinates and not useful in long run.

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

This is how you can select date from datepicker in android app from selenium.

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

here I have used Xpath to find out previous month button and used tap event to select ,I have cast this to android element to get tap event.

So this will go just one value back to current value set in picker .say current month is May then it will select Apr from picker , if selected year is 2016  then it will select 2015.

So if you want to select say Jan then you need to put this in loop and keep tapping.

happy datepicking..

Advertisements

3 thoughts on “Select date with android datepicker appium

  1. ok, I tried it your way it works but everytime while automating a user need to count the loop and work it to get.
    So I wanted to know if there is any either way to use date picker other than this method.

    I’m unable to select the date-picker in an android device using appium.
    I have tried three ways but still am unable to change.
    Kindly suggest me how do I proceed in this.

    **Try #1**
    ((AndroidElement)(driver.findElementByXPath(“//android.widget.NumberPicker[@index=’0′]//android.widget.Button[@index=0]”))).tap(1, 2);
    ((AndroidElement)(driver.findElementByXPath(“//android.widget.NumberPicker[@index=’1′]//android.widget.Button[@index=0]”))).tap(1, 2);
    ((AndroidElement)(driver.findElementByXPath(“//android.widget.NumberPicker[@index=’2′]//android.widget.Button[@index=0]”))).tap(1, 2);

    **Try #2**
    List pick = driver.findElements(By.className(“android.widget.EditText”));
    pick.get(0).sendKeys(“24”);;
    pick.get(1).sendKeys(“5”);
    pick.get(2).sendKeys(“1991”);

    **Try #3**
    driver.findElement(By.xpath(“//android.widget.NumberPicker[@index=’0′]”)).sendKeys(“5”);
    driver.findElement(By.xpath(“//android.widget.NumberPicker[@index=’1′]”)).sendKeys(“5”);
    driver.findElement(By.xpath(“//android.widget.NumberPicker[@index=’2′]”)).sendKeys(“1990”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s