码迷,mamicode.com
首页 > 其他好文 > 详细

[Selenium] common functions comparison

时间:2015-04-23 15:28:27      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

1.Wait for element  in default time or self defined time

When the element need some time to be present , be visible, be not present or be not visible, for example : loading icon, waiting time is very import to get the element.

*
*SeleniumUtil.waitForElementNotVisible(driver, By.cssSelector("div#window-waiting-box"),"Waiting box should disppear in default time which is configured as timeOutInSeconds in environment.xml");

 

*SeleniumUtil.waitForElementNotVisible(driver, By.cssSelector("div#window-waiting-box"), 120 ,"Waiting box should disappear in 120s");
 

2.Explicit wait

(1)  new WebDriverWait(driver, 10). until(ExpectedConditions.elementToBeClickable(locator));

 

(2)  new WebDriverWait(driver, 10). until(ExpectedConditions.visibilityOf(locator));

 

(3)  new WebDriverWait(driver, 10). until(ExpectedConditions.presenceOfElementLocated(locator);

 

(4)

       Function<WebDriver, WebElement> waitFn = new Function<WebDriver, WebElement>() {

            @Override

            public WebElement apply(WebDriver driver) {

                return el.findElement(By.cssSelector("div.rptstatus.rptcomplete"));

            }

        };

        //Detect every 2 seconds,  the maximum time  is 120 seconds

       WebDriverWait wait = new WebDriverWait(driver, 120, 2);

       wait.withMessage("A processing icon should display in the Status column in the row.”)

       wait.until(waitFn);

 

3.waitForElementVisible    VS  waitForElementPresent

*SeleniumUtil.waitForElementVisible(driver, By.cssSelector("input#btnClose"), "Close button exists but not visible")
*
*SeleniumUtil.waitForElementPresent(driver, By.cssSelector("input#btnClose"), "Close button doesn’t exist")
 
4.waitForElementPresent   VS   waitForAllElementsPresent
*WebElement element = SeleniumUtil.waitForElementPresent(driver, By.cssSelector("input[value=‘"+buttonName+"‘]"),"Cannot get button named: "+buttonName);
*
*List<WebElement> elementList = SeleniumUtil.waitForAllElementsPresent(driver, By.cssSelector("div.rtq-grid-row[rowid]"),"Cannot get folders list");
 

5.Some element might be Present/Visible, it also might not. But both conditions are correct.

For example : alert dialog

In this condition, we need to use try{ ...} catch()

 

 6.Find element under another element

 

permissionEl.findElement(By.cssSelector("input[value=‘true‘]"))

 

SeleniumUtil.waitForElementVisible(driver, By.cssSelector(".top-bottom-split"), workSpaceEl);

public void catchIfPopUpDialogAndClickClose(){

     try{

             SeleniumUtil.waitForElementVisible(driver, By.cssSelector("input#btnClose")).click();

               logger.info("Dialog pops up");

      }

      catch(Exception e)

      {

               logger.info("No dialog pops up");

       }

   }

[Selenium] common functions comparison

标签:

原文地址:http://www.cnblogs.com/feifeidxl/p/4450530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!