appium 版本 1.7.1,python 环境,使用的 appiumlibrary 库,版本如下:

页面上的元素 “关闭易信首页提示” 在 automator viewer 里面能找到,且在 android5.0 的手机上控件能正常识别

但是在 android7.0、android8.0 的手机上,不管使用 ID 还是 name 定位的方式都找不到。appium 的 log 如下:
[info] [HTTP] <-- POST /wd/hub/session/3623631a-ebf6-4fe2-b4fe-661a9f263b45/element/16/click 200 135 ms - 76
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":true}[info] [HTTP] --> POST /wd/hub/session/3623631a-ebf6-4fe2-b4fe-661a9f263b45/elements {"using":"id","sessionId":"3623631a-ebf6-4fe2-b4fe-661a9f263b45","value":"im.yixin:id/btn_agenda_un_track"}
[debug] [MJSONWP] Calling AppiumDriver.findElements() with args: ["id","im.yixin:id/btn_agenda_un_track","3623631a-ebf6-4fe2-b4fe-661a9f263b45"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator, name
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"im.yixin:id/btn_agenda_un_track","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"im.yixin:id/btn_agenda_un_track","context":"","multiple":true}}
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'im.yixin:id/btn_agenda_un_track' using 'ID' with the contextId: '' multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=im.yixin:id/btn_agenda_un_track]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=im.yixin:id/btn_agenda_un_track]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=im.yixin:id/btn_agenda_un_track][debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying.
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'im.yixin:id/btn_agenda_un_track' using 'ID' with the contextId: '' multiple: true
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[RESOURCE_ID=im.yixin:id/btn_agenda_un_track]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements selector:UiSelector[RESOURCE_ID=im.yixin:id/btn_agenda_un_track]
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Element[] is null: (0)
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] getElements tmp selector:UiSelector[INSTANCE=0, RESOURCE_ID=im.yixin:id/btn_agenda_un_track][debug] [AndroidBootstrap] Received command result from bootstrap
[debug] [MJSONWP] Responding to client with driver.findElements() result: []
[info] [HTTP] <-- POST /wd/hub/session/3623631a-ebf6-4fe2-b4fe-661a9f263b45/elements 200 9047 ms - 74
[debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":[]}
这个页面的其他元素,在 android7.0、8.0 上能正常识别,只有这个元素,
看了下 appiumlibrary 中 click_element 这个方法,写的是:

def click_element(self, locator):
        """Click element identified by `locator`.

        Key attributes for arbitrary elements are `index` and `name`. See
        `introduction` for details about locating elements.
        """
        self._info("Clicking element '%s'." % locator)
        self._element_find(locator, True, True).click()

求各位指点指点


↙↙↙阅读原文可查看相关链接,并与作者交流