最好的学习方法,就是看源码!

在  \appium\webdriver\webdriver.py ,新增了两个封装好定位安卓元素的方法,如  find_element_by_accessibility_id 与 find_element_by_android_uiautomator

Appium 自动化测试(8) -- Appium Python client -- API

Appium 自动化测试(8) -- Appium Python client -- API

 

如下图,定位“一起玩”tab页:

Appium 自动化测试(8) -- Appium Python client -- API

一、根据UIAutomator定位元素

    def test_find_element(self):
        self.driver.wait_activity('com.yy.mobile.ui.home.MainActivity',30)
        # text 属性的方法
        el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("一起玩")')
        self.assertIsNotNone(el)
        e2 = self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("起玩")')
        self.assertIsNotNone(e2)
        e3 = self.driver.find_element_by_android_uiautomator('new UiSelector().textStartsWith("一起")')
        self.assertIsNotNone(e3)
        e4 = self.driver.find_element_by_android_uiautomator('new UiSelector().textMatches("^一起.*")')
        self.assertIsNotNone(e4)
        # class属性的方法
        e5 = self.driver.find_element_by_android_uiautomator('new UiSelector().className("android.widget.TextView").text("一起玩")')
        self.assertIsNotNone(e5)
        # resourceId属性的方法
        e6 = self.driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.yy.mobile.plugin.main:id/tab_tab_btn")')
        self.assertIsNotNone(e6)

二、根据accessibility_id定位

    def find_element_by_accessibility_id(self, id):
        """Finds an element by accessibility id.

        :Args:
         - id - a string corresponding to a recursive element search using the
         Id/Name that the native Accessibility options utilize

        :Usage:
            driver.find_element_by_accessibility_id()
        """
        return self.find_element(by=By.ACCESSIBILITY_ID, value=id)

对于 Android 就是 content-description

Appium 自动化测试(8) -- Appium Python client -- API

对于 iOS 就是 accessibility identifier

 三、看源码可知,Appium 中的Webdriver是Selenium中的webdirver.Remote的子类,所以更多的API,可是在Selenium中寻找

Appium 自动化测试(8) -- Appium Python client -- API

Appium 自动化测试(8) -- Appium Python client -- API

Appium 自动化测试(8) -- Appium Python client -- API

 

Appium 自动化测试(8) -- Appium Python client -- API
***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

相关文章:

  • 2022-12-23
  • 2021-11-13
  • 2018-06-28
  • 2021-10-05
  • 2021-11-28
  • 2021-07-15
  • 2021-11-25
  • 2021-12-31
猜你喜欢
  • 2021-08-04
  • 2021-07-25
  • 2022-12-23
  • 2021-11-16
  • 2021-08-25
相关资源
相似解决方案