【问题标题】:How to Handle soft keys like search , enter etc in Appium android如何在 Appium android 中处理搜索、输入等软键
【发布时间】:2016-05-18 02:29:37
【问题描述】:

我正在使用 Appium (java) 自动化我的 android 应用程序。
我在需要输入文本并从软键盘按搜索/输入键的情况下感到震惊。
我尝试了很多解决方案,但是他们都没有工作。
有人试过这个吗?
试过这么远:

WebElement input = driver.findElement(By.id("myId"));
        input.sendKeys(value); // the value we want to set to input
        input.sendKeys(Keys.ENTER);
         genericMethods.wait(1000);

【问题讨论】:

    标签: android testing automation appium


    【解决方案1】:

    使用这个:

    public void tapEnterButtonOnKeyboard() {
            ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ENTER);
        }
    

    【讨论】:

    • 谢谢,但不幸的是它没有奏效。甚至尝试过这个 -AndroidKeyCode.KEYCODE_SEARCH
    【解决方案2】:

    试试这样的

    selenium.keyPress("css=input.tagit-input.ui-autocomplete-input", "13");

    或者

    selenium.keyPressNative("10"); // 输入

    参考资料:

    Typing Enter/Return key in Selenium

    Press Enter key in Selenium script

    http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/Keys.html

    【讨论】:

    • 我有一个 AppiumDriver 驱动程序作为对象,它可以工作吗?
    【解决方案3】:

    我正在使用 1.11.0 Appium 版本,我尝试了这个并且它有效。试试这个:

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

    注意:

    “驱动程序”是一个 AppiumDriver 类型。

    【讨论】:

      【解决方案4】:

      你可能会发现进入软键对象并在其上执行点击事件..它将在 uiakeyboard 节点下..

      【讨论】:

      • 你能解释一下吗?谢谢
      【解决方案5】:

      这个使用 wd 的 JavaScript 解决方案对我有用:

      return driver.waitForElementById(<elementId>).type(<text to type>).click().execute( "mobile: performEditorAction", { "action": "search" } );

      这让我可以找到一个文本字段,输入一些文本,然后提交一个搜索命令(与单击键盘上的搜索图标相同)。当然,您必须将<elementId><text to type> 替换为正确的值。有关“mobile: performEditorAction”的详细信息,请参阅http://appium.io/docs/en/commands/mobile-command/

      【讨论】:

        猜你喜欢
        • 2016-01-15
        • 2018-04-07
        • 1970-01-01
        • 2011-03-13
        • 1970-01-01
        • 2011-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多