【问题标题】:Cannot swipe from bottom to top on ios - appium无法在 ios 上从下到上滑动 - appium
【发布时间】:2016-10-20 16:32:58
【问题描述】:

我想在 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:点不在屏幕范围内

日志是:

[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

知道发生了什么吗?

谢谢

【问题讨论】:

  • 你尝试过将 y-30 作为 startY 吗?
  • 是的。从来没有工作过。
  • 我也试过了:action = new TouchAction(driverWrapper.getIosDriver()); action.press(middleX, y - 1 ).waitAction(1000) .moveTo(middleX, y / 2).release().perform();
  • 使用 TouchAction 滑动方法本身!所以它显然行不通!检查源代码!

标签: java selenium appium


【解决方案1】:

Swipe method Criteria(Only for IOS) 避免此错误

  1. 0

  2. 0

务实的永久解决方案

为了简化我们的日常生活,写下这样的函数

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

RCA for Error: VerboseError: point is not in the bounds of the screen

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

对于 IOS,它实际上是 deltaX 和 deltaY。看看这张图片,并认为你的手指在原点(两个轴的交点)。

如果要向下或向右滑动手指,则需要传递正 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)

【讨论】:

    【解决方案2】:
    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。

    【讨论】:

    • 非常感谢您的帮助,但仍然无法正常工作。我认为取得了进展,因为现在我没有收到错误:点不在屏幕范围内。现在发生的是滑动被忽略。它没有被执行。
    • Swipe方法Criteria(Only for IOS) 避免这个错误 1. startx + endx
    【解决方案3】:

    带有 Appium 1.6.5 的 iOS10 的 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。

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 1970-01-01
      • 2019-05-26
      • 2015-11-22
      • 2020-08-06
      • 2017-07-19
      • 2015-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多