org.openqa.selenium.support.ui
Class ExpectedConditions

java.lang.Object
  extended by org.openqa.selenium.support.ui.ExpectedConditions

public class ExpectedConditions
extends Object

Canned ExpectedConditions which are generally useful within webdriver tests.


Method Summary
static ExpectedCondition<Alert> alertIsPresent()
           
static ExpectedCondition<Boolean> elementSelectionStateToBe(By locator, boolean selected)
           
static ExpectedCondition<Boolean> elementSelectionStateToBe(WebElement element, boolean selected)
          An expectation for checking if the given element is selected.
static ExpectedCondition<WebElement> elementToBeClickable(By locator)
          An expectation for checking an element is visible and enabled such that you can click it.
static ExpectedCondition<Boolean> elementToBeSelected(By locator)
           
static ExpectedCondition<Boolean> elementToBeSelected(WebElement element)
          An expectation for checking if the given element is selected.
static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(String frameLocator)
          An expectation for checking whether the given frame is available to switch to.
static ExpectedCondition<Boolean> invisibilityOfElementLocated(By locator)
          An expectation for checking that an element is either invisible or not present on the DOM.
static ExpectedCondition<Boolean> invisibilityOfElementWithText(By locator, String text)
          An expectation for checking that an element with text is either invisible or not present on the DOM.
static ExpectedCondition<Boolean> not(ExpectedCondition<?> condition)
          An expectation with the logical opposite condition of the given condition.
static ExpectedCondition<List<WebElement>> presenceOfAllElementsLocatedBy(By locator)
          An expectation for checking that there is at least one element present on a web page.
static ExpectedCondition<WebElement> presenceOfElementLocated(By locator)
          An expectation for checking that an element is present on the DOM of a page.
static
<T> ExpectedCondition<T>
refreshed(ExpectedCondition<T> condition)
          Wrapper for a condition, which allows for elements to update by redrawing.
static ExpectedCondition<Boolean> stalenessOf(WebElement element)
          Wait until an element is no longer attached to the DOM.
static ExpectedCondition<Boolean> textToBePresentInElement(By locator, String text)
          An expectation for checking if the given text is present in the specified element.
static ExpectedCondition<Boolean> textToBePresentInElementValue(By locator, String text)
          An expectation for checking if the given text is present in the specified elements value attribute.
static ExpectedCondition<Boolean> titleContains(String title)
          An expectation for checking that the title contains a case-sensitive substring
static ExpectedCondition<Boolean> titleIs(String title)
          An expectation for checking the title of a page.
static ExpectedCondition<WebElement> visibilityOf(WebElement element)
          An expectation for checking that an element, known to be present on the DOM of a page, is visible.
static ExpectedCondition<WebElement> visibilityOfElementLocated(By locator)
          An expectation for checking that an element is present on the DOM of a page and visible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

titleIs

public static ExpectedCondition<Boolean> titleIs(String title)
An expectation for checking the title of a page.

Parameters:
title - the expected title, which must be an exact match
Returns:
true when the title matches, false otherwise

titleContains

public static ExpectedCondition<Boolean> titleContains(String title)
An expectation for checking that the title contains a case-sensitive substring

Parameters:
title - the fragment of title expected
Returns:
true when the title matches, false otherwise

presenceOfElementLocated

public static ExpectedCondition<WebElement> presenceOfElementLocated(By locator)
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible.

Parameters:
locator - used to find the element
Returns:
the WebElement once it is located

visibilityOfElementLocated

public static ExpectedCondition<WebElement> visibilityOfElementLocated(By locator)
An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

Parameters:
locator - used to find the element
Returns:
the WebElement once it is located and visible

visibilityOf

public static ExpectedCondition<WebElement> visibilityOf(WebElement element)
An expectation for checking that an element, known to be present on the DOM of a page, is visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.

Parameters:
element - the WebElement
Returns:
the (same) WebElement once it is visible

presenceOfAllElementsLocatedBy

public static ExpectedCondition<List<WebElement>> presenceOfAllElementsLocatedBy(By locator)
An expectation for checking that there is at least one element present on a web page.

Parameters:
locator - used to find the element
Returns:
the list of WebElements once they are located

textToBePresentInElement

public static ExpectedCondition<Boolean> textToBePresentInElement(By locator,
                                                                  String text)
An expectation for checking if the given text is present in the specified element.


textToBePresentInElementValue

public static ExpectedCondition<Boolean> textToBePresentInElementValue(By locator,
                                                                       String text)
An expectation for checking if the given text is present in the specified elements value attribute.


frameToBeAvailableAndSwitchToIt

public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(String frameLocator)
An expectation for checking whether the given frame is available to switch to.

If the frame is available it switches the given driver to the specified frame.


invisibilityOfElementLocated

public static ExpectedCondition<Boolean> invisibilityOfElementLocated(By locator)
An expectation for checking that an element is either invisible or not present on the DOM.

Parameters:
locator - used to find the element

invisibilityOfElementWithText

public static ExpectedCondition<Boolean> invisibilityOfElementWithText(By locator,
                                                                       String text)
An expectation for checking that an element with text is either invisible or not present on the DOM.

Parameters:
locator - used to find the element
text - of the element

elementToBeClickable

public static ExpectedCondition<WebElement> elementToBeClickable(By locator)
An expectation for checking an element is visible and enabled such that you can click it.


stalenessOf

public static ExpectedCondition<Boolean> stalenessOf(WebElement element)
Wait until an element is no longer attached to the DOM.

Parameters:
element - The element to wait for.
Returns:
false is the element is still attached to the DOM, true otherwise.

refreshed

public static <T> ExpectedCondition<T> refreshed(ExpectedCondition<T> condition)
Wrapper for a condition, which allows for elements to update by redrawing. This works around the problem of conditions which have two parts: find an element and then check for some condition on it. For these conditions it is possible that an element is located and then subsequently it is redrawn on the client. When this happens a StaleElementReferenceException is thrown when the second part of the condition is checked.


elementToBeSelected

public static ExpectedCondition<Boolean> elementToBeSelected(WebElement element)
An expectation for checking if the given element is selected.


elementSelectionStateToBe

public static ExpectedCondition<Boolean> elementSelectionStateToBe(WebElement element,
                                                                   boolean selected)
An expectation for checking if the given element is selected.


elementToBeSelected

public static ExpectedCondition<Boolean> elementToBeSelected(By locator)

elementSelectionStateToBe

public static ExpectedCondition<Boolean> elementSelectionStateToBe(By locator,
                                                                   boolean selected)

alertIsPresent

public static ExpectedCondition<Alert> alertIsPresent()

not

public static ExpectedCondition<Boolean> not(ExpectedCondition<?> condition)
An expectation with the logical opposite condition of the given condition. In case of null, it will return false.



Copyright © 2013. All Rights Reserved.