Appium Appium 页面滑动的问题请教!

大磊哥 · 2017年03月06日 · 最后由 含泪若冰 回复于 2018年06月29日 · 1535 次阅读

向大神们请教,appium1.6.3 下 引导页的滑动没有效果,脚本和 log 如下,谢谢了🙏!

# 引导页滑屏处理
    def getSize():
        x = self.driver.get_window_size()['width']
        y = self.driver.get_window_size()['height']
        return (x, y)
    def swipLeft(t):
        l = getSize()
        x1 = int(l[0] * 0.75)
        y1 = int(l[1] * 0.5)
        x2 = int(l[0] * 0.05)
        self.driver.swipe(x1, y1, x2, y1, t)
    swipLeft(5000)
    sleep(3)
[HTTP] <-- GET /wd/hub/session/ac98620d-0167-4d9a-8a82-94a292bd8209/window/current/size 200 131 ms - 98 
[HTTP] --> GET /wd/hub/session/ac98620d-0167-4d9a-8a82-94a292bd8209/window/current/size {}
[debug] [MJSONWP] Calling AppiumDriver.getWindowSize() with args: ["current","ac98620d-0167-4d9a-8a82-94a292bd8209"]
[debug] [XCUITest] Executing command 'getWindowSize'
[debug] [JSONWP Proxy] Proxying [GET /window/current/size] to [GET http://localhost:8100/session/67E76085-E6BF-424A-93CD-598A62F81EAB/window/current/size] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\n  \"value\" : {\n    \"width\" : 375,\n    \"height\" : 667\n  },\n  \"sessionId\" : \"67E76085-E6BF-424A-93CD-598A62F81EAB\",\n  \"status\" : 0\n}"
[debug] [MJSONWP] Responding to client with driver.getWindowSize() result: {"width":375,"height":667}
[HTTP] <-- GET /wd/hub/session/ac98620d-0167-4d9a-8a82-94a292bd8209/window/current/size 200 130 ms - 98 
[HTTP] --> POST /wd/hub/session/ac98620d-0167-4d9a-8a82-94a292bd8209/touch/perform {"sessionId":"ac98620d-0167-4d9a-8a82-94a292bd8209","actions":[{"action":"press","options":{"y":333,"x":281}},{"action":"wait","options":{"ms":5000}},{"action":"moveTo","options":{"y":333,"x":18}},{"action":"release","options":{}}]}
[debug] [MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"y":333,"x":281}},{"action":"wait","options":{"ms":5000}},{"action":"moveTo","options":{"y":333,"x":18}},{"action":"release","options":{}}],"ac98620d-0167-4d9a-8a82-94a292bd8209"]
[debug] [XCUITest] Executing command 'performTouch'
[debug] [XCUITest] Received the following touch action: press-wait-moveTo-release
[debug] [JSONWP Proxy] Proxying [POST /uiaTarget/0/dragfromtoforduration] to [POST http://localhost:8100/session/67E76085-E6BF-424A-93CD-598A62F81EAB/uiaTarget/0/dragfromtoforduration] with body: {"fromX":281,"fromY":333,"toX":299,"toY":666,"duration":5}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{},"sessionId":"67E76085-E6BF-424A-93CD-598A62F81EAB","status":0}
[debug] [MJSONWP] Responding to client with driver.performTouch() result: {}
共收到 7 条回复 时间 点赞

log 看起来没有报错和异常,不过引导页面就是没有滑动效果。
请路过的大神帮忙看看什么情况🙏🙏!

匿名 #3 · 2017年03月06日
def get_window_size():
    '''
    获取屏幕大小
    :return: windowsize
    '''
    windowSize = driver.get_window_size()
    return windowSize

def swipe_left(t):
    '''
    swipe left
    向左滑动
    :return:
    '''
    windowsSize = get_window_size()
    width = windowsSize.get("width")
    height = windowsSize.get("height")
    driver.swipe(width*3/4, height/2, width*1/4, height/2, t)

swipe_left(5000)

换了你的脚本方法,log 看上去没什么异常,但是还是 app 没有动,是不是我前面少了什么条件

原因是移动的坐标的问题
调试了几次最终
self.driver.swipe(width * 3 / 4, 100, -4* width / 4, 100, t)
实现了引导页的滑动

刚学 appium,self.driver.get_window_size() 我使用这个方法感觉都没执行,x,y 的数据都没获取到

大磊哥 回复

我也尝试你这个代码了 报错说 超出边界
请问你这个代码 对配置有要求么? 谢谢解答

@lucia_gaga
个人觉得是 appium 的版本问题,在 appium1.4.16 上滑动是使用 [起始坐标 + 相对坐标] 实现,但是换到 appium1.8.1 就报越界的错误,几经周折发现又变成了 [起始坐标 + 绝对坐标] 的实现。感觉好奇怪啊,TouchAction(Swipe) 的实现应该跟代码库有关啊,跟 appium 的版本有什么关系?

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