We are trying to automate testing for a hybrid Android app but we are stuck on the date picker. We want to change the value within the date picker to a specific date (Jun. -> May). Therefore we have retrieved the EditText element and tried to change the text.
We have basically tried 2 possibilities:
- Setting the text directly by using sendKeys();
- And first selecting all the text and then setting the text
Using the first option appium told us that the text could not completely removed (Using appium 1.4.0, sendKeys should clear the edit text). Instead the first 2 characters where removed and we were stuck with the characters "n.". We have also tried setting the text (by using sendKeys()) on the number picker (changed android.widget.EditText -> android.widget.NumberPicker).
driver.elementsByClassName("android.widget.EditText").then(function (promisses) {
var promise = promisses[0];
return promise.sendKeys('May').setImplicitWaitTimeout(3000);
});
With the second option we tried using a touch action (wd.TouchAction) to long press the input field and selecting the whole text. Then we used sendKeys to overwrite the selected text. The problem with this option was that using the long press didn't work.
driver.elementsByClassName("android.widget.EditText").then(function (elements) {
var promise = elements[0];
var action = new wd.TouchAction();
action.press({el: promise}).wait(5000).release();
return driver.performTouchAction(action);
});
And
driver.elementsByClassName("android.widget.EditText").then(function (elements) {
var promise = elements[0];
return driver.perform(new wd.TouchAction().longPress(promise));
});
We have also tried changing the context. For retrieving the elements we needed the NATIVE context but to be sure we have also tried the WEBVIEW context and switching in between.
Changing the datepicker text is done in 3 steps:
Retrieving the edit text elements is done by class name which is on android 'android.widget.EditText'. In order to retrieve the elements you should also be in the Native context.
It should also be possible to do it directly on the number picker since it behaves just like an edit text. But we didn't try that.