?一般方法是通过不同的属性来定位元素的:
通过xpath\class\resourceid\text\index:
from appiumimport webdriver
import time
desired_cap = {
# 什么平台
"platformName":"Android",
# 平台版本
"platformVersion":"7.1.2",
"deviceName":"SM-G9810",
# 包名
"appPackage":"com.tencent.mobileqq",
# 启动页面
"appActivity":"com.tencent.mobileqq.activity.LoginActivity",
# 不清理缓存
"noReset":True,
#
"automationName":"Uiautomator2",
"newCommandTimeout":"6000",
# 设置中文的输入
"unicodeKeyboard":True,
"resetKeyboard":True
}
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_cap)
driver.implicitly_wait(5)
#1通过resourceid来定位元素
el1 = driver.find_element('id', 'android:id/title)
#2通过find_element_by_accessibility_id('description属性内容')来定位元素
el2 = driver.find_element_by_accessibility_id('密码 安全')el2.click()
#3通过xpath来定位元素
el3 = driver.find_element('xpath', '//*[@resource-id="com.tencent.mobileqq:id/password"]').click()
?
|