How to locate a web element id, name or xpath in mobile android or iOS app

Hi,
Currently i am working on mobile app automation using appium. Need help regarding to locate an element in mobile app. generally we do in browser by firebug or inspect element. So i need suggestion for locating a web element on app.i have learned something about Appium inspector but how to use this tool.

1 Like

Launch the app with Appium, start the Inspector and navigate through the element tree. It will give you the available info related to the elements (name, type, value, label, xpath) [some stuff like name, value … won’t be available all the time, but the xpath will always be there]

Android also provides tool called DumpViewHierarachy.
Its easy to use with Eclipse.

iOS
A few people have messaged me this week asking about accessing an element using the Accessibility ID. So I’ll post the help that I gave them. Now, I use a lot of helper methods so that my code looks nice to someone who isn’t familiar with it. I will show you three methods from a base class that all my tests inherit.

As for my environment, this was written in java, wd is my webdriver, and I am running my tests on iOS right now. Once a button is on screen, I find the web element by its accessibility label. To get that label, I go into my app on the ios simulator, turn on the Accessibility Inspector, and select the button I wish to “find”. The Inspector will tell you the Label, and that is the name you will use to find the web element.

public WebElement findButton(String buttonName){ return wd.findElement(By.name(buttonName)); }
public void findButtonAndClick(String buttonName){ findButton(buttonName).click(); }
public void findSubmitAndClick(){ findButtonAndClick(“Submit”); }

So the findButton is the function that actually finds and returns the web element by its name (Accessibility ID). The second allows me to find and click a button by just passing the name of the ID, and the third is just an example of a helper function that I use to make things look nice in my code :slight_smile: hope this helps. And “Submit” is just a submit button that I am trying to find in this example.

when i have launch Appium Inspector at that time i am not able see the complete app features on the screen just a black screen come out.could you please help me how to solve this issue currently i am trying with the Emulator.

how we can use DumpViewHierarachy with Eclipse and how we can find the webelement .

So, is the app not showing up at all when you try to launch it with Appium, but it runs fine on the XCode’s Simulator?
Have you tried deleting the app folder, building again and giving the new app folder path to appium?
Make sure that all those missing features are available when running the app after building, before trying to run it on appium.