selenium webdriver 等待元素

        /**显示等待并返回元素
         * @param driver
         * @param locator
         */
        public static WebElement showWait(WebDriver driver, final String locator)
        {
            return new WebDriverWait(driver, 10).until(new ExpectedCondition<WebElement>() {
                public WebElement apply(WebDriver d) {
                    return d.findElement(By.id(locator));
                }
            });
        }

        /**隐式等待
         * @param driver
         */
        public static void implicitWait(WebDriver driver) {
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        }

 

posted @ 2013-08-24 20:30  苦逼IT男  阅读(228)  评论(0编辑  收藏  举报