Skip to content

AndroidFindBy View Tag Support #1269

Open

Description

@iChip

I'd like to use the @AndroidFindBy annotation for finding elements by view tag on Android, I am specifying a test ID through this attribute as we cannot use resource ids for targeting views when using React Native.

It does not seem like @AndroidFindBy currently supports this. I see MobileBy.ByAndroidViewTag, but I believe this cannot be used with the page object model to initially locate elements.

Is the only workaround an xpath selector (which I believe requires knowing the tag name in advance in addition to the view tag)?
e.g. driver.findElementByXPath("//android.widget.TextView[@view-tag='some-tag']"

Activity

  1. iChip commented on Nov 20, 2019

    @iChip
    Author

    Tagging @dpgraham since he's my guy on the inside + appears to have some context

  2. jayandran-Sampath commented on Nov 28, 2019

    @jayandran-Sampath
    Contributor

    @iChip : As per current implementation, AndroidFindBy(tagName="some-tag") itself will work. Just give a try and let us know.

  3. iChip commented on Dec 12, 2019

    @iChip
    Author

    Thanks, It does work, but I am confused by the naming. Your solution seems more sensible, the existing tagName annotation does not seem to correctly describe this locator strategy.

    I added some comments on your closed PR:
    #1271 (comment)

  4. vaishaliidnani commented on Dec 18, 2019

    @vaishaliidnani

    is this project run in Android because i m not able to run this please give the link

  5. VivekShahare04 commented on Jul 10, 2024

    @VivekShahare04

    @iChip @dpgraham try to Create a custom annotation:

    just like

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.FIELD, ElementType.TYPE})
    public @interface AndroidFindByViewTag {
        String value();
    }
    
  6. ranjeetksingh55 commented on Jun 19, 2025

    @ranjeetksingh55

    Hi @iChip,

    In React Native apps where resource-id isn’t available, we often rely on view-tag (mapped from testID). While MobileBy.AndroidViewTag("some-tag") works, it’s not usable with @AndroidFindBy, limiting Page Object Model usage.

    Currently, the workaround is using XPath like:
    @AndroidFindBy(xpath = "//android.widget.TextView[@view-tag='some-tag']") But this requires knowing the class name, making it fragile.

    Support for something like @AndroidFindBy(viewTag = "some-tag") would be a clean solution.
    Happy to contribute if this is feasible!

    Thanks 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions