s3c
s3c

Reputation: 1851

How to type text without selecting an element in CodeceptJS?

Normally I use I.fillField(elementSelector, text) to fill the text into the field with elementSelector xpath or sth.

I have a case where there is only one element (Appium shows no nested elements), that is really six squares one next to the other with a small gap in-between, and if you tap on any of the squares, the first one is focused, and you can type in a 6-digit PIN code to fill all of the squares without tapping each one separately.

Using CodeceptJS I naturally first tried the usual go-to function I.fillField, but the keyboard doesn't pop up so the field is not getting filled.

For debugging purposes, I also tried I.grabElementAndTap and noticed the keyboard doesn't pop up as well. So my conclusion was, that given an even number of squares, both functions I.fillField and I.grabElementAndTap must be tapping directly in the middle between squares 3 and 4, and testing manually I confirmed this would not open the keyboard.

Then I decided for a different approach. Using rect = I.grabElementBoundingRect(elementSelector) I got the exact screen coordinates where one should click for the keyboard to open:

position = {
    x: parseInt(rect.x) + parseInt(rect.height) / 2
    y: parseInt(rect.y) + parseInt(rect.height) / 2
}

Then with

I.touchPerform([{
    action: 'press',
    options: position
}])

I succeded in tapping the element so the keyboard is opened.

How do I type text now just using the keyboard (without getting x,y coordinates of every digit on the keyboard and touchPerform again)?

If I use I.fillField now, I must give the elementSelector as the first parameter, and that closes the keyboard.

Is there a way to type using opened keyboard without selecting anything?

Or is there a way for touchPerform to type text as well?

Upvotes: 0

Views: 365

Answers (1)

boYan
boYan

Reputation: 3

For Android, you can always use:

I.sendDeviceKeyEvent(7) 

Where event "7" would send a "0" key. Here is the list of all Key Events.

For iOS, use:

I.tap('~0')

this would tap on the "0" key on the keyboard, or just change the key to any other key you need instead of 0.

Upvotes: 0

Related Questions