简体   繁体   中英

Appium Date Picker Scroll android

Hey Guys I am new to Appium Automation testing... I need to work on automating the android default OS Date picker dialog as per the below image. Can some one help me on this? Date picker dialog

Just Use the below code

First open your date picker and use the sample code..


public static String datePicker_ui_id = "android:id/datePicker";

public static String pickers_ui_id = "android:id/pickers";

public static String NumberPicker_ui_id = "//android.widget.NumberPicker";

public static String numberpicker_input_ui_id = "android:id/numberpicker_input";

public static String startDate = "10";

public static String EndDate = "20";

public static String startMonth = "Jun";

public static String Year = "2017";

public static String aler_dialog_cancel_ui_id = "//android.widget.Button[@resource-id='android:id/button2']";

public static String aler_dialog_ok_ui_id = "//android.widget.Button[@resource-id='android:id/button1']";

driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[1]")).findElement(By.id(numberpicker_input_ui_id)).clear();
driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[1]")).findElement(By.id(numberpicker_input_ui_id)).sendKeys(startDate);
driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[2]")).clear();
driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[2]")).findElement(By.id(numberpicker_input_ui_id)).sendKeys(startMonth);
driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[3]")).clear();
driver.findElement(By.id(datePicker_ui_id)).findElement(By.id(pickers_ui_id)).findElement(By.xpath(NumberPicker_ui_id+"[3]")).findElement(By.id(numberpicker_input_ui_id)).sendKeys(Year);
driver.findElement(By.xpath(aler_dialog_ok_ui_id)).click();

As you mentioned, you have to automate a scroll action from left-to-right or right-to-left.

This is an example of how to scroll from right-to-left:

    new TouchAction(wd)
            .press(900, 800)
            .waitAction(Duration.ofMillis(1000))
            .moveTo(900, 200)
            .release()
            .perform();

You can use appium desktop in order to get the proper coordinates, since the resolution of your device matters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM