环境:
系统:ios 10.13.6 (17G12034)
appium:1.14.0
xcode:10.1
iphone:iphone7 12.4
在尝试使用driver.tap([(a,b)],500)做点击操作报错(复制了一个别人的,自己的当时没有存,大致格式就是这样):
WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Unhandled endpoint: /session/9C347804-6FAD-44F7-8C25-0CE995D01EF0/wda/touch/perform -- http://localhost:8100/ with parameters {
wildcards = (
"session/9C347804-6FAD-44F7-8C25-0CE995D01EF0/wda/touch/perform"
);
}
搜索了一下是driver.tap()已经不兼容了
这边分享一下我这边测试有效的点击和滑动方法
1、相对坐标点击
def target_click(x1, y1):
'''
:param self:
:param x1: x1,y1为编写脚本时适用设备的实际坐标
:param y1:
:return:
'''
a1 = x1 / 374
b1 = y1 / 667
# 获取当前手机屏幕大小X,Y
X = driver.get_window_size()['width']
Y = driver.get_window_size()['height']
# 屏幕坐标乘以系数即为用户要点击位置的具体坐标
driver.execute_script("mobile: tap", {"x": a1 * X, "y": b1 * Y})
调用:
target_click(117,515)
2.1、滑动-控件左划
def geteleByPredicate(con):
'''
通过ByPredicate方式获得元素
:param con: condition
:return: 元素
'''
ele = driver.find_element_by_ios_predicate(con)
return ele
def toLeftSwipeByPredicate(con):
ele = geteleByPredicate(con)
driver.execute_script("mobile:swipe", {"direction": "left", 'element':ele , "duration": 1})
调用:
toLeftSwipeByPredicate("type == 'XCUIElementTypeStaticText' AND value CONTAINS 'xxxx'")
2.2、滑动-整个屏幕缓慢向下滑动2次(这个操作很迷)
driver.execute_script('mobile: scroll', {'direction': 'down'})
参考博客:https://blog.csdn.net/qq_35741999/article/details/88533812