简体   繁体   中英

Unable to scroll in appium IOS

Unable to scroll in appium IOS till bottom of the page with below code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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