Appium Server v 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
我已经确认我的上下文和窗口句柄是正确的(如果不是,则无法单击元素)。
我的问题是打算如何工作? sendKeys是将文本发送到带有appium的离子应用程序中将文本发送到html输入元素的预期方式吗?如果是这样-这似乎是一个错误,因为appium对此没有其他机制,因此我需要向他们发送错误报告。但这也许不是预期的方式,我犯了一个错误?
为什么会这样: 我假设这是邪恶的根源,实际上离子输入元素会让人联想起子输入元素,而子输入元素是HTML树中的标准输入元素。您可以通过chrome进行查看。我认为Appium感到困惑,因为它试图将离子输入视为输入,并等待离子输入相对于输入元素聚焦。这就解释了为什么我可以单击事物但不能发送密钥给它。
以防万一其他人偶然发现此问题,这是我暂时发现的一些解决方法。
driver.executeScript("arguments[0].setAttribute('value', arguments[1])", element, "text-to-send");
您可以单击元素,然后执行很多关键事件IE:
AndroidDriver d = (AndroidDriver) driver;
d.pressKey(new KeyEvent(AndroidKey.A));
d.pressKey(new KeyEvent(AndroidKey.B));
d.pressKey(new KeyEvent(AndroidKey.c));
您可以选择
List<MobileElement> l = e.findElements(By.cssSelector("*"));
l.get(0).sendKeys(text);