Appium Date Picker Scroll android

时间:2017-10-25 19:05:50

标签: android automated-tests appium automator

Hey Guys我是Appium Automation测试的新手......我需要根据下图自动化android默认操作系统日期选择器对话框。有人可以帮我解决这个问题吗?Date picker dialog

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

正如您所提到的,您必须从左到右或从右到左自动执行滚动操作。

这是如何从右向左滚动的示例:

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

您可以使用appium桌面来获取正确的坐标,因为您设备的分辨率很重要。