from appium.webdriver.common.touch_action import TouchAction
from appium import webdriver
import time
desired_caps = {} #配置参数的字典
desired_caps['platformName'] = 'Android' #平台名称,iOS、Android、 FirefoxOS,选择真机/模拟器对应的就好
desired_caps['platformVersion'] = '5.1.1' #平台版本
desired_caps['deviceName'] = '真机' #设备名称填写任意内容(使用的移动设备或模拟器的种类)
# desired_caps['appPackage'] = 'com.dyhoa.school' #要运行的Android应用程序的Java包
# desired_caps['appActivity'] = '.LauncherNewActivity' #要运行的Android应用程序的主入口
desired_caps['appPackage'] = 'com.android.settings' #要运行的Android应用程序的Java包
desired_caps['appActivity'] = '.Settings' #要运行的Android应用程序的主入口
# desired_caps['udid'] = '8c9abb78' #连接的物理设备的唯一设备标识符,可通过adb devices查看(非必选)
desired_caps['unicodeKeyboard'] = True #设置启动编码
# desired_caps['resetKeyboard'] = False #重置键盘
desired_caps['noReset'] = 'True' #默认为False,当设置为true时不作为首次进入(在此会话之前,请勿重置应用程序状态)
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desired_caps)
print("start")
end = driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
start = driver.find_element_by_xpath("//*[contains(@text,'存储')]")
driver.drag_and_drop(start,end) #上下滑动
TouchAction(driver).tap(driver.find_element_by_xpath("//*[contains(@text,'安全')]")).perform()
TouchAction(driver).tap(driver.find_element_by_xpath("//*[contains(@text,'屏幕锁定方式')]")).perform()
edit = driver.find_element_by_id("com.android.settings:id/password_entry")
edit.send_keys("123456")
time.sleep(1)
TouchAction(driver).tap(driver.find_element_by_xpath("//*[contains(@text,'下一步')]")).perform()
time.sleep(1)
TouchAction(driver).tap(driver.find_element_by_xpath("//*[contains(@text,'图案')]")).perform()
time.sleep(2)
TouchAction(driver).press(x=177,y=640).wait(1000)\
.move_to(x=0,y=360).wait(1000)\
.move_to(x=0,y=356).wait(1000)\
.move_to(x=358,y=0).wait(1000)\
.move_to(x=365,y=0).release().wait(100).perform()
# 这里遇到的问题,下面注释的是按照正常的xy点执行,然后报错,原因是因为超出最大范围(
提供给交互操作的坐标无效。
):
The coordinates provided to an interactions operation are invalid.
上面的是正常可以运行的,修改是把当前xy点的实际值减去上一条xy点(第一条除外)。
这是appium的报错信息:
报错结果:
# TouchAction(driver).press(x=177,y=640).wait(1000)\
# .move_to(x=177,y=1000).wait(1000)\
# .move_to(x=177,y=1356).wait(1000)\
# .move_to(x=535,y=1360).wait(1000)\
# .move_to(x=900,y=1360).release().perform()
print("end")