An element (Android COMPOSE) could not be located on the page using the given search parameters

Hi,

I’m redoing the tests in the application that previously used XML to create screen objects.
Jetpack compose has been implemented. As a result, screen objects are no longer identified as before by the appium inspector.

To display the ID of the screen objects again, assign the testTag property to the semantics, like this:
Modifier.semantics {testTag = “tagFab” testTagsAsResourceId = true}

With that, the FAB (floating action button) assumed the ID that was passed in the tag (tagFab).

However, when I trigger the FAB through the name I assigned to the testTag, it is not identified. I’m looking for the FAB through findElement(By.id()).

I’ve implemented these two ways:
appiumDriver!!.findElements(By.id("br.com.myapp:id/tagFab"))
or
appiumDriver!!.findElements(By.id("tagFab"))

However, both options always return the same message:
org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

What is the problem or what am I doing wrong so that the object is not being identified? Thank you in advance for your attention.

Full disclosure: I don’t use JetPack compose.

However, I found this article detailing some changes to Appium Espresso driver to help with JetPack compose automation informative. Maybe it will help you:

https://medium.com/bumble-tech/automating-android-jetpack-compose-using-appium-edb760fe79b9

Hello, my dear.

So I’ve seen this example before. But it only talks about configuring the appium driver for compose. Thing I already did. Even so, it still does not identify the object on the screen.

Thank you for your attention.

Hi, i had the same problem, you have to use UiSelector : driver.findElement(AppiumBy.androidUIAutomator(“new UiSelector().resourceId(“fab”)”)).click();

1 Like

Hi, Giuma. Thanks for your response.

I implemented your suggestion, but that didn’t work either.

This my implementation:
appiumDriver!!.findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"br.com.myapp:id/fab\")")).click()

A small difference from your code is in the quotes and slash it was needed by.

Still not found the element fab.

Hi, wilkegutierre …yes in my code there are slashes but I don’t know why they are not seen.
driver.findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"your resource-id\")")).click();
my driver is not AppiumDriver but AndroidDriver and you have to write only your id no the package.

1 Like

on your screenshot element does not have package name in id. remove it and try again exactly as @Giuma suggested

1 Like

Hi Aleksei.
Thank you for your attention, my dear.

I forgot to mention in the Giuma answer post that I implemented it with and without a package name. In the code you can see that it is with the package name, but I also tried without. As well, I was using AppiumDriver and not AndroidDriver. I’ll try without the package name and with the AndroidDriver.

Hi, Giuma.

I already tried it without the package name and it didn’t find the element. However, I was using AppiumDriver. I’ll try with the AndroidDriver and without the package name like you said.

Thanks.

I hope it works, in case it still doesn’t , are you sure that id is in the right component? if you need to get the plus button id you need to get the resouce-id of the android.widget.button class in your screenshot i see the wrong class id.

Oh yeah.
In the image it is off, below the drawerMenu.

The AppiumDriver is used in the project. I’ll give it a try by switching to AndrodiDriver.

Add more details what does not work. Element not found. Tap did but nothing happens. Enable in debug mode to show on phone where touch happens. Possibly ypu have same element in another place…

1 Like

try following this with the help of your dev team:

1 Like

Hey guys!
I went back! And I came back to first thank all of you who collaborated with my question. And especially, thanks to @Giuma for showing me 60% of the problem I was having in identifying the compose element of the app screen.

In addition to not using the correct way to identify the element on the screen, I wasn’t passing the testTagsAsResourceId property at the top level of compose’s semantic tree. As shown in this post:
https://juliensalvi.medium.com/ui-tests-with-jetpack-compose-and-appium-x-uiautomator-5d276fb655aa

In short: what I had to do was inform the testTagsAsResourceId property at the top of the composible elements tree and fetch the screen element through this way:

appiumDriver!!.findElement(AppiumBy.androidUIAutomator("new UiSelector().resourceId(\"fab\")")).click()

P.S.: I used AppiumDriver instead of AndroidDriver, as indicated by @Giuma .

Thank you very much!

1 Like