Ionic framework 使用appium将文本输入到ionic hybrid应用程序输入字段的预期方式是什么?sendkeys:无法聚焦元素

Ionic framework 使用appium将文本输入到ionic hybrid应用程序输入字段的预期方式是什么?sendkeys:无法聚焦元素,ionic-framework,focus,appium,sendkeys,Ionic Framework,Focus,Appium,Sendkeys,Appium服务器版本1.9.1 Appium Java客户端v6.1.0 我正在使用Appium自动化一个用Ionic 4构建的混合应用程序。除了Appium的sendkeys方法(element.sendkeys(“”;)之外,一切都很好。尝试与元素交互时,我可以使用.click()点击它们,但如果我尝试发送键,则会出现以下“无法聚焦元素”错误: Appium Java客户端日志: org.openqa.selenium.WebDriverException: An unknown serv

Appium服务器版本1.9.1 Appium Java客户端v6.1.0

我正在使用Appium自动化一个用Ionic 4构建的混合应用程序。除了Appium的sendkeys方法(element.sendkeys(“”;)之外,一切都很好。尝试与元素交互时,我可以使用.click()点击它们,但如果我尝试发送键,则会出现以下“无法聚焦元素”错误:

Appium Java客户端日志:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: cannot focus element
  (Session info: chrome=73.0.3683.90)
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)


at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
    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.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:276)
    at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
    at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
    at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:100)
Appium服务器日志

