2016-05-17 77 views
0

我想在appium測試用例中訪問我的應用程序的登錄頁面的文本字段。目前,我正在使用「恢復標識」來標識文本字段並將其用作唯一標識符。獲取文本字段Appium for iOS

目前appium是無法通過「中興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(),並通過獨特的有沒有人告訴我怎樣才能得到文本字段編號爲它。我怎樣才能從故事板中的UITextField獲得該ID,以及在故事板中指定該ID的位置。

+0

你用什麼樣的代碼訪問相同的?請將其添加到問題中 – nullpointer

回答

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?

+0

什麼是任何視圖的資源ID,如何從故事板獲取它? –

+0

@AbuzarAmin:嘗試使用'UIAutomator'或'Appium Inspector'獲取它 – nullpointer

+0

@AbuzarAmin:如果可以,您必須添加'textField.getText(); '然後打印它;) – Emna