模拟器进行自动化解锁

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")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@删库跑路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值