本文共 2702 字,大约阅读时间需要 9 分钟。
from appium import webdriverimport timeserver = 'http://127.0.0.1:4723/wd/hub'
desired_caps = {"deviceName": "d9d26a8f","platformVersion": "9","platformName": "Android","appPackage": "com.tencent.mm","appActivity": "com.tencent.mm.ui.LauncherUI","unicodeKeyboard": "True","resetKeyboard": "True","noReset": "True"}
b = webdriver.Remote(server, desired_caps)
1.android_uiautomator text定位
1.1uiautomator tex精确定位 ele = b.find_element_by_android_uiautomator(‘new UiSelector().text(“通讯录”)’) ele.click() 1.2uiautomator textContains模糊定位 ele = b.find_element_by_android_uiautomator(‘new UiSelector().textContains(“通讯”)’) ele.click() 1.3uiautomator textStartsWith文本开头定位 ele = b.find_element_by_android_uiautomator(‘new UiSelector().textStartsWith(“通讯”)’) ele.click() 1.4uiautomator textMatches正则表达式定位 ele = b.find_element_by_android_uiautomator(‘new UiSelector().textMatches(“通讯.”)’) ele.click()android_uiautomator resourceId定位,resourceIdMatches定位
ele1 = b.find_element_by_android_uiautomator(‘new UiSelector().resourceId(“com.tencent.mm:id/cn1”)’) ele1.click()android_uiautomator className
class属性一般不唯一,多半用在复数定位,className复数定位–find_elements ele_list = b.find_elements_by_android_uiautomator(‘new UiSelector().className(“android.widget.ImageView”)’) print(ele_list) ele_list[0].click()android_uiautomator多属性组合定位,一般组合用id,class,text这三个属性
id+class 属性组合 id_class = ‘resourceId(“com.tencent.mm:id/f8y”).className(“android.widget.ImageView”)’ b.find_element_by_android_uiautomator(id_class).click() id+text 属性组合 id_text = ‘resourceId(“com.tencent.mm:id/cns”).text(“通讯录”)’ b.find_element_by_android_uiautomator(id_text).click() android_uiautomator description定位 ele = b.find_element_by_android_uiautomator(‘new UiSelector().description(“更多功能按钮,已折叠”)’) ele.click() descriptionStartsWith b.find_element_by_android_uiautomator(‘new UiSelector().descriptionStartsWith(“更多功能”)’) descriptionMatches b.find_element_by_android_uiautomator(‘new UiSelector().descriptionMatches(".*折叠$")’).click()1.xpath定位
ele2 = b.find_element_by_xpath(’//*[@resource-id=“com.tencent.mm:id/bhn” and @text=“搜索”]’) ele2.click() ele2.send_keys(“缘来是你阿”) 2. id定位 ele3 = b.find_element_by_id(“com.tencent.mm:id/gbv”) ele3.click()b.find_element_by_accessibility_id(“更多功能按钮,已折叠”).click()
转载地址:http://atmji.baihongyu.com/