无法在ios上自下而上滑动 - appium

时间:2016-06-19 08:15:01

标签: java selenium appium

我想在ios上设置wifi状态,为了做到这一点,我需要从控制中心的底部向上滑动。

    dimension = driverWrapper.getIosDriver().manage().window().getSize();
    int middleX = dimension.getWidth() / 2;
    int y = dimension.getHeight();
   driverWrapper.getIosDriver().swipe(middleX,y-10,middleX,150,600);

在我将java客户端升级到4.0.0并将appium升级到1.5.2之前,它正常工作。

我收到错误: 错误:VerboseError:point不在屏幕范围内

日志是:

[debug] [UIAuto] Socket data received (49 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"width":320,"height":568}}
[MJSONWP] Responding to client with driver.getWindowSize() result: {"width":320,"height":568}
[HTTP] <-- GET /wd/hub/session/31411e39-f408-418f-b9b8-e28b80ba1b35/window/current/size 200 1071 ms - 98 
[HTTP] --> POST /wd/hub/session/31411e39-f408-418f-b9b8-e28b80ba1b35/touch/perform {"actions":[{"action":"press","options":{"x":160,"y":558}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":160,"y":284}},{"action":"release","options":{}}]}
[MJSONWP] Calling AppiumDriver.performTouch() with args: [[{"action":"press","options":{"x":160,"y":558}},{"action":"wait","options":{"ms":100}},{"action":"moveTo","options":{"x":160,"y":284}},{"action":"...
[debug] [iOS] Executing iOS command 'performTouch'
[debug] [UIAuto] Sending command to instruments: target.touch([{"touch":[{"x":160,"y":558}],"time":0.2},{"touch":[{"x":160,"y":558}],"time":0.30000000000000004},{"touch":[{"x":320,"y":842}],"time":0.5}])

[debug] [Instruments] [INST] 2016-06-19 07:39:13 +0000 Debug: Got new command 6 from instruments: target.touch([{"touch":[{"x":160,"y":558}],"time":0.2},{"touch":[{"x":160,"y":558}],"time":0.30000000000000004},{"touch":[{"x":320,"y":842}],"time":0.5}])

[debug] [Instruments] [INST] 2016-06-19 07:39:13 +0000 Debug: evaluating target.touch([{"touch":[{"x":160,"y":558}],"time":0.2},{"touch":[{"x":160,"y":558}],"time":0.30000000000000004},{"touch":[{"x":320,"y":842}],"time":0.5}])

[debug] [Instruments] [INST] 2016-06-19 07:39:13 +0000 Debug: target.touch(__NSCFArray)

[debug] [Instruments] [INST] 2016-06-19 07:39:13 +0000 Debug: point is not within the bounds of the screen

知道发生了什么事吗?

由于

3 个答案:

答案 0 :(得分:2)

滑动方法标准(仅适用于IOS)以避免此错误

  1. 0&lt; startx + endx&lt;宽度

  2. 0&lt; starty + endy&lt;高度

  3. 务实的永久性解决方案

    为了简化我们的日常生活,请记下这样的功能

    public void swipeFinger(startx, starty, endx, endy, duration) {
       driver.swipe(startx, starty, startx - endx, starty - endy, duration);
    }
    

    RCA for Error:VerboseError:point不在屏幕范围内

    问题是对于IOS,driver.swipe方法的endx和endy输入参数的实现方式不同。

    IOS实际上是deltaX和deltaY。看看这张图片并考虑你的手指在原点(两个轴的交点)。

    enter image description here

    如果你想向下滑动手指或向右滑动你需要传递正向endx和endy正值,如果你想向上或从右向左滑动,你需要传递你想要刷你的像素值的负值手指。

    20像素向右滑动

    driver.swipe(startx,starty,20,0,duration)

    因为你不想在垂直方向上移动手指所以y总是为零!

    20像素向下滑动

    driver.swipe(startx,starty,0,20,duration)

    因为您不想在水平方向上移动手指,因此x始终为零!

    现在向上和向左滑动动作

    20像素向上滑动操作

    driver.swipe(startx,starty,0,-20,duration)

    20像素向左滑动操作

    driver.swipe(startx,starty,-20,0,duration)

答案 1 :(得分:0)

JavascriptExecutor executor = driver;

executor.executeScript(
    "target.frontMostApp().mainWindow().dragInsideWithOptions({startOffset:{x:0.5, y:0.1}, endOffset:{x:0.5, y:0.7}, duration:0.8});");

检查这是否有效..如果没有尝试进一步减少y:0.01。

答案 2 :(得分:0)

适用于iOS10和Appium 1.6.5的Python版本:

def swipe_up(self):

logging.info("swipe up")
sleep(1)
window_size = self.driver.get_window_size()  # this returns dictionary
sleep(1)
el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
action = TouchAction(self.driver)
sleep(1)
start_x = window_size["width"] * 0.5
start_y = window_size["height"]
end_x = window_size["width"] * 0.5
end_y = window_size["height"] * 0.5
action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform()
sleep(1)

对于iOS9您需要将等待更改为1000。