Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Unexpected Selector Translation with @AndroidFindBy and AppiumFieldDecorator

未关闭
#2,051 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 5 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
android, java
领域
mobile, testing

调研方向

首先,跟踪 AppiumFieldDecorator 通过 PageFactory.initElements 处理 @AndroidFindBy(accessibility = "open menu") 与 EventFiringWebDriver 一起工作时的调用路径。将该路径与正常工作的 AppiumBy.accessibilityId("open menu") 查找以及关联的错误日志进行比较。当注解路径使用受支持的 accessibility 查找,并且提供的复现能够成功且不出现不受支持的 CSS 选择器错误时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Description

I've encountered an unexpected behavior when using @AndroidFindBy annotation in conjunction with PageFactory.initElements(new AppiumFieldDecorator(eventDriver, Duration.ofSeconds(30)), this);.

Environment

  • Java client build version or git revision if you use some snapshot: 9.0.0.
  • Appium server version or git revision if you use some snapshot: 2.1.3
  • Desktop OS/version used to run Appium if necessary: Windows 10
  • Node.js version : v18.18.0
  • Mobile platform/version under test: Android 13
  • Real device or emulator/simulator: Real Device

Details

When using the annotation @AndroidFindBy(accessibility = "open menu") for an element, I'm encountering an error stating:

Unsupported CSS selector '*[name='webElementOpenMenu']'. Reason: ''name' is not a valid attribute. Supported attributes are 'checkable, checked, clickable, enabled, focusable, focused, long-clickable, scrollable, selected, index, instance, description, resource-id, text, class-name, package-name''

However, using the direct method appiumDriver.findElementByAccessibilityId("open menu").click(); works without any issues.

It appears that the accessibility attribute from the annotation is being incorrectly translated into a CSS selector with the name attribute when using AppiumFieldDecorator with EventFiringWebDriver.

Code To Reproduce Issue [ Good To Have ]


 @AndroidFindBy(accessibility = "open menu")
    private WebElement webElementOpenMenu;

    @Test()
    public void demaoTest() {
        AppiumDriverLocalService appiumDriverLocalService = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
                .withIPAddress("127.0.0.1")
                .usingPort(4723)
                .withArgument(GeneralServerFlag.RELAXED_SECURITY)
                .withArgument(GeneralServerFlag.SESSION_OVERRIDE)
                .withArgument(GeneralServerFlag.USE_DRIVERS, "uiautomator2")
                .withArgument(GeneralServerFlag.BASEPATH, "/wd/hub/")
                .withArgument(GeneralServerFlag.LOG_LEVEL, "info:debug")
                .withTimeout(Duration.ofSeconds(180)));
        appiumDriverLocalService.start();

        UiAutomator2Options uiAutomator2Options = new UiAutomator2Options()
                .setAutomationName(AutomationName.ANDROID_UIAUTOMATOR2)
                .setApp(System.getProperty("user.dir" + File.separator + "app" + File.separator + "android" + File.separator + "Android-MyDemoAppRN.1.3.0.build-244.apk"))
                .setFullReset(false)
                .setNoReset(true)
                .setPlatformName("android")
                .setPlatformVersion("13")
                .setUdid("ZD222CJSXB")
                .setAppPackage("com.saucelabs.mydemoapp.rn")
                .setAppActivity("com.saucelabs.mydemoapp.rn.MainActivity");

        AppiumDriver appiumDriver = new AndroidDriver(appiumDriverLocalService.getUrl(), uiAutomator2Options);

        EventFiringWebDriver eventDriver = new EventFiringWebDriver(appiumDriver);
        CustomEventListener listener = new CustomEventListener();
        eventDriver.register(listener);

        //WebElement webElementOpenMenu_1 = eventDriver.findElement(AppiumBy.accessibilityId("open menu")); --- This is working

        PageFactory.initElements(new AppiumFieldDecorator(eventDriver, Duration.ofSeconds(30)), this);

        webElementOpenMenu.click();

//        webElementOpenMenu_1.click(); --- This is working
        
        appiumDriver.quit();
        appiumDriverLocalService.stop();
    }

Exception Stacktraces

Appium Error Log:
https://gist.github.com/dipakkumar1225/619b603dbd8f9383b442b76eab343bc5

Appium Working Log:
https://gist.github.com/dipakkumar1225/d7ecf952f56ddf8a93543ae87f5667d4#file-working-txt

主要语言
Java
星标
1.3k
派生
755
平均合并
5 天 14 小时
30 天内合并 PR
8

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

appium/java-client 的其他 Issue

查看 appium/java-client 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。