首页 技术 正文
技术 2022年11月20日
0 收藏 352 点赞 3,245 浏览 4318 个字

在用appium-desktop-setup-1.6.2进行app手势密码设置时,发现move_to(x, y)相对偏移量的方法用不了,绘制的手势也是乱跑

新版appium绘制九宫格的一个注意点

还会抛一个错误

selenium.common.exceptions.InvalidCoordinatesException: Message: Coordinate [x=-210.0, y=210.0] is outside of element rect: [0,0][720,1280]

代码如下

from appium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom appium.webdriver.common.mobileby import MobileByfrom appium.webdriver.common.touch_action import TouchActionfrom time import sleep# 由你主动来告诉appium server,我要操作哪个设备上的哪个app# Desired Capabilites,键值对,键名都是已经定义好的# 操作对象的信息准备desired_caps={}# 使用的手机操作系统desired_caps["platformName"] = "Android"# 手机操作系统的版本desired_caps["platformVersion"]="5.1.1"# 使用的设备名字或模拟器的类型desired_caps["deviceName"]="Android Emulator"# app信息desired_caps["appPackage"]="com.xxzb.fenwoo"#进入的界面desired_caps["appActivity"] = ".activity.addition.WelcomeActivity"# 连接appium server,并告诉其要操作的对象driver=webdriver.Remote('http://127.0.0.1:4723/wd/hub',desired_caps)# 获取屏幕尺寸size=driver.get_window_size()for x in range(0,4):    # 向左滑动    driver.swipe(size["width"]*0.9,size["height"]*0.5,size["width"]*0.1,size["height"]*0.5,500)    # 向右滑动    # driver.swipe(size["width"]*0.1,size["height"]*0.5,size["width"]*0.9,size["height"]*0.5,500)    sleep(1)# 点击立即体验WebDriverWait(driver,20,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/btn_start")))driver.find_element_by_id("com.xxzb.fenwoo:id/btn_start").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/btn_login")))# 点击登录注册按钮driver.find_element_by_id("com.xxzb.fenwoo:id/btn_login").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/et_phone")))# 输入用户名driver.find_element_by_id("com.xxzb.fenwoo:id/et_phone").send_keys("XXXXXX")# 点击下一步driver.find_element_by_id("com.xxzb.fenwoo:id/btn_next_step").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/et_pwd")))# 输入密码driver.find_element_by_id("com.xxzb.fenwoo:id/et_pwd").send_keys("XXXXXX")# 点击确定按钮driver.find_element_by_id("com.xxzb.fenwoo:id/btn_next_step").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/btn_confirm")))# 马上设置driver.find_element_by_id("com.xxzb.fenwoo:id/btn_confirm").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/btn_gesturepwd_guide")))# 立即创建driver.find_element_by_id("com.xxzb.fenwoo:id/btn_gesturepwd_guide").click()# 等待WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/right_btn")))# 确定按钮driver.find_element_by_id("com.xxzb.fenwoo:id/right_btn").click()# 手势绘制页面ta=TouchAction(driver)# 获取九宫格的起点坐标和大小ele=driver.find_element_by_id("com.xxzb.fenwoo:id/gesturepwd_create_lockview")size=ele.size# 获取坐标start_point=ele.locationta.press(x=start_point["x"]+size["width"]*1/6,y=start_point["y"]+size["height"]*1/6).wait(200).\    move_to(x=size["width"]*2/6,y=0).wait(200).\    move_to(x=size["width"]*2/6,y=0).wait(200).\    move_to(x=-size["width"]*2/6,y=size["width"]*2/6).wait(200).\    move_to(x=0,y=size["width"]*2/6).wait(200).release().wait(200).perform()# 等待# WebDriverWait(driver,30,1).until(EC.visibility_of_element_located((MobileBy.ID,"com.xxzb.fenwoo:id/right_btn")))# 点击继续driver.find_element_by_id("com.xxzb.fenwoo:id/right_btn").click()

而且一个奇怪的现象是第一个圆圈的坐标点是(150, 379),相对偏移(210, 0)之后得到的坐标是(210, 640)

新版appium绘制九宫格的一个注意点

后来尝试着

ta.press(x=0, y=0).release().perfrom()

神奇的发现(0, 0)点竟然是(360, 640)这个位置

新版appium绘制九宫格的一个注意点

新版appium绘制九宫格的一个注意点

如果尝试press(x=0, y=10)得到的坐标点是(360, 10), press(x=10, y=0),得到的坐标点是(10, 640),只有当press(x=10, y=10)的时候得到的才是(10, 10),这样就可以解释上面x=210, y=0, 为什么是(210, 640)了。看来x或y不能为0,不然会跑偏

这个问题目前已经报bug,bug地址为:https://discuss.appium.io/t/set-gesture-password-and-show-pressed-coordinate-error-using-1-6-2-appium-desktop-on-android-simulator/22858

目前的解决办法是利用绝对坐标定位,修改的代码如下:

ta.press(x=start_point["x"]+size["width"]*1/6,y=start_point["y"]+size["height"]*1/6).wait(200).\    move_to(x=start_point["x"]+size["width"]*3/6, y=start_point["y"]+size["height"]*1/6).wait(200).\    move_to(x=start_point["x"]+size["width"]*5/6, y=start_point["y"]+size["height"]*1/6).wait(200).\    move_to(x=start_point["x"]+size["width"]*3/6, y=start_point["y"]+size["width"]*3/6).wait(200).\    move_to(x=start_point["x"]+size["width"]*3/6, y=start_point["y"]+size["width"]*5/6).wait(200).release().wait(200).perform()
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,853