【问题标题】:Appium Date Picker Scroll androidAppium 日期选择器滚动 android
【发布时间】:2018-04-07 00:07:42
【问题描述】:

大家好,我是 Appium 自动化测试的新手...我需要按照下图自动化 android 默认操作系统日期选择器对话框。有人可以帮我吗?Date picker dialog

【问题讨论】:

    标签: android automated-tests appium automator


    【解决方案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();
    

    【讨论】:

    • @Mohan 如果您仍然发现任何困难,请告诉我,我非常乐意为您提供帮助..
    【解决方案2】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2021-12-17
      • 2019-01-11
      • 1970-01-01
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      相关资源
      最近更新 更多