ios InvalidElementStateException:消息:Error Domain=com.facebook.WebDriverAgent Code=1“屏幕键盘必须存在才能发送密钥”

w3nuxt5m  于 2023-05-19  发布在  iOS
关注(0)|答案(3)|浏览(269)

我试图在真实的的iPhone设备上的Safari上输入URL,但得到了这个错误
InvalidElementStateException: Message: Error Domain=com.facebook.WebDriverAgent Code=1 "The on-screen keyboard must be present to send keys" UserInfo={NSLocalizedDescription=The on-screen keyboard must be present to send keys}
这是我的代码

**** Settings ****
Library    Selenium2Library
Library    Collections
Library    requests
Library    AppiumLibrary

**** Test Cases ****
Test_case_sample
    Open application    http://127.0.0.1:4723/wd/hub    alias=Phone    platformName=iOS    platformVersion=13.3    deviceName=iPhone    bundleId=com.apple.mobilesafari
    ...    udid=**********************    nativeWebTap=true    automationName=XCUITest    noReset=false    wdaLocalPort=8145    useNewWDA=true
    AppiumLibrary.Input Text    xpath=//XCUIElementTypeButton[@name="URL"]    https://www.google.com/
    Hide Keyboard    Go

1.我没有安装任何第三方键盘。
我不想使用browserName=Safari,因为我想验证URL链接。
3.输入问题只发生在Safari上。
iPhone 7 iOS 13.3 Appium 1.17.1-1
谁能帮帮我。

smtd7mpg

smtd7mpg1#

这似乎是一个已知的问题与appium。这里有一个线程谈论它:https://github.com/appium/appium/issues/10418
至于我,我修复了这个问题,在发送之前点击元素,向它发送密钥。

arknldoa

arknldoa2#

更换

AppiumLibrary.Input Text    xpath=//XCUIElementTypeButton[@name="URL"]    https://www.google.com/

有以下三行:

AppiumLibrary.Click Element  xpath=//XCUIElementTypeOther[@name="Address"]

这似乎是您可以单击的地址元素。单击该元素后,该元素将变为文本字段。但至少在我尝试的时候,xpath的读取速度不够快,除非我们等待它变得可见,否则测试将失败:

AppiumLibrary.Wait Until Element Is Visible  xpath=//XCUIElementTypeTextField[@name="URL"]

现在输入文本:

AppiumLibrary.Input Text    xpath=//XCUIElementTypeTextField[@name="URL"]    https://www.google.com/

如果您遇到脚本无法找到第一个元素的问题,那么您可能还需要一个Wait Until Element Is Visible

gwo2fgha

gwo2fgha3#

在我的情况下,通过在设置文本值之前单击与输入元素相关的附近文本标签,解决了这个问题。我猜这是由于输入元素的值可以通过扫描以及在这个应用程序中添加。

相关问题