查看 ios 和 android 上下滚动直到找到元素然后单击

Looking to ios and android scroll up and down till element found and then click

我尝试了很多关于 ios 和 android 在 appium 中滚动的博客和讨论,java。但看起来大多数方法都已弃用或不起作用。请帮助。 我正在使用 appium 1.15.1,java,硒。

寻求快速帮助。

我正在尝试遵循代码,但它滚动了两次,甚至没有点击。

嗨,

我正在使用 Mac 并使用真实设备。 我正在使用带有 POM 的 Appium 1.15.1、Selenium、Java。 我为 iOS 向下滑动编写了以下代码。

嗨,

public void chkMenuOptioniOS1(String sName)
    {   
/* This is actual path which got from inspector
//XCUIElementTypeStaticText[@name="Account Information"]
*/
        String targetCell = "//XCUIElementTypeStaticText[contains(@name,'" + sName + "')]";
        MobileElement cellWithText = driver.findElement(By.xpath(targetCell));
        HashMap<String, String> scrollObject = new HashMap<String, String>();
        scrollObject.put("element", ((RemoteWebElement)cellWithText).getId());
        scrollObject.put("direction", "down");
        scrollObject.put("predicateString", "value == '" + sName + "'");
        scrollObject.put("toVisible", "true");
        driver.executeScript("mobile:scroll", scrollObject);
        try {
            System.out.println("In Try Block "+cellWithText.getText());
            Thread.sleep(10);
            cellWithText.click();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
  1. 滚动两次
  2. 它没有点击,

正在附加 DOM 对象屏幕截图。

请帮帮我

这些是满足您 iOS 和 Android 需求的方法:

private JavascriptExecutor js;
private HashMap<String, String> scrollObject = new HashMap<>();

void iosScrollToAnElement(IOSElement el) {
        scrollObject.put("direction", "down");
        scrollObject.put("element", el.getId());
        js.executeScript("mobile: swipe", scrollObject);
}

void androidScrollToAnElementByText(String text) {
        try {
            ((AndroidDriver)driver).findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text(\"" + text + "\").instance(0))");
        } catch (Exception e) {
            throw new NoSuchElementException("No element" + e);
        }
    }

在此之后,您需要 click() 您正在寻找的特定元素。 (只有滚动的方法)