如何将元素滚动到iOS版appium 1.7中的特定位置

如何将元素滚动到iOS版appium 1.7中的特定位置,appium,Appium,下面的代码是工作的滚动到结束,但我不想滚动到结束 我想滚动某些特定位置: driver.findElementByXPath("//*[@value='UpcomingInstallations']").click(); JavascriptExecutor js = (JavascriptExecutor) driver; HashMap<String, String> scrollObject = new HashMap<String, String>(); scro

下面的代码是工作的滚动到结束,但我不想滚动到结束 我想滚动某些特定位置:

driver.findElementByXPath("//*[@value='UpcomingInstallations']").click();
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
driver.findelementbypath(“//*[@value='upcomingininstallations'])。单击();
JavascriptExecutor js=(JavascriptExecutor)驱动程序;
HashMap scrollObject=新建HashMap();
滚动对象。放置(“方向”,“向下”);
js.executeScript(“移动:滚动”,滚动对象);

我这样做的方法是在屏幕上查找元素(),如果看不到,则滑动

while (!displayed)
   swipe
我建议您为您的刷卡查看TouchAction类:。首选的刷卡方法如下:

myTouchAction.press(startX,startY).moveTo(endX,endY).release().perform()
由于设备之间的像素可能不同,所以您需要使用基于总屏幕大小百分比的坐标。有关更多信息,请参阅

这对我有用(Python代码):


现在让我告诉你,你的滚动代码是正确的,你还需要指定元素名属性值,下面是它在Appium 1.7中工作的代码:-

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
scrollObject.put("name", "object name value");
js.executeScript("mobile: scroll", scrollObject);
这绝对有效。

在我的例子中(使用Java),我对一个简单的UIListView执行了这项操作,并且它(在Appium-mac-1.15.0-1中)在这方面有效,因为driver.swipe方法已被弃用:

好了

public static void scrollDownIos(IOSDriver<IOSElement> driver, double scrollPercentageStart, double scrollPercentageEnd) 
{
    Dimension size = driver.manage().window().getSize();
    int x = size.getWidth()/2;
    int starty = (int) (size.getHeight() * scrollPercentageStart);
    int endy = (int) (size.getHeight() * scrollPercentageEnd);
    (new TouchAction(driver)).press(PointOption.point(x, starty))
    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
    .moveTo(PointOption.point(x, endy))
    .release()
    .perform();
}
publicstaticvoidscrolldownios(IOSDriver驱动程序,双滚动百分比开始,双滚动百分比结束)
{
维度大小=driver.manage().window().getSize();
int x=size.getWidth()/2;
int starty=(int)(size.getHeight()*scrollPercentageStart);
int endy=(int)(size.getHeight()*scrollPercentageEnd);
(新触摸动作(驱动程序))。按(点选项。点(x,起始))
.waitAction(WaitOptions.WaitOptions(持续时间:百万(2000)))
.moveTo(PointOption.point(x,endy))
.release()
.perform();
}

在滚动对象中,只需给出一个定位器值。您的定位器可以是任何可用的,例如:ID、name、xpath或其他几个可用的

JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap<String, String> scrollObject = new HashMap<String, String>();
        scrollObject.put("direction", "down");
        scrollObject.put("xpath", "<your xpath value>");
        js.executeScript("mobile: scroll", scrollObject);
JavascriptExecutor js=(JavascriptExecutor)驱动程序;
HashMap scrollObject=新建HashMap();
滚动对象。放置(“方向”,“向下”);
scrollObject.put(“xpath”,即“);
js.executeScript(“移动:滚动”,滚动对象);

感谢您的回复,我试过了,但在appium 1.7Nihal中它不起作用,它抛出错误“未知移动命令”滚动。滚动失败。
public static void scrollDownIos(IOSDriver<IOSElement> driver, double scrollPercentageStart, double scrollPercentageEnd) 
{
    Dimension size = driver.manage().window().getSize();
    int x = size.getWidth()/2;
    int starty = (int) (size.getHeight() * scrollPercentageStart);
    int endy = (int) (size.getHeight() * scrollPercentageEnd);
    (new TouchAction(driver)).press(PointOption.point(x, starty))
    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
    .moveTo(PointOption.point(x, endy))
    .release()
    .perform();
}
JavascriptExecutor js = (JavascriptExecutor) driver;
        HashMap<String, String> scrollObject = new HashMap<String, String>();
        scrollObject.put("direction", "down");
        scrollObject.put("xpath", "<your xpath value>");
        js.executeScript("mobile: scroll", scrollObject);