Get Element By ID. How to get Resource ID?


I am trying to run a simply test just to click a button by ID. However, test fails. The problem is Resource ID value I think. I can’t get correct Resource ID, because uiautomatorviewer do not provide me such information, it just shows layouts. So I am taking ID from app web page by inspecting element. So my question would be, what is another possible way to get information about app Resource ID? My app is hybrid.

@LaurynasKac try with xpath

Xpath do not help. Here is my code:


Provide the full XML for the button in question. There’s likely some unique attribute you can key from such as @content-desc or @text which you can then use, including in your xpath such as.


If you’re not seeing any unique attribute you likely just need to drill down the tree further. You’re probably looking at some upper level container element and the actual button is a child element further down the tree.

Looks like you are testing on a webview. Just to make clear, webview ist he view in which u load an HTML page in Android.

In that case you need to change the context to webview before you call findBy method.


Check if view is webview -

            protected boolean isWebView() {
	boolean bWebView = false;
	try {
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
	List<WebElement> mList = android_driver
	if (mList.size() > 0) {
		System.out.println("Webview available");
		bWebView = true;
	} else {
		System.out.println("Webview NOT available");
		// android_driver.context("NATIVE_APP");

	return bWebView;

Then you can call - MobileBy.xpath("/html/body/div[5]/div/div/div[1]/div[1]/div[3]/div[1]/div[2]/div[3]/div[2]")

I tried just to find some elements, no more actions like click. It does work for me.