Appium 求一个 swipe 使用方法。python-appium 使用场景;

华玺 · 2017年09月21日 · 最后由 prettfool 回复于 2017年09月22日 · 1490 次阅读


我这里有报错。不知道怎么处理,求解;

共收到 4 条回复 时间 点赞

我用的这个~

获得机器屏幕大小 x,y

def getSize(self):
x = self.driver.get_window_size()['width']
y = self.driver.get_window_size()['height']
return (x, y)

向上滑动

def swipeUp(self, t):
l = self.getSize()
x1 = int(l[0] * 0.5) # x 坐标
y1 = int(l[1] * 0.75) # 起始 y 坐标
y2 = int(l[1] * 0.25) # 终点 y 坐标
self.driver.swipe(x1, y1, x1, y2, t)

向左滑动

def swipeLeft(self, t):
l = self.getSize()
x1 = int(l[0] * 0.75)
y1 = int(l[1] * 0.5)
x2 = int(l[0] * 0.25)
self.driver.swipe(x1, y1, x2, y1, t)

向右滑动

def swipeRight(self, t):
l = self.getSize()
x1 = int(l[0] * 0.25)
y1 = int(l[1] * 0.5)
x2 = int(l[0] * 0.75)
self.driver.swipe(x1, y1, x2, y1, t)

向下滑动

def swipeDown(self, t):
l = self.getSize()
x1 = int(l[0] * 0.5)
y1 = int(l[1] * 0.25)
y2 = int(l[1] * 0.75)
self.driver.swipe(x1, y1, x1, y2, t)

我已经暂时解决了。你说的这个方法。我这里报错。

华玺 回复

不知道是不是因为你改动的部分导致的,建议你直接把这些方法封装起来,然后导入使用。


你的这个没有定义 driver 对象,所以是 NoneType object,应该把 self 传进去,使用 self.driver.swipe

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册