Appium can't find objects on real devices( iPhones) -(appium/instruments bug?)

Hi

I am using appium 1.3.5 java 1.8.25 and real devices such as iPhone4s(7.1) iPhone6 (8.1) iPhone6+(8.1)
and i have an issue with identifying objects. I tried using the page object design pattern and driver.find to find the objects. I am aware of the known issue that objects in iOS can become invalidated immediately so i tap on an object immediately after i find one.But the problem is that appium just doesn’t find the objects ! as i mentioned earlier ,it happens randomly and sometimes the tests passes (about 50% of the times)

For example this is what i see in the appium server log when trying to find an object that i can see on the screen by it’s name.

info: --> POST /wd/hub/session/487a1e1a-b0e0-4bf4-8756-16859094d708/element {“using”:“name”,“value”:“Contacts”}
info: [debug] Waiting up to 1000ms for condition
info: [debug] Pushing command to appium work queue: “au.getElementByName(‘Contacts’)”
info: [debug] Sending command to instruments: au.getElementByName(‘Contacts’)
info: [debug] [INST] 2015-03-04 07:16:55 +0000 Debug: Got new command 3 from instruments: au.getElementByName(‘Contacts’)
info: [debug] [INST] 2015-03-04 07:16:55 +0000 Debug: evaluating au.getElementByName(‘Contacts’)
info: [debug] [INST] 2015-03-04 07:16:58 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-03-04 07:16:58 +0000 Debug: responding with:
info: [debug] [INST] 2015-03-04 07:16:58 +0000 Debug: Running system command #4: /usr/local/bin/node /Users/hannuchka/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 4162ms. 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”:“487a1e1a-b0e0-4bf4-8756-16859094d708”}
info: <-- POST /wd/hub/session/487a1e1a-b0e0-4bf4-8756-16859094d708/element 500 4163.356 ms - 179
info: --> POST /wd/hub/session/487a1e1a-b0e0-4bf4-8756-16859094d708/timeouts/implicit_wait {“ms”:1000}

Hey there. I briefly saw that you had some find element by name statements in there. That is deprecated now. There are some good post on here around alternatives to find element by name

Good luck!

This isn’t the issue,it happens also in find by xpath and by ios ui automation.
What happens is that i get an answer from instruments that looks something like:
info: [debug] Got result from instruments: {“status”:0,“value”:{“UIAApplication”:{"@":{“name”:“rTest”,“label”:“rTest”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0",“x”:0,“y”:20,“width”:414,“height”:716},">":[{“UIAWindow”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true
info: [debug] Responding to client with success: {“status”:0,“value”:“Successfully launched the app.”,“sessionId”:“d8da4371-b8c5-4e53-b8d9-283cb1cc0cfc”}
info: <-- POST /wd/hub/session/d8da4371-b8c5-4e53-b8d9-283cb1cc0cfc/appium/app/launch 200 7454.177 ms - 104 {“status”:0,“value”:“Successfully launched the app.”,“sessionId”:“d8da4371-b8c5-4e53-b8d9-283cb1cc0cfc”}

When all values are null .When this happens every “find” method i try to use returns null/false answer from instruments…

I added the appium server logs:

info: [debug] Sending command to instruments: au.getElementsByName(‘Custom menu.’)
info: [debug] [INST] 2015-03-08 13:50:58 +0000 Debug: Got new command 54 from instruments: au.getElementsByName(‘Custom menu.’)
info: [debug] [INST] 2015-03-08 13:50:58 +0000 Debug: evaluating au.getElementsByName(‘Custom menu.’)
info: [debug] [INST] 2015-03-08 13:50:59 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-03-08 13:50:59 +0000 Debug: Lookup returned [object UIAButton] with the name “Custom menu.” (id: 30).
info: [debug] [INST] 2015-03-08 13:50:59 +0000 Debug: responding with:
info: [debug] [INST] 2015-03-08 13:50:59 +0000 Debug: Running system command #55: /usr/local/bin/node /Users/hannuchka/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:[{“ELEMENT”:“30”}]}…
info: [debug] Socket data received (41 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {“status”:0,“value”:[{“ELEMENT”:“30”}]}
info: [debug] Responding to client with success: {“status”:0,“value”:[{“ELEMENT”:“30”}],“sessionId”:“ccd2e94c-4b42-4f4f-9ae6-12787629ffb2”}
info: <-- POST /wd/hub/session/ccd2e94c-4b42-4f4f-9ae6-12787629ffb2/elements 200 1986.717 ms - 90 {“status”:0,“value”:[{“ELEMENT”:“30”}],“sessionId”:“ccd2e94c-4b42-4f4f-9ae6-12787629ffb2”}
info: --> POST /wd/hub/session/ccd2e94c-4b42-4f4f-9ae6-12787629ffb2/timeouts/implicit_wait {“ms”:1000}
info: [debug] Set iOS implicit wait to 1000ms
info: [debug] Responding to client with success: {“status”:0,“value”:null,“sessionId”:“ccd2e94c-4b42-4f4f-9ae6-12787629ffb2”}

What can cause the null/ [] values ?
Is it an instruments or the app’s fault?
In all this cases i can see the objects on the screen (available and clickable)

Hi Ag,
Have you tried using arc to find elements? (http://appium.io/slate/en/tutorial/ios.html?java#appium-ruby-console)
arc is really useful in showing which elements Appium can see.
Good luck!
eric

I didn’t mention it earlier but i am using java.The problem is that sometimes i can see these elements in the inspector and sometimes i can’t.Is there some order to the way appium finds the objects? usually the problem is with objects located in the tabBar

Not sure since i’m not really in the java world. it’s possible it may be a timing or visibility issue.

You can use explicit waits and change the timeout. example below
Not sure after that.
good luck!

wait = Selenium::WebDriver::Wait.new :timeout => 10
wait.until { find_element(:id, ‘Stream’).displayed? }

partially solved my issue (works for iOS 7 ,still problematic in iOS 8)

setting the device’s UDID as a server argument (in command line )instead of desired capability set in the code helped to identify all objects (regardless of appium version)