Class ExpectedConditions
ExpectedCondition
s which are generally useful within webdriver tests.-
Method Summary
Modifier and TypeMethodDescriptionstatic ExpectedCondition<Alert>
static ExpectedCondition<Boolean>
and
(ExpectedCondition<?>... conditions) An expectation with the logical and condition of the given list of conditions.static ExpectedCondition<Boolean>
attributeContains
(By locator, String attribute, String value) An expectation for checking WebElement with given locator has attribute which contains specific valuestatic ExpectedCondition<Boolean>
attributeContains
(WebElement element, String attribute, String value) An expectation for checking WebElement with given locator has attribute which contains specific valuestatic ExpectedCondition<Boolean>
attributeToBe
(By locator, String attribute, String value) An expectation for checking WebElement with given locator has attribute with a specific valuestatic ExpectedCondition<Boolean>
attributeToBe
(WebElement element, String attribute, String value) An expectation for checking given WebElement has attribute with a specific valuestatic ExpectedCondition<Boolean>
attributeToBeNotEmpty
(WebElement element, String attribute) An expectation for checking WebElement any non empty value for given attributestatic ExpectedCondition<Boolean>
domAttributeToBe
(WebElement element, String attribute, String value) An expectation for checking given WebElement has DOM attribute with a specific valuestatic ExpectedCondition<Boolean>
domPropertyToBe
(WebElement element, String property, String value) An expectation for checking given WebElement has DOM property with a specific valuestatic 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<WebElement>
elementToBeClickable
(WebElement element) 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
(int frameLocator) An expectation for checking whether the given frame is available to switch to.static ExpectedCondition<WebDriver>
frameToBeAvailableAndSwitchToIt
(String frameLocator) An expectation for checking whether the given frame is available to switch to.static ExpectedCondition<WebDriver>
frameToBeAvailableAndSwitchToIt
(By locator) An expectation for checking whether the given frame is available to switch to.static ExpectedCondition<WebDriver>
frameToBeAvailableAndSwitchToIt
(WebElement frameLocator) An expectation for checking whether the given frame is available to switch to.static ExpectedCondition<Boolean>
invisibilityOf
(WebElement element) An expectation for checking the element to be invisiblestatic ExpectedCondition<Boolean>
invisibilityOfAllElements
(List<WebElement> elements) An expectation for checking all elements from given list to be invisiblestatic ExpectedCondition<Boolean>
invisibilityOfAllElements
(WebElement... elements) An expectation for checking all elements from given list to be invisiblestatic 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>
javaScriptThrowsNoExceptions
(String javaScript) An expectation to check if js executable.static ExpectedCondition<Object>
jsReturnsValue
(String javaScript) An expectation for String value from javascriptstatic ExpectedCondition<Boolean>
not
(ExpectedCondition<?> condition) An expectation with the logical opposite condition of the given condition.static ExpectedCondition<List<WebElement>>
numberOfElementsToBe
(By locator, Integer number) An expectation for checking number of WebElements with given locatorstatic ExpectedCondition<List<WebElement>>
numberOfElementsToBeLessThan
(By locator, Integer number) An expectation for checking number of WebElements with given locator being less than defined numberstatic ExpectedCondition<List<WebElement>>
numberOfElementsToBeMoreThan
(By locator, Integer number) An expectation for checking number of WebElements with given locator being more than defined numberstatic ExpectedCondition<Boolean>
numberOfWindowsToBe
(int expectedNumberOfWindows) static ExpectedCondition<Boolean>
or
(ExpectedCondition<?>... conditions) An expectation with the logical or condition of the given list of conditions.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 ExpectedCondition<WebElement>
presenceOfNestedElementLocatedBy
(By locator, By childLocator) An expectation for checking child WebElement as a part of parent element to presentstatic ExpectedCondition<WebElement>
presenceOfNestedElementLocatedBy
(WebElement element, By childLocator) An expectation for checking child WebElement as a part of parent element to be presentstatic ExpectedCondition<List<WebElement>>
presenceOfNestedElementsLocatedBy
(By parent, By childLocator) An expectation for checking child WebElement as a part of parent element to presentstatic <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>
textMatches
(By locator, Pattern pattern) An expectation for checking WebElement with given locator has text with a value as a part of itstatic ExpectedCondition<Boolean>
An expectation for checking WebElement with given locator has specific textstatic ExpectedCondition<Boolean>
textToBePresentInElement
(WebElement element, String text) An expectation for checking if the given text is present in the specified element.static ExpectedCondition<Boolean>
textToBePresentInElementLocated
(By locator, String text) An expectation for checking if the given text is present in the element that matches the given locator.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>
textToBePresentInElementValue
(WebElement element, 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 substringstatic ExpectedCondition<Boolean>
An expectation for checking the title of a page.static ExpectedCondition<Boolean>
urlContains
(String fraction) An expectation for the URL of the current page to contain specific text.static ExpectedCondition<Boolean>
urlMatches
(String regex) Expectation for the URL to match a specific regular expressionstatic ExpectedCondition<Boolean>
An expectation for the URL of the current page to be a specific url.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<List<WebElement>>
visibilityOfAllElements
(List<WebElement> elements) An expectation for checking that all elements present on the web page that match the locator are visible.static ExpectedCondition<List<WebElement>>
visibilityOfAllElements
(WebElement... elements) An expectation for checking that all elements present on the web page that match the locator are visible.static ExpectedCondition<List<WebElement>>
visibilityOfAllElementsLocatedBy
(By locator) An expectation for checking that all elements present on the web page that match the locator are visible.static ExpectedCondition<WebElement>
visibilityOfElementLocated
(By locator) An expectation for checking that an element is present on the DOM of a page and visible.static ExpectedCondition<List<WebElement>>
visibilityOfNestedElementsLocatedBy
(By parent, By childLocator) An expectation for checking child WebElement as a part of parent element to be visiblestatic ExpectedCondition<List<WebElement>>
visibilityOfNestedElementsLocatedBy
(WebElement element, By childLocator) An expectation for checking child WebElement as a part of parent element to be visible
-
Method Details
-
titleIs
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
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
-
urlToBe
An expectation for the URL of the current page to be a specific url.- Parameters:
url
- the url that the page should be on- Returns:
true
when the URL is what it should be
-
urlContains
An expectation for the URL of the current page to contain specific text.- Parameters:
fraction
- the fraction of the url that the page should be on- Returns:
true
when the URL contains the text
-
urlMatches
Expectation for the URL to match a specific regular expression- Parameters:
regex
- the regular expression that the URL should match- Returns:
true
if the URL matches the specified regular expression
-
presenceOfElementLocated
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
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
-
visibilityOfAllElementsLocatedBy
An expectation for checking that all elements present on the web page that match the locator are visible. Visibility means that the elements are not only displayed but also have a height and width that is greater than 0.- Parameters:
locator
- used to find the element- Returns:
- the list of WebElements once they are located
-
visibilityOfAllElements
An expectation for checking that all elements present on the web page that match the locator are visible. Visibility means that the elements are not only displayed but also have a height and width that is greater than 0.- Parameters:
elements
- list of WebElements- Returns:
- the list of WebElements once they are located
-
visibilityOfAllElements
public static ExpectedCondition<List<WebElement>> visibilityOfAllElements(List<WebElement> elements) An expectation for checking that all elements present on the web page that match the locator are visible. Visibility means that the elements are not only displayed but also have a height and width that is greater than 0.- Parameters:
elements
- list of WebElements- Returns:
- the list of WebElements once they are located
-
visibilityOf
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
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
An expectation for checking if the given text is present in the specified element.- Parameters:
element
- the WebElementtext
- to be present in the element- Returns:
- true once the element contains the given text
-
textToBePresentInElementLocated
An expectation for checking if the given text is present in the element that matches the given locator.- Parameters:
locator
- used to find the elementtext
- to be present in the element found by the locator- Returns:
- true once the first element located by locator contains the given text
-
textToBePresentInElementValue
public static ExpectedCondition<Boolean> textToBePresentInElementValue(WebElement element, String text) An expectation for checking if the given text is present in the specified elements value attribute.- Parameters:
element
- the WebElementtext
- to be present in the element's value attribute- Returns:
- true once the element's value attribute contains the given text
-
textToBePresentInElementValue
An expectation for checking if the given text is present in the specified elements value attribute.- Parameters:
locator
- used to find the elementtext
- to be present in the value attribute of the element found by the locator- Returns:
- true once the value attribute of the first element located by locator contains the given text
-
frameToBeAvailableAndSwitchToIt
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.
- Parameters:
frameLocator
- used to find the frame (id or name)- Returns:
- WebDriver instance after frame has been switched
-
frameToBeAvailableAndSwitchToIt
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.
- Parameters:
locator
- used to find the frame- Returns:
- WebDriver instance after frame has been switched
-
frameToBeAvailableAndSwitchToIt
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 frameIndex.
- Parameters:
frameLocator
- used to find the frame (index)- Returns:
- WebDriver instance after frame has been switched
-
frameToBeAvailableAndSwitchToIt
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 web element.
- Parameters:
frameLocator
- used to find the frame (webelement)- Returns:
- WebDriver instance after frame has been switched
-
invisibilityOfElementLocated
An expectation for checking that an element is either invisible or not present on the DOM.- Parameters:
locator
- used to find the element- Returns:
- true if the element is not displayed or the element doesn't exist or stale element
-
invisibilityOfElementWithText
An expectation for checking that an element with text is either invisible or not present on the DOM.- Parameters:
locator
- used to find the elementtext
- of the element- Returns:
- true if no such element, stale element or displayed text not equal that provided
-
elementToBeClickable
An expectation for checking an element is visible and enabled such that you can click it.- Parameters:
locator
- used to find the element- Returns:
- the WebElement once it is located and clickable (visible and enabled)
-
elementToBeClickable
An expectation for checking an element is visible and enabled such that you can click it.- Parameters:
element
- the WebElement- Returns:
- the (same) WebElement once it is clickable (visible and enabled)
-
stalenessOf
Wait until an element is no longer attached to the DOM.- Parameters:
element
- The element to wait for.- Returns:
- false if the element is still attached to the DOM, true otherwise.
-
refreshed
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.- Type Parameters:
T
- return type of the condition provided- Parameters:
condition
- ExpectedCondition to wrap- Returns:
- the result of the provided condition
-
elementToBeSelected
An expectation for checking if the given element is selected.- Parameters:
element
- WebElement to be selected- Returns:
- true once the element is selected
-
elementSelectionStateToBe
public static ExpectedCondition<Boolean> elementSelectionStateToBe(WebElement element, boolean selected) An expectation for checking if the given element is selected.- Parameters:
element
- WebElement to be selectedselected
- boolean state of the selection state of the element- Returns:
- true once the element's selection stated is that of selected
-
elementToBeSelected
-
elementSelectionStateToBe
-
alertIsPresent
-
numberOfWindowsToBe
-
not
An expectation with the logical opposite condition of the given condition.Note that if the Condition you are inverting throws an exception that is caught by the Ignored Exceptions, the inversion will not take place and lead to confusing results.
- Parameters:
condition
- ExpectedCondition to be inverted- Returns:
- true once the condition is satisfied
-
attributeToBe
An expectation for checking WebElement with given locator has attribute with a specific value- Parameters:
locator
- used to find the elementattribute
- used to define css or html attributevalue
- used as expected attribute value- Returns:
- Boolean true when element has css or html attribute with the value
-
textToBe
An expectation for checking WebElement with given locator has specific text- Parameters:
locator
- used to find the elementvalue
- used as expected text- Returns:
- Boolean true when element has text value equal to @value
-
textMatches
An expectation for checking WebElement with given locator has text with a value as a part of it- Parameters:
locator
- used to find the elementpattern
- used as expected text matcher pattern- Returns:
- Boolean true when element has text value containing @value
-
numberOfElementsToBeMoreThan
public static ExpectedCondition<List<WebElement>> numberOfElementsToBeMoreThan(By locator, Integer number) An expectation for checking number of WebElements with given locator being more than defined number- Parameters:
locator
- used to find the elementnumber
- used to define minimum number of elements- Returns:
- Boolean true when size of elements list is more than defined
-
numberOfElementsToBeLessThan
public static ExpectedCondition<List<WebElement>> numberOfElementsToBeLessThan(By locator, Integer number) An expectation for checking number of WebElements with given locator being less than defined number- Parameters:
locator
- used to find the elementnumber
- used to define maximum number of elements- Returns:
- Boolean true when size of elements list is less than defined
-
numberOfElementsToBe
An expectation for checking number of WebElements with given locator- Parameters:
locator
- used to find the elementnumber
- used to define number of elements- Returns:
- Boolean true when size of elements list is equal to defined
-
domPropertyToBe
public static ExpectedCondition<Boolean> domPropertyToBe(WebElement element, String property, String value) An expectation for checking given WebElement has DOM property with a specific value- Parameters:
element
- used to check its parametersproperty
- property namevalue
- used as expected property value- Returns:
- Boolean true when element has DOM property with the value
-
domAttributeToBe
public static ExpectedCondition<Boolean> domAttributeToBe(WebElement element, String attribute, String value) An expectation for checking given WebElement has DOM attribute with a specific value- Parameters:
element
- used to check its parametersattribute
- attribute namevalue
- used as expected attribute value- Returns:
- Boolean true when element has DOM attribute with the value
-
attributeToBe
public static ExpectedCondition<Boolean> attributeToBe(WebElement element, String attribute, String value) An expectation for checking given WebElement has attribute with a specific value- Parameters:
element
- used to check its parametersattribute
- used to define css or html attributevalue
- used as expected attribute value- Returns:
- Boolean true when element has css or html attribute with the value
-
attributeContains
public static ExpectedCondition<Boolean> attributeContains(WebElement element, String attribute, String value) An expectation for checking WebElement with given locator has attribute which contains specific value- Parameters:
element
- used to check its parametersattribute
- used to define css or html attributevalue
- used as expected attribute value- Returns:
- Boolean true when element has css or html attribute which contains the value
-
attributeContains
public static ExpectedCondition<Boolean> attributeContains(By locator, String attribute, String value) An expectation for checking WebElement with given locator has attribute which contains specific value- Parameters:
locator
- used to define WebElement to check its parametersattribute
- used to define css or html attributevalue
- used as expected attribute value- Returns:
- Boolean true when element has css or html attribute which contains the value
-
attributeToBeNotEmpty
public static ExpectedCondition<Boolean> attributeToBeNotEmpty(WebElement element, String attribute) An expectation for checking WebElement any non empty value for given attribute- Parameters:
element
- used to check its parametersattribute
- used to define css or html attribute- Returns:
- Boolean true when element has css or html attribute with non empty value
-
visibilityOfNestedElementsLocatedBy
public static ExpectedCondition<List<WebElement>> visibilityOfNestedElementsLocatedBy(By parent, By childLocator) An expectation for checking child WebElement as a part of parent element to be visible- Parameters:
parent
- used to check parent element. For example table with locator By.id("fish")childLocator
- used to find the ultimate child element.- Returns:
- visible nested element
-
visibilityOfNestedElementsLocatedBy
public static ExpectedCondition<List<WebElement>> visibilityOfNestedElementsLocatedBy(WebElement element, By childLocator) An expectation for checking child WebElement as a part of parent element to be visible- Parameters:
element
- used as parent element. For example table with locator By.xpath("//table")childLocator
- used to find child element. For example td By.xpath("./tr/td")- Returns:
- visible sub-element
-
presenceOfNestedElementLocatedBy
public static ExpectedCondition<WebElement> presenceOfNestedElementLocatedBy(By locator, By childLocator) An expectation for checking child WebElement as a part of parent element to present- Parameters:
locator
- used to check parent element. For example table with locator By.xpath("//table")childLocator
- used to find child element. For example td By.xpath("./tr/td")- Returns:
- sub-element
-
presenceOfNestedElementLocatedBy
public static ExpectedCondition<WebElement> presenceOfNestedElementLocatedBy(WebElement element, By childLocator) An expectation for checking child WebElement as a part of parent element to be present- Parameters:
element
- used as parent elementchildLocator
- used to find child element. For example td By.xpath("./tr/td")- Returns:
- sub-element
-
presenceOfNestedElementsLocatedBy
public static ExpectedCondition<List<WebElement>> presenceOfNestedElementsLocatedBy(By parent, By childLocator) An expectation for checking child WebElement as a part of parent element to present- Parameters:
parent
- used to check parent element. For example table with locator By.xpath("//table")childLocator
- used to find child element. For example td By.xpath("./tr/td")- Returns:
- sub-element
-
invisibilityOfAllElements
An expectation for checking all elements from given list to be invisible- Parameters:
elements
- used to check their invisibility- Returns:
- Boolean true when all elements are not visible anymore
-
invisibilityOfAllElements
An expectation for checking all elements from given list to be invisible- Parameters:
elements
- used to check their invisibility- Returns:
- Boolean true when all elements are not visible anymore
-
invisibilityOf
An expectation for checking the element to be invisible- Parameters:
element
- used to check its invisibility- Returns:
- Boolean true when elements is not visible anymore
-
or
An expectation with the logical or condition of the given list of conditions.Each condition is checked until at least one of them returns true or not null.
- Parameters:
conditions
- ExpectedCondition is a list of alternative conditions- Returns:
- true once one of conditions is satisfied
-
and
An expectation with the logical and condition of the given list of conditions.Each condition is checked until all of them return true or not null
- Parameters:
conditions
- ExpectedCondition is a list of alternative conditions- Returns:
- true once all conditions are satisfied
-
javaScriptThrowsNoExceptions
An expectation to check if js executable.Useful when you know that there should be a Javascript value or something at the stage.
- Parameters:
javaScript
- used as executable script- Returns:
- true once javaScript executed without errors
-
jsReturnsValue
An expectation for String value from javascript- Parameters:
javaScript
- as executable js line- Returns:
- object once javaScript executes without errors
-