Skip to content

getByRole is not working for some cases #107

@krishhna123

Description

@krishhna123

Mobilewright version

0.0.33

Operating system

macOS 26.4.1

Target platform

Android

Device or simulator

Pixel 10 Pro XL (emulator)

Minimal reproduction

 <node index="6" text="Let's  Shop"
             resource-id="com.androidsample.generalstore:id/btnLetsShop"
             class="android.widget.Button"
             package="com.androidsample.generalstore" content-desc=""
             checkable="false" checked="false" clickable="true"
             enabled="true" focusable="true" focused="false"
             scrollable="false" long-clickable="false"
             password="false" selected="false"
             bounds="[162,1709][1182,1844]" drawing-order="7" hint="" />
 </node>

I have an .apk file having above UI hierarchy xml

Now I am trying to access the element using

await screen.getByRole('button', { name : "Let's Shop" }).tap();

but it wasn't possible but accessible element is possible with

await screen.getByText("Let's Shop").tap();

Actual behavior

Getting below error:

LocatorError: Locator: no matching element found after 5000ms

   8 |   await screen.getByText('Enter name here').fill('tester')
   9 |   await screen.getByText('Female').tap();
> 10 |   await screen.getByRole('button', {name : "Let's  Shop"}).tap();
     |   ^
  11 | });
  12 |

Expected behavior

Element should be accessible with getByRole

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions