首页 > 解决方案 > UI自动化——iOS按回车键

问题描述

我正在尝试在搜索文本时自动按下 ENTER 键

public void pressEnter() {
      ((IOSDriver) driver).getKeyboard().sendKeys(Keys.RETURN);
}

尝试自动按 Enter 键时出现此错误。这里有什么问题?这曾经奏效。我也试过 Keys.ENTER ,它给出了同样的错误。

java客户端版本:6.0.0

org.openqa.selenium.UnsupportedCommandException: sendKeysToActiveElement
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'DESKTOP-JPLMVQR', ip: 'my.ip.address.here', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_152-release'
Driver info: driver.version: IOSDriver

    at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:218)
    at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:117)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:152)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:218)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
    at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35)
    at org.openqa.selenium.remote.RemoteKeyboard.sendKeys(RemoteKeyboard.java:38)
    at com.example.base.BaseTest.pressEnter(BaseTest.java:98)
    at com.example.tests.SearchTests.verifySearch_RedirectToDetail(SearchTests.java:97)

标签: seleniumappium-ios

解决方案


根据您的要求使用此代码更改,而不是 Done 像这样使用 Enter

IOSDriver<WebElement> AD= (IOSDriver) 驱动程序;
AD.hideKeyboard("PRESS_KEY", "完成");


推荐阅读