Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Appium滚动动作发生两次_Java_Ios_Selenium_Automation_Appium - Fatal编程技术网

Java Appium滚动动作发生两次

Java Appium滚动动作发生两次,java,ios,selenium,automation,appium,Java,Ios,Selenium,Automation,Appium,我使用下面的代码在iOS设备上滚动屏幕,但它会滚动两次。屏幕上有多个同名元素,但我想滚动到第一个元素 JavascriptExecutor js = (JavascriptExecutor) driver; HashMap<String, String> scrollObject = new HashMap<String, String>(); scrollObject.put("direction", "down");

我使用下面的代码在iOS设备上滚动屏幕,但它会滚动两次。屏幕上有多个同名元素,但我想滚动到第一个元素

 JavascriptExecutor js = (JavascriptExecutor) driver;
         HashMap<String, String> scrollObject = new HashMap<String, String>();
         scrollObject.put("direction", "down");
         scrollObject.put("xpath", "//XCUIElementTypeStaticText[@name='Max threshold (L/s)']");
         js.executeScript("mobile: scroll", scrollObject);
JavascriptExecutor js=(JavascriptExecutor)驱动程序;
HashMap scrollObject=新建HashMap();
滚动对象。放置(“方向”,“向下”);
scrollObject.put(“xpath”,“//XguiElementTypeStaticText[@name='Max threshold(L/s)')”;
js.executeScript(“移动:滚动”,滚动对象);

将序列号添加到您的
xpath

scrollObject.put("xpath", "(//XCUIElementTypeStaticText[@name='Max threshold (L/s)'])[1]");
下面的代码帮助了我

public void verticalSwipeOnce(double scrollPercentageStart, double scrollPecentageEnd) {

Dimension dim = driver.manage().window().getSize();
int height = dim.getHeight(); int starty = (int) (height * scrollPercentageStart);
int endy = (int) (height * scrollPecentageEnd);
new TouchAction((PerformsTouchActions) (driver)).press(PointOption.point(0, starty)) .waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).moveTo(PointOption.point(0, endy)) .release().perform();

 }

它仍然会滚动两次,但不会在目标元素处停止。是否有任何方法可以滚动到iOS应用程序的目标元素。我使用了下面的代码,对我来说效果很好。公共无效垂直开关(双滚动百分比开始,双滚动百分比结束){Dimension dim=driver.manage().window().getSize();int-height=dim.getHeight();int-starty=(int)(height*scrollPercentageStart);int-endy=(int)(height*scrollPecentageEnd);new-TouchAction((PerformsTouchActions)(driver))。按(PointOption.point(0,starty)).waitAction(WaitOptions.WaitOptions(Duration.ofMillis(1000)).moveTo(PointOption.point(0,endy)).release().perform();}@cindy87建议一下,如果这解决了您的问题,请将其作为答案发布。