简体   繁体   English

无法在iOS上从下往上滑动-Appium

[英]Cannot swipe from bottom to top on ios - appium

I would like to set the wifi status on ios and in order to do that, I need to to swipe up from the bottom the Control Center. 我想在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);

Before I upgraded java client to 4.0.0 and appium to 1.5.2 it worked correctly. 在将Java客户端升级到4.0.0并将appium升级到1.5.2之前,它可以正常工作。

I get an error of: Error: VerboseError: point is not within the bounds of the screen 我收到以下错误消息: 错误:VerboseError:点不在屏幕范围内

The logs are: 日志是:

[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

Any idea what is going on? 知道发生了什么吗?

Thanks 谢谢

Swipe method Criteria(Only for IOS) to avoid this error 滑动方法Criteria(仅适用于IOS)可避免此错误

  1. 0 < startx + endx < width 0 <开始+结束<宽度

  2. 0 < starty + endy < Height 0 <起始+结束<高度

Pragmatic permanent solution 务实的永久解决方案

For to simplify our day to day life, write down a function like this 为了简化我们的日常生活,写下一个这样的函数

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

RCA for Error: VerboseError: point is not within the bounds of the screen RCA错误:VerboseError:点不在屏幕范围内

Issue is endx and endy input parameters of the driver.swipe method is implemented differently for IOS. 问题是driver的endx和endy输入参数.swipe方法对于IOS的实现方式有所不同。

It is actually deltaX and deltaY for IOS.Look at this image and Consider your finger is at the origin(intersection of both axis). 对于IOS,它实际上是deltaX和deltaY。查看此图像并考虑您的手指在原点(两个轴的交点)。

在此处输入图片说明

If you want to swipe your finger down or Right side you need to pass positive endx and endy positive value and if you want to swipe down to up or right to left you need to pass negative value of pixels you want to swipe your finger. 如果要向下或向右滑动手指,则需要传递正的endx和endy正值;如果要向下或向右滑动,则需要传递负值的像素来滑动手指。

20 pixel Right Swipe 20像素向右滑动

driver.swipe(startx, starty, 20, 0, duration) driver.swipe(startx,starty,20,0,持续时间)

because you do not want to move your finger in vertical direction so y is always zero! 因为您不想在垂直方向上移动手指,所以y始终为零!

20 pixel Down Swipe 20像素向下滑动

driver.swipe(startx, starty, 0, 20, duration) driver.swipe(startx,starty,0,20,持续时间)

because you do not want to move your finger in Horizontal direction so x is always zero! 因为您不想在水平方向上移动手指,所以x始终为零!

Now UP and Left swipe actions 现在向上和向左滑动动作

20 pixel UP Swipe Action 20像素向上滑动动作

driver.swipe(startx, starty, 0, -20, duration) driver.swipe(startx,starty,0,-20,持续时间)

20 pixel Left Swipe Action 20像素向左滑动动作

driver.swipe(startx, starty, -20, 0, duration) driver.swipe(startx,starty,-20,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});");

Check if this works .. if not try to reduce the y:0.01 further. 检查是否有效..如果不尝试进一步减小y:0.01。

Python version for iOS10 with Appium 1.6.5: 适用于带有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)

For iOS9 You need to change wait to 1000. 对于iOS9,您需要将wait更改为1000。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM