无法在appium IOS中滚动

时间:2018-02-28 12:04:58

标签: ios selenium-webdriver appium

无法在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);

2 个答案:

答案 0 :(得分:0)

我可以使用以下代码滚动:

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

检查这是否适合你!

编辑/更新:

使用以下代码滚动,直到找到一些元素:

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

或者您可以使用以下代码进行向上滑动:

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

答案 1 :(得分:0)

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