Problems to swipe and set values on pickerWheel with Java

I’m using Java for automation with Appium (io.appium.java_client.AppiumDriver) and I can’t find a way to swipe or set values on a pickerWheel.

I have found info on blogs, but is not working fine. Isn’t a offical way to do that?

It will be nice having options like:
dragInsideWithOptions({startOffset:{x:0.0, y:0.0}, endOffset:{x:0.0, y:0.0}, duration:1.0}); for swipe and
pickers()[0].wheels()[0].selectValue(“value”); for the pickerWheel

The code given by Appium Inspector isn’t working either.

@jlipps any ideas/workarounds about this?

I need to swipe over a slider, so using the scroll won’t work for me.

Also about the pickerWheel, is there a way to set values on those?

Thanks!

1 Like

use sendKeys to set values on pickerwheels

1 Like

thanks! pickerWheel issue solved.
I was using sendKeys, but it wasn’t working fine (not sure why)

I’ll post a couple of lines here, that may help some other people.

// define a webelement with the pickerWheel you want to set the values on, here I’m using xpath
// then use sendKeys() to set the value

WebElement _pickerWheel = driver.findElement(By.xpath(“yourpath/UIAPicker[1]/UIAPickerWheel[1]”));
_pickerWheel.sendKeys(“value”);

Hi Neto,

The code is working for iOS but it is not working for Android. Is there any solution for Android to select date from DatePicker.

Hi @jlipps

Hi Team,

Testing an iOS app with 6.1, 7.1 on the real device,It’s working fine with 6.1, but when i am trying to perform sendskey action on 7.0, 7.1 UIPicker Instruments died.
I had tried with below configuration but did’t got success

MAC 10.10, MAC 10.8
Appium 1.3.3 to 1.3.7
Xcode 5.1,6.2

Find Appium logs

info: --> POST /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/element {“using”:“name”,“value”:“Add % Item Tax Override. 1 of 12”}

warn: [DEPRECATED] The name locator strategy has been deprecated and will be removed. Please use the accessibility id locator strategy instead.
info: [debug] Waiting up to 0ms for condition
info: [debug] Pushing command to appium work queue: “au.getElementByName(‘Add % Item Tax Override. 1 of 12’)”
info: [debug] Sending command to instruments: au.getElementByName(‘Add % Item Tax Override. 1 of 12’)
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: Got new command 26 from instruments: au.getElementByName(‘Add % Item Tax Override. 1 of 12’)
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: evaluating au.getElementByName(‘Add % Item Tax Override. 1 of 12’)
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: Lookup returned [object UIAPickerWheel] with the name “Add % Item Tax Override. 1 of 12” (id: 0).
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: responding with:
info: [debug] [INST] 2015-05-22 11:39:42 +0000 Debug: Running system command #27: /Applications/Appium.app/Contents/Resources/node/bin/node /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:{“ELEMENT”:“0”}}…
info: [debug] Socket data received (38 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:0,“value”:{“ELEMENT”:“0”}}
info: [debug] Responding to client with success: {“status”:0,“value”:{“ELEMENT”:“0”},“sessionId”:“35913ec2-af44-453b-a37d-fe988f104193”}
info: <-- POST /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/element 200 870.085 ms - 87 {“status”:0,“value”:{“ELEMENT”:“0”},“sessionId”:“35913ec2-af44-453b-a37d-fe988f104193”}
info: --> POST /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/element/0/value {“value”:[“I”,“t”,“e”,“m”," “,“A”,“s”,“s”,“o”,“c”,“i”,“a”,“t”,“e”,”."," “,“3”,” “,“o”,“f”,” ",“1”,“2”]}
info: [debug] Pushing command to appium work queue: “au.getElement(‘0’).setValueByType(‘Item Associate. 3 of 12’)”
info: [debug] Sending command to instruments: au.getElement(‘0’).setValueByType(‘Item Associate. 3 of 12’)
info: [debug] [INST] 2015-05-22 11:39:43 +0000 Debug: Got new command 27 from instruments: au.getElement(‘0’).setValueByType(‘Item Associate. 3 of 12’)
info: [debug] [INST] 2015-05-22 11:39:43 +0000 Debug: evaluating au.getElement(‘0’).setValueByType(‘Item Associate. 3 of 12’)
info: [debug] [INST] 2015-05-22 11:39:44 +0000 Fail: The target application appears to have died
info: [debug] [INST] 2015-05-22 11:39:44 +0000 Debug: - selectValue is not supported on a picker with undefined values
info: [debug] [INST] Instruments Trace Complete (Duration : 250.839081s; Output : /tmp/appium-instruments/instrumentscli0.trace)
info: [debug] [INSTSERVER] Instruments exited with code 0
info: [debug] Cleaning up after instruments exit
info: [debug] Instruments exited unexpectedly
info: [debug] Shutting down command proxy and ignoring any errors
info: [debug] Closing socket server.
info: [debug] Instruments socket server was closed
info: [debug] Stopping iOS log capture
info: [debug] Reset not set, not ending sim or cleaning up app state
info: [debug] We were in the middle of processing a command when instruments died; responding with a generic error
info: [debug] Cleaning up appium session
info: [debug] Responding to client with error: {“status”:13,“value”:{“message”:“Instruments died while responding to command, please check appium logs”,“name”:“UnknownError”,
“origValue”:“Instruments died while responding to command, please check appium logs”},“sessionId”:null}
info: <-- POST /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/element/0/value 500 2491.327 ms - 230
info: --> GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/source {}
info: <-- GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/source 404 1.061 ms - 40
info: --> GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/orientation {}
info: <-- GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/orientation 404 0.963 ms - 40

