【问题标题】:Accessing mobile virtual keyboard using appium使用 appium 访问移动虚拟键盘
【发布时间】:2016-07-26 20:07:46
【问题描述】:

我正在使用 appium 进行移动自动化,在这种情况下,我需要在提供输入后单击移动虚拟键盘上的 "Done" 按钮。如何在 appium 中使用WebDriver

【问题讨论】:

标签: java appium


【解决方案1】:
  1. 我相信来自@Slavo 的解决方案在 appium 中已被弃用。虽然具有相同键事件的 adb 命令应该可以工作,即

    adb shell input keyevent 66

  2. 在大多数情况下,您的输入主要是单个衬里,例如执行搜索。在这种情况下,您可以将前一行更改为:

    WebElement myTextView = <find your text-view> myTextView.sendKeys("your-text/n"); // "/n" as a new line in java

  3. 您还可以隐藏键盘并使用其上的其他屏幕小部件执行操作。喜欢:

    driver.hideKeyboard(); WebElement otherGoodToGoButton = <find other useful button/widget> otherGoodToGoButton.click();

  4. 使用TouchActions 点击屏幕坐标也是一种方法,但我不建议使用它。

【讨论】:

    【解决方案2】:

    您可以使用隐藏键盘功能

    driver.hideKeyboard()
    

    谢谢, 萨迪克

    【讨论】:

      【解决方案3】:
      driver.pressKeyCode(AndroidKeyCode.ENTER);
      

      【讨论】:

        【解决方案4】:

        我们在使用原生数字键盘上的 done 复选框时遇到了很多麻烦,而且所有 keyevent 键码都不起作用。最后,这个脚本对我们有用:

        $driver.execute_script("mobile:performEditorAction", {'action'=>'done'})
        

        无论您使用什么语言...执行脚本'mobile:performEditorAction'并发送一个哈希{'action' => 'done'}。

        【讨论】:

          【解决方案5】:

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

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

          这让我可以找到一个文本字段,输入一些文本,然后提交一个搜索命令(与单击键盘上的搜索图标相同)。

          当然,您必须将&lt;elementId&gt;&lt;text to type&gt; 替换为正确的值。有关“mobile: performEditorAction”的详细信息,请参阅http://appium.io/docs/en/commands/mobile-command/

          您可以将“搜索”替换为“完成”或上面链接中的各种其他命令。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-09-14
            • 1970-01-01
            相关资源
            最近更新 更多