appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.19k stars 753 forks source link

AndroidFindBy View Tag Support #1269

Open iChip opened 4 years ago

iChip commented 4 years ago

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']"

iChip commented 4 years ago

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

jayandran-Sampath commented 4 years ago

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

iChip commented 4 years ago

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: https://github.com/appium/java-client/pull/1271#discussion_r356983682

vaishaliidnani commented 4 years ago

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

VivekShahare04 commented 1 month ago

@iChip @dpgraham try to Create a custom annotation:

just like

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.TYPE})
public @interface AndroidFindByViewTag {
    String value();
}