How to submit searching field with android keyboard?

I have a problem with submitting searching field with android keyboard in Appium (selenium, java).I didn't find any working solution and stuck at this point. Please, help me.

I tried this: JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("UIATarget.localTarget().frontMostApp().keyboard().buttons()['Done\'].tap()");

But had an error: org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

Upvotes: 2

Views: 4317

Answers (4)

Long Nguyen
Long Nguyen

Reputation: 10936

This solution in JavaScript worked for me:

Java:

driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));

Javascript:

await driver.execute('mobile: performEditorAction', { action: 'search' });

Notice: This special native api just worked for Android.

This allowed me to submit a search command (same as clicking the search icon in the keyboard).

See http://appium.io/docs/en/commands/mobile-command/ for details on "mobile: performEditorAction".

Upvotes: 0

Satheesh Francis
Satheesh Francis

Reputation: 1

If you are automating mobile web apps, then following is the best way to hide keyboard.

Map<String, Object> BackspaceKeyEvent  = new HashMap<>();
BackspaceKeyEvent.put("key", "67");
((JavascriptExecutor)driver).executeScript("mobile:key:event", BackspaceKeyEvent);

Upvotes: 0

Ru Cindrea
Ru Cindrea

Reputation: 733

You can send ENTER using:

driver.sendKeyEvent(66); // "66 - KEYCODE_ENTER

This link:

http://developer.android.com/reference/android/view/KeyEvent.html

will give you a list of all the Android KeyEvents, if you click on one of them you can see the actual code for it, like here:

http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_ENTER

Hope this helps!

Upvotes: 1

TinyTimZamboni
TinyTimZamboni

Reputation: 5345

You can't execute JS code that way in appium unless you are in a web view.

For hitting the search key, I would do it like this: driver.sendKeyEvent(IOSKeyCode.ENTER);

Upvotes: 3

Related Questions