[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element] to [POST http://127.0.0.1:5309/wd/hub/session/027c8d0e01db56c76726b5f3842aa1d2/element] with body: {"using":"css selector","value":"#logs-filter"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"027c8d0e01db56c76726b5f3842aa1d2","status":0,"value":{"ELEMENT":"0.16747293389607476-4"}}
[JSONWP Proxy] Replacing sessionId 027c8d0e01db56c76726b5f3842aa1d2 with 3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c
[HTTP] <-- POST /wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element 200 76 ms - 107
[HTTP]
[HTTP] --> POST /wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value
[HTTP] {"id":"0.16747293389607476-4","text":"asd","value":["a","s","d"]}
[W3C] Driver proxy active, passing request on via HTTP proxy
[debug] [JSONWP Proxy] Matched '/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value' to command name 'setValue'
[debug] [JSONWP Proxy] Proxying [POST /wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value] to [POST http://127.0.0.1:5309/wd/hub/session/027c8d0e01db56c76726b5f3842aa1d2/element/0.16747293389607476-4/value] with body: {"id":"0.16747293389607476-4","text":"asd","value":["a","s","d"]}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"027c8d0e01db56c76726b5f3842aa1d2","status":13,"value":{"message":"unknown error: cannot focus element\n  (Session info: chrome=73.0.3683.90)\n  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)"}}
[debug] [W3C] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: The request to /wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value has failed
[debug] [W3C]     at JWProxy.proxy$ (C:\Users\jstrickland\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:182:13)
[debug] [W3C]     at tryCatch (C:\Users\jstrickland\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\jstrickland\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[debug] [W3C]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\jstrickland\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke (C:\Users\jstrickland\AppData\Roaming\npm\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[debug] [MJSONWP] Matched JSONWP error code 13 to UnknownError
[debug][JSONWP Proxy]代理[POST/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element]到[POST]http://127.0.0.1:5309/wd/hub/session/027c8d0e01db56c76726b5f3842aa1d2/element]正文:{“使用”:“css选择器”,“值”:“#日志过滤器”}
[debug][JSONWP Proxy]获得状态为200的响应:{“sessionId”:“027c8d0e01db56c76726b5f3842aa1d2”,“状态”:0,“值”:{“元素”:“0.16747293389607476-4”}
[JSONWP代理]将会话ID 027c8d0e01db56c76726b5f3842aa1d2替换为3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c
[HTTP]POST/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value
[HTTP]{“id”:“0.16747293389607476-4”,“text”:“asd”,“value”:[“a”,“s”,“d”]}
[W3C]驱动程序代理处于活动状态,通过HTTP代理传递请求
[debug][JSONWP Proxy]将“/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value”匹配到命令名“setValue”
[debug][JSONWP Proxy]代理[POST/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value]到[POST]http://127.0.0.1:5309/wd/hub/session/027c8d0e01db56c76726b5f3842aa1d2/element/0.16747293389607476-4/value]带正文:{“id”:“0.16747293389607476-4”,“text”:“asd”,“value”:[“a”,“s”,“d”]
[debug][JSONWP Proxy]获得状态为200的响应:{“sessionId”:“027C8D01DB56C76726B5F3842AA1D2”,“status”:13,“value”:{“message”:“未知错误:无法聚焦元素\n(会话信息:chrome=73.0.3683.90)\n(驱动程序信息:chromedriver=2.41.578737(49DA6702B16031C40D63E5618DE03A32F6C197E),平台=Windows NT 10.0.17134 x86)”
[调试][W3C]在运行命令时遇到内部错误:ProxyRequestError:无法将命令代理到远程服务器。原始错误:对/wd/hub/session/3c1b8a7a-a990-4ffa-be83-5b3fcc1d0a2c/element/0.16747293389607476-4/value的请求失败
JWProxy.proxy$(C:\Users\jstrickland\AppData\Roaming\npm\node\u modules\appium\node\u modules\appium base driver\lib\jsonwp proxy\proxy.js:182:13)上的[debug][W3C]
tryCatch上的[debug][W3C](C:\Users\jstrickland\AppData\Roaming\npm\node\u modules\appium\node\u modules\babel runtime\registrator\runtime.js:67:40)
[调试][W3C]位于GeneratorFunctionPrototype.invoke[作为调用](C:\Users\jstrickland\AppData\Roaming\npm\node\u modules\appium\node\u modules\babel runtime\Recreator\runtime.js:315:22)
[调试][W3C]位于GeneratorFunctionPrototype.prototype.(匿名函数)[作为下一步](C:\Users\jstrickland\AppData\Roaming\npm\node\U modules\appium\node\U modules\babel runtime\regenerator\runtime.js:100:21)
[调试][W3C]位于GeneratorFunctionPrototype.invoke(C:\Users\jstrickland\AppData\Roaming\npm\node\u modules\appium\node\u modules\babel runtime\registrator\runtime.js:136:37)
[debug][MJSONWP]将JSONWP错误代码13与UnknownError匹配
我已经确认我的上下文和窗口句柄是正确的(如果元素不正确,我就不能单击它)

我的问题是这是如何运作的?sendKeys是将文本发送到使用appium的ionic应用程序中的html输入元素的预期方式吗?如果是这样的话——这看起来像是一个bug,因为appium没有其他机制来解决这个问题,我需要向他们发送一份bug报告。但也许这不是我想要的方式,我犯了一个错误

关于为什么会发生这种情况的一些想法: 我假设这里的邪恶根源是离子输入元素实际上会召唤一个子输入元素,它是HTML树中的标准输入元素。您可以通过chrome的检查看到这一点。我认为appium正在变得混乱,因为它试图将离子输入视为一个输入,并等待离子输入相对于输入元素是可聚焦的。这就解释了为什么我可以点击这个东西,但我不能给它发钥匙

如果其他人偶然发现了这一点,这里有一些我已经找到的暂时解决办法

  • 您可以使用javascript实现这一点:
    driver.executeScript(“参数[0].setAttribute('value',参数[1])”,元素,“要发送的文本”)
  • 您可以单击该元素,然后执行许多关键事件,例如:
    AndroidDriver d=(AndroidDriver)驱动程序;
    d、 按键(新按键事件(AndroidKey.A));
    d、 按键(新按键事件(AndroidKey.B));
    d、 按键(newkeyevent(AndroidKey.c))

  • 您可以选择标准输入的的子元素,并在此元素上执行sendkeys

    List l=e.findElements(By.cssSelector(“*”);
    l、 获取(0).发送键(文本)