如何使用 appium webdriver 查找并单击或点击导航栏上的用户图标?

How to find and click or tap on user icon on navigation bar using appium webdriver?

我想使用 selenium webdriver 单击图片中显示的元素(中间带有 M 字母的紫色圆圈)。

元素位于导航栏上。我尝试使用 Appium Desktop 查找元素,但未成功。

我的代码执行所有操作,直到打开导航栏。

# Android environment
import unittest
from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
from appium.webdriver.common.touch_action import TouchAction
from time import sleep

class TESTZERO(unittest.TestCase):

    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '5.0'
        desired_caps['deviceName'] = 'JUST5 Blaster'
        desired_caps['appPackage'] = 'com.android.vending'
        desired_caps['appActivity'] = 'com.google.android.finsky.activities.MainActivity'
        self.driver = webdriver.Remote('http://localhost:5000/wd/hub', desired_caps)

    def test_accept(self):
        "Test Accept button"
        self.driver.implicitly_wait(20)
        element = self.driver.find_element_by_id('com.android.vending:id/positive_button')
        element.click()

        element = self.driver.find_element_by_id('com.android.vending:id/navigation_button')
        element.click()


if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TESTZERO)
    unittest.TextTestRunner(verbosity=2).run(suite)

知道如何找到并点击或点按此元素吗?

添加 desired_caps['automationName'] = 'UiAutomator2' 并尝试查找元素:

self.driver.find_element_by_id('com.android.vending:id/secondary_avatar_frame_right')

我强烈建议使用 appium-desktop 来检查元素: