简体   繁体   English

我怎样才能从安卓设备的键盘上按下搜索按钮?

[英]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.我正在使用 appium 进行移动应用程序测试和语言作为 java。

I have given below coding to enter the text by using sendkeys.我已经给出了以下代码来使用 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);

}

Do you have access to developer ?您可以访问开发人员吗? You should check with them if keycode 84 is equivalent to pressing on search button on your app.如果键码 84 相当于按下应用上的搜索按钮,您应该与他们确认。 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.我以前遇到过类似的问题,在按下 android 键盘上的 Enter 按钮时输入键码没有行为,所以我的键码按下脚本没有做任何事情。 Then I used coordinates in that case to press on the Enter button from the keyboard.然后我在这种情况下使用坐标按下键盘上的 Enter 按钮。

The below code is working fine;下面的代码工作正常;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM