Sending android keyevents to text field of a native app

156 views
Skip to first unread message

Adil Imroz

unread,
Dec 11, 2013, 2:24:35 PM12/11/13
to appium-...@googlegroups.com
Hello All,

Can anyone tell me with an example how to send an android keyevent to a particular text field in an android app. 

Until Now I was achieving this by following way::


driver.findElementByXPath("some xpath").click();
sendKeyEvent(153);

Where sendKeyEvent() is as follows ::

public void sendKeyEvent(int code) {

HashMap<String, Integer> keycode = new HashMap<String, Integer>();

keycode.put("keycode", code);

((JavascriptExecutor)Test1.d).executeScript("mobile: keyevent", keycode);

}


But Now when am using the same way to input an alphabetical character through the softkeyboard to a text field, appium responds as if the characters has been supplied to the text field, but actually nothing happened in that text field.


Please help. Would highly appreciate your fast response as I have a critical deliverable pending due to this.

Looking forward to your responses.

Regards

Adil





Vic Wong

unread,
Dec 11, 2013, 6:45:19 PM12/11/13
to appium-...@googlegroups.com

Is there a reason you can't use sendKeys?

WebElement field = driver.findElement(By <your_element>)

field.sendKeys(keys);

Reply all
Reply to author
Forward
0 new messages