info: --> GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/screenshot {}
info: <-- GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/screenshot 404 0.996 ms - 40
info: --> GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/contexts {}
info: <-- GET /wd/hub/session/35913ec2-af44-453b-a37d-fe988f104193/contexts 404 0.928 ms - 40

Hi Jipps
I am trying to set the network by using below code
some times its working fine to set a Wi-Fi
some times it showing error

driver.runAppInBackground(5);
driver.tap(1,driver.findElement(By.name(“Settings”)),1);
driver.tap(1,driver.findElement(By.name(“Wi-Fi”)),1);
Thread.sleep(2000);
driver.tap(1,driver.findElement(By.name(“BLR")),1);
actually when i use the method runappinbackground app moving to background and and i can able to view settings in Iphone and the code working fine but some times app get relaunch and the settings r not visible and the above code get fail

At Last find the solution app and settings of IPhone should not in same screen.

and while launching the app we need to make sure iphone settings is visible

Hey,

I try to select a random month with year, I m unable to select it as scroll/swipe is not working.

PS: It always try to select a current value only as I understand UIAPickerWheel isn’t having list of values, so I try to scroll it, but could luck, any valuable suggestion will be appreciated.

Below is my code snippet with image:


//select from year dropdown driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[7]")).click();

//Get number of UIAPickerWheel’s
List DatePicker = driver.findElements(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAPicker[1]/UIAPickerWheel"));
for (int i = 1; i <=DatePicker.size(); i++) {
IOSElement we = (IOSElement) driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAPicker[1]/UIAPickerWheel["+(i)+"]");
driver.scrollTo(“June”);
we.sendKeys(“June”);
}

Hi All,

In My case I can not use sendkey or set value because in my wheel value is not static. Its change on run time.

Please suggest me can I select the value on the basis of ID or index.

any input will be appreciated.

I’m having a similar problem. The 10 values in the pickerWheel are dates like:
Wed (July 20)
Thu (July 21)

Since these values change every day, I’m looking for some kind of solution where I can pick “the 2nd value”, etc. Any simple solution, without writing a function that gets the current day, date, formats it, etc?

why cant you get just get the current date, thats what i do, but before i got my platform to use setValue properly i would use the TouchAction class and basically blindly click on the x,y coordinates if the screen never changes in size this could work.

TouchAction ta = new TouchAction((IOSDriver)driver)
ta.press(change me X,change me Y).perform()

you can use the precise tap function on the inspector to figure out the location.

Hi @Kyle, TouchAction works, but I want to pick a particular month for doing this I need to scroll the wheel and scrolling is not working in UIAPICKERWHEEEL.

With below code I can successfully pick the particular month but when I perform sendKeys it throws error, please below code and my code snippets:

driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[7]")).click();
   MobileElement we = (MobileElement)          
   driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAPicker[2]/UIAPickerWheel[1]"));
 System.out.println(we.getAttribute("values"));
we.getAttribute("values");
Thread.sleep(2000);
we.sendKeys("Jun");

Please See below error stacktrace:
org.openqa.selenium.WebDriverException: - selectValue requires a valid value (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.38 seconds
Build info: version: ‘2.53.0’, revision: ‘35ae25b1534ae328c771e0856c93e187490ca824’, time: ‘2016-03-15 10:43:46’
System info: host: ‘GGNF1882s-MacBook-Pro.local’, ip: ‘172.16.64.102’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.3’, java.version: ‘1.8.0_74’
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{app=/Users/f2849/Desktop/iOS_ipa/Shine27June.ipa, networkConnectionEnabled=false, databaseEnabled=false, deviceName=iPhone 5, platform=MAC, desired={app=/Users/f2849/Desktop/iOS_ipa/Shine27June.ipa, sendKeyStrategy=grouped, platformVersion=9.3, platformName=iOS, deviceName=iPhone 5}, sendKeyStrategy=grouped, platformVersion=9.3, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=iOS}]
Session ID: b7ca297e-a0ae-4aed-8948-94c406fc20ff
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:27)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:27)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.ios.IOSElement.execute(IOSElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:122)
at com.iOSApp.Shine.Registration_Complete_ThirdScreen.test3_goto_Fill_ProfileInfo(Registration_Complete_ThirdScreen.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)

try this

driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[7]")).click();

((IOSElement)driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATextField[7]"))).setValue("value");

your setting the TextField that the picker is setting, this just basically bypasses the annoying picker. Just make sure the value is formatted to match the what the picker will set.

Thanks a lot @Kyle for your valuable response, but by above code snippets I can only select current date only.

Please refer screenshot of muy UIAutomator : https://cdn-standard.discourse.org/uploads/default/original/2X/d/d02e958b956e6772bc0bffa69a21d8b0279b3ee7.png

Any one having solution for above problem?

I had to delete an table cell and for that I had to perform a swipe gesture. This is in python I am sure there will be similar code for Java.
What I figured out is if you have width/height its easier to perform action.
Get second cell of table.
el = self.driver.find_element_by_xpath("//XCUIElementTypeTable[1]/XCUIElementTypeCell[1]")
Get size
el_size = el.size
print el_size[‘width’]
print el_size[‘height’]
touch = TouchAction(self.driver)
touch.press(el,375,65).wait(15).move_to(el,225,65).release()
touch.perform()

to delete element we need to tap on same location

touch.tap(el,375,65,1).perform()
https://appium.readthedocs.io/en/stable/en/writing-running-appium/touch-actions/