简体   繁体   English

使用移动设备滚动日期选择器:appium 中的 selectPickerWheelValue

[英]Scroll Date Picker using mobile: selectPickerWheelValue in appium

I am working with appium and i am trying to select date from Date picker for iOS.我正在使用 appium,我正在尝试从 iOS 的日期选择器中选择日期。

Here is my Code这是我的代码

JavascriptExecutor js = (JavascriptExecutor) driver;
    Map<String, Object> params = new HashMap();
    params.put("order", "next");
    params.put("offset", 0.15);
    params.put("element", dayPicker);
    for (int i=0;i<10;i++) {
        js.executeScript("mobile: selectPickerWheelValue", params);
    }

I want to select day as 10 , some month and year.我想选择日期为 10 ,某个月份和年份。 Below is the snapshot of ui.下面是ui截图。

在此处输入图片说明

But i am getting following error message when i try to use the above code.但是当我尝试使用上面的代码时,我收到以下错误消息。

org.openqa.selenium.WebDriverException: An unknown server-side error 
occurred while processing the command. Original error: Error 
Domain=com.facebook.WebDriverAgent Code=1 "Picker wheel value has not 
been changed after 2 seconds timeout" UserInfo= . 
{NSLocalizedDescription=Picker wheel value has not been changed after 2 
seconds timeout}
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'

I also tried scroll.But, unfortunately scroll is happening 2 times and getting stopped.我也试过滚动。但是,不幸的是滚动发生了 2 次并停止了。 Here is the code.这是代码。

JavascriptExecutor js = (JavascriptExecutor) driver;
    Map<String, Object> params = new HashMap();
    params.put("element", dayPicker);
    params.put("direction", "down");
    params.put("text", "10");
    params.put("toVisible", "true");
    js.executeScript("mobile: scroll" , params);
    System.out.println("******"+dayPicker.getText());

i also want to select country from country list in other part of application.我还想从应用程序其他部分的国家/地区列表中选择国家/地区。 so it would be helpful if you can help me out on how to use these methods like scroll , swipe因此,如果您能帮助我了解如何使用滚动、滑动等这些方法,那将会很有帮助

I am using latest appium desktop version 1.6 and appium server 1.8.我正在使用最新的 appium 桌面版本 1.6 和 appium 服务器 1.8。

Found alternate solution找到替代解决方案

((IOSDriver) driver).findElementByClassName("XCUIElementTypePickerWheel")
                        .sendKeys(text);

Find the xpath for different picker(Date,Month, Year) and set value accordingly (try set_value('1') or set_value('= 1') )找到不同选择器(日期、月份、年份)的 xpath 并相应地设置值(尝试set_value('1')set_value('= 1')

date_picker = driver.find_element_by_xpath('//XCUIElementTypePickerWheel')
date_picker.set_value('1')
JavascriptExecutor js = (JavascriptExecutor) driver;
    Map<String, Object> params = new HashMap();
    params.put("order", "next");
    params.put("offset", 0.15);
    params.put("element",((RemoteWebElement) driver.findElement(dayPicker)).getId());
    for (int i=0;i<10;i++) {
        js.executeScript("mobile: selectPickerWheelValue", params);
    }

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

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