iOS locating element using xpath and verifying in Appium Inspector

Hi folks,
I am trying to locate a button which is under UIATableCell and I have the following line of code listed below
AppiumWebElement btn1 = (AppiumWebElement)ad.FindElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIAScrollView[1]/UIATableView[1]/UIATableCell[1]/UIAButton[1]");

The issue I am facing is , btn1.Click is not clicking on the correct button all the times, At times it seems to click on a button which is not visible on the screen and an alert come up as a result of clicking on that button.

I have verified the xpath using appium inspector and its returns one unique match all the time but when running the script it is not the case.

Also, I am running the test on simulator…any suggestions to troubleshoot will be great.


would you mind sharing the XML where this button exists

XPath for a particular UI Element can change at run time, and that is why it is not consistent.

you better use other locator type.

UIAButton name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/10/5" x=“0” y=“153” width=“320” height=“50” />

========= this is the part which is being picked up on and offf

ummmm I tried to post the xml but it is not displaying on the board…anyway to attach the dump…