簡體   English   中英

無法在iOS上從下往上滑動-Appium

[英]Cannot swipe from bottom to top on ios - 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:點不在屏幕范圍內

日志是:

[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

知道發生了什么嗎?

謝謝

滑動方法Criteria(僅適用於IOS)可避免此錯誤

  1. 0 <開始+結束<寬度

  2. 0 <起始+結束<高度

務實的永久解決方案

為了簡化我們的日常生活,寫下一個這樣的函數

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

RCA錯誤:VerboseError:點不在屏幕范圍內

問題是driver的endx和endy輸入參數.swipe方法對於IOS的實現方式有所不同。

對於IOS,它實際上是deltaX和deltaY。查看此圖像並考慮您的手指在原點(兩個軸的交點)。

在此處輸入圖片說明

如果要向下或向右滑動手指,則需要傳遞正的endx和endy正值;如果要向下或向右滑動,則需要傳遞負值的像素來滑動手指。

20像素向右滑動

driver.swipe(startx,starty,20,0,持續時間)

因為您不想在垂直方向上移動手指,所以y始終為零!

20像素向下滑動

driver.swipe(startx,starty,0,20,持續時間)

因為您不想在水平方向上移動手指,所以x始終為零!

現在向上和向左滑動動作

20像素向上滑動動作

driver.swipe(startx,starty,0,-20,持續時間)

20像素向左滑動動作

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});");

檢查是否有效..如果不嘗試進一步減小y:0.01。

適用於帶有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,您需要將wait更改為1000。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM