简体   繁体   English

Appium日期选择器滚动android

[英]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. 嗨,大家好,我是Appium Automation测试的新手...根据下图,我需要进行android默认的OS日期选择器对话框的自动化工作。 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. 您可以使用appium桌面来获取正确的坐标,因为设备的分辨率很重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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