Appium Date Picker Scroll android

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:46:03

问题


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


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/46940246/appium-date-picker-scroll-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!