selvi
selvi

Reputation: 1457

How can I able to press search button from keyboard of android device?

I am using appium for mobile app testing and language as java.

I have given below coding to enter the text by using sendkeys.

After entering the text, I need to press the search button from keyboard.

For that I have used key code event to press the search button. But the search action doesn't happen for me.

@Test
public static void test_demo() throws Exception {
    WebElement element = driver.findElement(By.id("mytextfield"));
    element.sendKeys("Chennai");

    // press search button
    driver.sendKeyEvent(84);

}

Upvotes: 0

Views: 3839

Answers (2)

Deepu
Deepu

Reputation: 1

The below code is working fine;

element.click();    
element.sendKeys("text");    
driver.executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));

Upvotes: 0

vvvvaib
vvvvaib

Reputation: 334

Do you have access to developer ? You should check with them if keycode 84 is equivalent to pressing on search button on your app. It depends on how it is coded. I have faced similar issue previously where enter keycode was not behaving as it presses the enter button on the android keyboard so my keycode press script wasn't doing anything. Then I used coordinates in that case to press on the Enter button from the keyboard.

Upvotes: 1

Related Questions