获取文本字段Appium for iOS

时间:2016-05-17 15:03:57

标签: ios uitextfield appium testcase appium-ios

我正在尝试在appium测试用例中访问我的应用程序登录页面的文本字段。目前我正在使用" Restoration 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的位置。

1 个答案:

答案 0 :(得分:0)

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

如果您正确指定了id,这行代码将使您的文本字段中有一个元素。

我能从日志中读到的内容:

  

info:[debug] Id选择器,&#39; com.myapps.myappDummyName:id / loginButton&#39;,   在Localizable.strings中找不到。

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

另外,我希望你不要面对这个:IOS Storyboards: Restoration ID just like Storyboard ID?