查找元素: find_element/find_elements
一、定位文字text
# 全部text文字
driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().text("xxx")')
# 包含text文字
driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textContains("xxx")')
# 以text什么开始
driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textStartsWith("xxx")')
# 正则匹配text
driver.find_element(MobileBy.ANDROID_UIAUTOMATOR, 'new UiSelector().textMatches("^xxx.*")')
二、定位id
driver.find_element(MobileBy.ID, 'xxx')
三、定位Classnam
driver.find_element(MobileBy.CLASS_NAME, 'xxx')
四、定位ACCESSIBILITY_ID
driver.find_element(MobileBy.ACCESSIBILITY_ID, 'xxx')
五、定位文字Xpath
driver.find_element(MobileBy.XPATH, 'xxx')
?六、定位文字CSS_SELECTOR
driver.find_element(MobileBy.CSS_SELECTOR, 'xxx')
?七、元素操作
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.extensions.android.nativekey import AndroidKey
params = {
'platformName': '',
'platformVersion': '',
'deviceName': '',
'appPackage': '',
'appActivity': '',
'resetKeyboard': '',
'noReset': '',
'newCommandTimeout': 6000,
'automationName': ''
}
driver = webdriver.Remote(r'http://localhost:4723/wd/hub', params)
target = driver.find_element(MobileBy.id, 'xxx')
# 点击
target.click()
# 输入文本
target.send_keys('xxx')
# 等待
driver.implicitly_wait(5)
# 回车
driver.press_keycode(AndroidKey.ENTER)
|