import time
from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
des_cap = dict()
des_cap["platformName"] = "Android"
des_cap["platformVersion"] = "6.0.1"
des_cap["deviceName"] = "127.0.0.1:7555"
des_cap["appPackage"] = "com.android.settings"
des_cap["appActivity"] = ".Settings"
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des_cap)
def get_element(driver,element):
wait = WebDriverWait(driver,10,1)
element = wait.until(lambda x:x.find_element(element[0],element[1]))
return element
def execute_swipe(driver,fx,count=1):
w = driver.get_window_size()['width']
h = driver.get_window_size()['height']
if fx=="top":
zb = (w/2, h*0.9, w/2 , h*0.1)
elif fx == "down":
zb = (w / 2, h * 0.1, w / 2, h * 0.9)
elif fx == "left":
zb = (w *0.9, h /2, w *0.1, h /2)
elif fx == "right":
zb = (w *0.1, h /2, w *0.9, h /2)
for i in range(count):
driver.swipe(*zb,duration=1200)
time.sleep(1)
execute_swipe(driver,'top',count=3)
toast_btn = By.XPATH,"//*[contains(@text,'开发者选项')]"
driver.find_element(*toast_btn).click()
time.sleep(2)
t1 = By.XPATH,"//*[contains(@text,'关闭')]"
driver.find_element(*t1).click()
|