from appium import webdriver
from selenium.common.exceptions import NoSuchElementException
caps = {
"platformVersion": "5.1.1",
"deviceName": "127.0.0.1:62028",
"appPackage": "com.android.settings",
"appActivity": ".Settings",
"platformName": "android"
}
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
size = driver.get_window_size()
width = size['width']
height = size['height']
x1 = x2 = width*0.5
y1, y2 = height*0.9, height*0.7
def try_find( driver, by, value):
try:
return driver.find_element(by,value)
except NoSuchElementException:
print("未找到元素")
for i in range (10):
elm = try_find(driver, 'xpath', '//*[@text="关于平板电脑"]')
if elm is not None:
print("找到元素")
elm.click()
break
driver.swipe(x1,y1,x2,y2)
driver.quit()