Unable to find element using xpath, ID, name on android application

Hi All,

I’am setup automation testing on Mobile using Appium and I got the issue regarding to find element on Android apps.
I couldn’t find element using xpath, id, name but it’s work with classname. Here is my application

My’s code:

es = driver.findElements(By.className(“android.widget.Button”));
System.out.println("size " + es.size());// return 56

es2 = driver.findElements(By.id(“com.android2.calculator3:id/digit_7”));//return 0
System.out.println("size " + es2.size());// return 0

es2 = driver.findElements(By.xpath("//android.widget.Button[@bounds=’[32,754][179,863]’]"));
System.out.println("size " + es2.size());// return 0

I was trying with many Appium version (latest version, older version) and many Android version

Please help me to support above issue and let me know the root cause or your solution.

Many thanks,
Xuyen Tran

Hi Xuyen,

It’s so strange. Please try to add a hard wait time by using Thread.sleep(3000) before interacting on the element (just for troubleshooting) and update the result.

And please give a try with driver.findElement(By.xpath("//*[@text=‘7’]")).click();

I was set sleep 50s after load apps.

It throws exception as below:
NoSuchElementException: An element could not be located on the page using the given search parameters.

I was try with many ways but I don’t know what happen in this case.

Ah, the root cause is: findElements
pls change to [findElement]

(findElements) is used to find out List of element.

System.out.println("size " + es2.size());// return 0
I want to check how many element found by this…it’s return 0 or more one.
The root cause is not by suing findElements or findElement.

Anyway, I was try with findElement but the same error occur.

Thx, Tu

I think it should be [com.android.calculator2:id/digit_7]

Sorry I was just daydreaming when thinking you’re trying to get element size!

The same issue, it’s aleay return to 0…
Here is my skype langtushtp.I will provide my code and apps.

Xuyen Tran

next try:
es2 = driver.findElements(MobileBy.id(“digit_7”));

1 Like

Thanks Aleksei very much!

It’s work for me. But I need to investigate about MobileBy.

Thanks again,
Xuyen Tran

Aleksei, google search about MobileBy but I got a little about this.
Can you share some document about this and what are difference between MobileBy and By?

Thanks in advanced,
Xuyen Tran

I don’t know if the typo was in your code or when you pasted here, but you have calculator3, and your image shows calculator2. if you fix that, it should work. This would be my desired method.

You can also try finding by name (built for iOS, but in Android, it searches for both description and text).

The issue is fixed by Aleksei’s solution.

Xuyen Tran