简体   繁体   中英

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.

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. Below is the snapshot of 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. 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.

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') )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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