• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 使用WebDriver遇到的那些坑(2)

    發表于:2014-07-16來源:DiggerPlus作者:陳永達點擊數: 標簽:WebDriver
    12345678910111213 protected Function WebDriver, Boolean isPageLoaded ( ) { return new Function WebDriver, Boolean ( ) { @Override public Boolean apply ( WebDriver driver ) { return ( ( JavascriptExecu

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    protected Function<WebDriver, Boolean> isPageLoaded() {
            return new Function<WebDriver, Boolean>() {
                @Override
                public Boolean apply(WebDriver driver) {
                    return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete");
                }
            };
        }
     
        public void waitForPageLoad() {
            WebDriverWait wait = new WebDriverWait(webDriver, 30);
            wait.until(isPageLoaded());
        }

      如果頁面有Ajax操作,需要寫一個Wait方法等待Ajax操作完成。方式與上一條中的基本相同。比如一個Ajax操作是用于向DropDownList中填充數據,則寫一個方法判斷該DropDownList中元素是否多余0個。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    private Function<WebDriver, Boolean> haveMoreThanOneOption(final By element) {
            return new Function<WebDriver, Boolean>() {
                @Override
                public Boolean apply(WebDriver driver) {
                    WebElement webElement = driver.findElement(element);
                    if (webElement == null) {
                        return false;
                    } else {
                        int size = webElement.findElements(By.tagName("option")).size();
                        return size >= 1;
                    }
                }
            };
        }
     
        public void waitForDropDownListLoaded() {
            WebDriverWait wait = new WebDriverWait(webDriver, 30);
            wait.until(isPageLoaded());
        }

    原文轉自:http://www.huangbowen.net/blog/2013/06/25/practice-of-webdriver/

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>