Mobile Set Text / Send Keys Without element

Hi All,

Does anyone know how to send texts into the textbox without using element? (When element not traceble)

Thanks
NU

@nithizunnikumaran21
If you want to insert text using send text/send keys to a text box you should Define the element.
if you want to send keyboard actions you can able to do it without elements
by select the type as keys in the manual mode on a test case.

hi @nithizunnikumaran21

you can type into whatever field currently has focus without locating it. tap where the field is (Mobile.tapAtPosition) so the keyboard comes up, then:

android (uiautomator2):

def driver = MobileDriverFactory.getDriver()
driver.executeScript('mobile: type', [text: 'hello'])

older drivers that do not have mobile: type accept the same through adb: driver.executeScript('mobile: shell', [command: 'input', args: ['text', 'hello']]), needs the adb_shell insecure feature enabled on the appium server.

ios (xcuitest):

driver.executeScript('mobile: keys', [keys: ['h','e','l','l','o']])

or driver.getKeyboard().sendKeys('hello') which is the older appium way and still works in the java client katalon ships.

that said, “not traceable” usually just means the field is not in the page source at the moment you spy, do a Mobile.getAttribute on the parent or dump the source (driver.getPageSource()) after tapping, the EditText tends to be there once the keyboard is open.

Good answer @depapp . A few additions for @nithizunnikumaran21:

  1. Since you tagged custom-keyword, here’s a reusable version that picks the right call per platform:

@Keyword
def typeIntoFocused(String text) {
def driver = MobileDriverFactory.getDriver()
if (driver instanceof io.appium.java_client.android.AndroidDriver) {
driver.executeScript('mobile: type', [text: text])
} else {
driver.executeScript('mobile: keys', [keys: text.toList()])
}
}

  1. Tap the field first and add a short Mobile.delay(1) so it has focus and the keyboard is up before typing.
  2. If you fall back to adb shell input text, spaces must be sent as %s and special or unicode characters often fail, so prefer mobile: type where the driver supports it.
  3. If the field really isn’t in the page source even with the keyboard open (Flutter, canvas or game UIs), these won’t help and you’d need that framework’s own driver or image-based taps.