简体   繁体   English

无法在appium IOS中滚动

[英]Unable to scroll in appium IOS

Unable to scroll in appium IOS till bottom of the page with below code:无法使用以下代码在 appium IOS 中滚动到页面底部:

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "up");
scrollObject.put("xpath", "//XCUIElementTypeStaticText[@name=\"NAME\"]");
js.executeScript("mobile: swipe", scrollObject);

I can scroll with the following code:我可以使用以下代码滚动:

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);

Check if this works for you!检查这是否适合您!

Edit/Update:编辑/更新:

Use the following code to scroll till you find some element:使用以下代码滚动直到找到某个元素:

JavascriptExecutor js = (JavascriptExecutor) driver;
String elementID = driver.findElementByAccessibilityId("Steppers").getId();
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", elementID);
scrollObject.put("toVisible", "not an empty string");
js.executeScript("mobile:scroll", scrollObject);

Or you can Swipe-up using the following code:或者您可以使用以下代码向上滑动:

JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "up");
js.executeScript("mobile:swipe", scrollObject);
Able to scroll to down using the below code
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);

Scroll to up using 
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "up");
js.executeScript("mobile: scroll", scrollObject);



Scrolldown till element found

    public static boolean isElementPresent(By locator, int timeout) {
        try {
            waitForElementToLoad(locator, timeout, driver);
            logger.debug("Element found in page " + pageName);
            return true;
        } catch (Exception e) {
            logger.warn("Could not find element: in page " + pageName);
            return false;

        }
    }
    
    public static WebElement waitForWebElementToLoad(By byLocator,int maxtimeWaitInSec, WebDriver driver) {
        if (driver == null) {
            return null;
        }
        FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(maxtimeWaitInSec, TimeUnit.SECONDS)
                .pollingEvery(500, TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class)
                .ignoring(StaleElementReferenceException.class);
        //return wait.until(ExpectedConditions.presenceOfElementLocated(byLocator));
        return wait.until(ExpectedConditions.visibilityOfElementLocated(byLocator));
    }


    public void scrollDownUntilElementFound(By element) {
        int scrollLimit = 0;
        while ((!isElementPresent(element, 20)) && scrollLimit < 25) {
            scrollLimit++;
            swipe(driver.`enter code here`manage().window().getSize().getWidth() / 2, driver.manage().window().getSize().getHeight() / 2,
                    0, -(driver.manage().window().getSize().getHeight()));
        }
    }

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

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