iOS - Wrong Button Getting Clicked

Hello -

I’ve lost a few days on this one. I haven’t seen anything written anywhere about this. I’ll provide more information tomorrow but I’m curious… Has anyone else had an issue where every time appium tries to click the a button on a page (the same code, and the same button), it clicks a different button instead? I cannot get past a certain test because every time it gets to this one screen appium random clicks another button instead of the one I want. The code hasn’t changed and my script hasn’t changed.

Like I said I’ll do more digging tomorrow and provide details just curious if anyone else has had this issue and before spending too much more time on it.

So I’ve done more digging and if I’m understanding the logs correctly I think I see what is happening.

When Appium receives the elements from the device it’s getting different xpaths each time.

Notice these two logs. One shows it pushing the command to xPath(’/0/0/13’) and the other (’/0/0/9’). One of these actually clicked the button I wanted and one didn’t.

Wrong Button clicked
{“status”:0,“value”:{“UIAApplication”:{"@":{“name”:“Xxxxxx”,“label”:“Xxxxxx”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0",“x”:0,“y”:0,“width”:320,“height”:568},">":[{“UIAWindow”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,
info: [debug] Pushing command to appium work queue: “au.getElementByIndexPath(’/0/0/9’)”

Correct Button clicked
{“status”:0,“value”:{“UIAApplication”:{"@":{“name”:“Xxxxxx”,“label”:“Xxxxxx”,“value”:null,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0",“x”:0,“y”:0,“width”:320,“height”:568},">":[{“UIAWindow”:{"@":{“name”:null,“label”:null,“value”:null,“dom”:null,“enabled”:true,
info: [debug] Pushing command to appium work queue: “au.getElementByIndexPath(’/0/0/13’)”

It’s even more clear here when it’s receiving the elements. This field is labeled and you see the paths are different on two different executions of the test script.

Execution 1
[]}},{“UIASearchBar”:{"@":{“name”:“Where would you like to eat? “,“label”:“Where would you like to eat? “,“value”:“Where would you like to eat?”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:”/0/0/11”,“x”:9,“y”:72,“width”:264,“height”:28},”>”:[]}},

Execution 2
[]}},{“UIASearchBar”:{"@":{“name”:“Where would you like to eat? “,“label”:“Where would you like to eat? “,“value”:“Where would you like to eat?”,”dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:”/0/0/16”,“x”:9,“y”:72,“width”:264,“height”:28},”>”:[]}},

I don’t see this type of behavior when getting elements on other screens where I don’t have this issue.

Execution 1
{“UIAStaticText”:{"@":{“name”:“and enter your phone number”,“label”:“and enter your phone number”,“value”:“and enter your phone number”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/1/1",“x”:70,“y”:92,“width”:181,“height”:21},">":[]}},{“UIAButton”:

Execution 2
{“UIAStaticText”:{"@":{“name”:“and enter your phone number”,“label”:“and enter your phone number”,“value”:“and enter your phone number”,“dom”:null,“enabled”:true,“valid”:true,“visible”:true,“hint”:null,“path”:"/0/0/1/1",“x”:70,“y”:92,“width”:181,“height”:21},">":[]}},{“UIAButton”:

A little bit about this screen… This screen has a search bar at the top and a map (google api) below where the users can search for locations. Is there something about this type of screen that I need to interact with it differently?

Thanks!
Matt

You’ve done a good job describing the problem. Can I ask if this could be a timing issue? Could the rendering of your map take more or less time depending on factors outside your app (like slow network, data connection, server side issue, etc)? I usually recommend doing an explicit wait, but in this case it seems like the wait would return immediately with the wrong button. Maybe an implicit wait, like a sleep for 2 seconds would stabilize this?

Thank you wreed.

I tried adding a wait until a specific element loaded in the map’s default search results thinking that by that time all elements on the page should be present but that did not seem to work. I will try your recommendation for an implicit wait and let you know if that works.

Thanks again!

There’s some different timing issues to be aware of:

  • Your element is not yet available on the page.
  • The entire page has not yet fully loaded, which can potentially change your target element’s IndexPath right before the click is physically invoked.

How I’ve attempted to handle this is to write functions for each of my pages that specifically waits for a specific list / set of elements to be available before any further code is executed. So, instead of just waiting for one single element I’m waiting for a bunch. Purely an effort to ensure my page has fully loaded before proceeding.

With all of that said, back in 1.4.16 I would still encounter a couple issues like you mentioned where it would click on the wrong UIATableCell I never figured out what the specific root cause was as the page it would typically fail on was not dynamic. Ohhhhh, now that I’m typing this all up there are some document counts that render in the right margin of each table cell, perhaps I’m not waiting for those to load and that’s throwing off my IndexPath sometimes? Gives me something to investigate. Sometimes talking (typing) it out really helps. Thanks! :slight_smile: