0

我正在尝试在 appium 测试用例中访问我的应用程序登录页面的文本字段。目前我正在使用“恢复 ID”来识别文本字段并将其用作唯一标识符。

目前 appium 无法通过“Restoration Id”找到文本字段并给出错误

info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Id selector, 'com.myapps.myappDummyName:id\/loginButton', not found in Localizable.strings.
info: [debug] Pushing command to appium work queue: "au.getElementById('com.myapps.myappDummyName:id\\/loginButton')"
info: [debug] Sending command to instruments: au.getElementById('com.myapps.myappDummyName:id\/loginButton')
info: [debug] [INST] 2016-05-17 12:54:11 +0000 Debug: Got new command 68 from instruments: au.getElementById('com.myapps.myappDummyName:id\/loginButton')
info: [debug] [INST] 2016-05-17 12:54:11 +0000 Debug: evaluating au.getElementById('com.myapps.myappDummyName:id\/loginButton')
info: [debug] [INST] 2016-05-17 12:54:11 +0000 Debug: evaluation finished
info: [debug] [INST] 2016-05-17 12:54:11 +0000 Debug: responding with:
info: [debug] [INST] 2016-05-17 12:54:11 +0000 Debug: Running system command #69: /usr/local/Cellar/node/5.6.0/bin/node /Users/Harry/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Condition unmet after 6942ms. Timing out.
info: [debug] Responding to client with error: {"status":7,"value":{"message":"An element could not be located on the page using the given search parameters.","origValue":""},"sessionId":"345b24b8-82da-31da-85c1-45ae33325c15"}

有人可以告诉我如何通过使用方法 findElementById() 并将唯一 ID 传递给它来获取文本字段。如何从情节提要中的 UITextField 获取该 ID,以及如何在情节提要中指定该 ID。

4

1 回答 1

0
WebElement textField = driver.findElement(By.id("<resource-id of element>"));

如果您正确指定了 id,这行代码将让您从文本字段中获得一个元素。

我可以从日志中读出:

信息:[调试] ID 选择器,'com.myapps.myappDummyName:id/loginButton',在 Localizable.strings 中找不到。

您可能使用了不正确id的字符串来访问该元素。

另外,我希望你没有遇到这样的问题:IOS Storyboards: Restoration ID just like Storyboard ID?

于 2016-05-17T15:16:17.157 回答