Broswer Xpath not working with ios using appium

I am stuck in the situation where my browser xpath is working for browser and android device with x path.
I have used hybrid app to automate the test case with android. I am able to run the test case with x path on android device with same x path i used for browser.
Ex: I have used “//*[@id=‘dialog-btn’]” this xpath to find button in browser and Android app.
For android i am able to find this x path by switching the context to web-view.

But when same thing i tried with ios using appium it is not working.When tried to inspect element it is showing different x path in appium inspector.



For iOS elements, they might not having id attribute. you can choose xpath as //*[@name=‘xyz’] or AccessibilityId (if it is having name attribute, if not take absloute xpath).

Thanks & Regards,
Vijay Bhaskar.

Thanks for your reply.
But for me attribute is data-id not name.I have to create xpath using data-id attribute.I am trying t keep same xpath for all devices and browser

If that is in the case, you can use xpath by using OR condition.

e.g. //*[@id=‘dialog-btn’ or @data-id=‘xyz’]

I’m not sure whether this works for both the platforms. please have a try and let us know.!!

Vijay Bhaskar.

i looked in appium page source my data id or id attribute is not rendering:

            <UIAButton name="Add" label="Back" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/2" x="12.500033155089227" y="-11.499999453607614" width="21.000000917939246" height="21.000000917939172">

I am not sure how to render those attributes here to find with xpath.Please suggest

So, is it working for Android?

I’m assuming for the same element on iOS we’ve the above UIAButton tag in xml.

For the combination :: //*[@id=‘dialog-btn’ or @name=‘Add’] should fullfil your requirement.

Happy testing :slight_smile:

Yes it is working for android but not for ios.
With name it should be work that is fine but my requirement is use same xpath for all platforms.
//*[@id=‘dialog-btn’ is not working with appium because if we see pagesource ID attribute is not there.