Appium: Change Android DatePicker value Javascript/NodeJS -


we trying automate testing hybrid android app stuck on date picker. want change value within date picker specific date (jun. -> may). therefore have retrieved edittext element , tried change text.

we have tried 2 possibilities:

  1. setting text directly using sendkeys();
  2. and first selecting text , setting text

using first option appium told text not removed (using appium 1.4.0, sendkeys should clear edit text). instead first 2 characters removed , stuck characters "n.". have tried setting text (by using sendkeys()) on 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 second option tried using touch action (wd.touchaction) long press input field , selecting whole text. used sendkeys overwrite selected text. problem option using 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 tried changing context. retrieving elements needed native context sure have tried webview context , switching in between.

changing datepicker text done in 3 steps:

  1. select text long press (var action)
  2. delete text key event (devicekeyevent(67))
  3. set text want (settext(text)/sendkeys(text))

retrieving edit text elements done class name on android 'android.widget.edittext'. in order retrieve elements should in native context.

it should possible directly on number picker since behaves edit text. didn't try that.

var els; return driver        .elementsbyclassname('android.widget.edittext')        .then(function (_els) {            els = _els;            var el = els[0];             return setdatepickertext(driver, el, month);        })        .then(function () {            var el = els[1];            return setdatepickertext(driver, el, year);        }); 

function setdatepickertext(driver, el, text) {   var pressduration = 1000;     var action = (new wd.touchaction()).press({el: el}).wait(pressduration).release();   return driver        .performtouchaction(action)        .devicekeyevent(67)        .then(function () {            return el;        })        .settext(text); } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -