Class Condition
-
Field Summary
Modifier and TypeFieldDescriptionstatic final WebElementCondition
Check that the element is animated.static final WebElementCondition
Synonym forvisible
- may be used for better readabilitystatic final WebElementCondition
Checks that checkbox is checkedstatic final WebElementCondition
Check if element is clickable:interactable
ANDenabled
.static final WebElementCondition
Checks that element is disabledstatic final WebElementCondition
Synonym forhidden
- may be used for better readability:static final WebElementCondition
static final WebElementCondition
1) For input element, check that value is missing or emptystatic final WebElementCondition
Checks that element is not disabledstatic final WebElementCondition
Check if element exist.static final WebElementCondition
Check if browser focus is currently in given element.static final WebElementCondition
Checks that element is not visible or does not exist.static final WebElementCondition
Check if image is loaded.static final WebElementCondition
Check if element is interactable: either is visible, or has css property "opacity: 0"static final WebElementCondition
Check if element has "readonly" attribute (with any value)static final WebElementCondition
Checks that element is selected (inputs like drop-downs etc.)static final WebElementCondition
Checks if element is visible -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic WebElementCondition
allOf
(WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym forand(String, WebElementCondition, WebElementCondition, WebElementCondition...)
with "all of" name.static WebElementCondition
allOf
(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) static WebElementCondition
and
(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Check if element matches ALL given conditions.static WebElementCondition
anyOf
(WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym foror(String, WebElementCondition, WebElementCondition, WebElementCondition...)
with "any of" name.static WebElementCondition
anyOf
(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) static WebElementCondition
Check if element has given attribute (with any value)static WebElementCondition
Sample:$("#mydiv").shouldHave(attribute("fileId", "12345"));
static WebElementCondition
attributeMatching
(String attributeName, String attributeRegex) Assert that given element's attribute matches given regular expressionstatic WebElementCondition
be
(WebElementCondition delegate) Used to form human-readable condition expression Example element.should(be(visible),have(text("abc"))static WebElementCondition
Asserts that element has the given class.static WebElementCondition
Checks if css property (style) applies for the element.static WebElementCondition
domAttribute
(String domAttributeName) Check if element has given dom attribute (with any value)static WebElementCondition
domAttribute
(String domAttributeName, String expectedDomAttributeValue) Sample:$("#mydiv").shouldHave(domAttributeValue("hidden", "hidden"));
static WebElementCondition
domProperty
(String domPropertyName) Check if element has given dom property (with any value)static WebElementCondition
domProperty
(String domPropertyName, String expectedDomPropertyValue) Sample:$("#mydiv").shouldHave(domPropertyValue("id", "mydiv"));
static WebElementCondition
exactOwnText
(String text) Assert that element has given text (without checking child elements).static WebElementCondition
Assert that element has given text (without checking child elements).static WebElementCondition
Assert that element has exactly (case-insensitive) given textstatic WebElementCondition
exactTextCaseSensitive
(String text) Assert that element has exactly the given textstatic WebElementCondition
exactValue
(String value) Sample:$("#input").shouldHave(exactValue("John"));
static WebElementCondition
have
(WebElementCondition delegate) Used to form human-readable condition expression Example element.should(be(visible),have(text("abc"))static WebElementCondition
Sample:$("#mydiv").shouldHave(href("/one/two/three.pdf"));
static WebElementCondition
Sample:$("#input").shouldHave(id("myForm"))
static WebElementCondition
Assert that element contains given inner text.static WebElementCondition
Checks if element matches the given predicate.static WebElementCondition
Assert that given element's text matches given regular expressionstatic WebElementCondition
Asserts the name attribute of the element to be exact stringstatic WebElementCondition
not
(WebElementCondition condition) Negate given condition.static WebElementCondition
oneOfExactTexts
(String... texts) Assert that given element's TEXT case-insensitively EQUALS to one of the giventexts
.static WebElementCondition
oneOfExactTextsCaseSensitive
(String... texts) Assert that given element's TEXT case-sensitively EQUALS to one of the giventexts
.static WebElementCondition
oneOfTexts
(String... texts) Assert that given element's TEXT case-insensitively CONTAINS at least one of the giventexts
.static WebElementCondition
oneOfTextsCaseSensitive
(String... texts) Assert that given element's TEXT case-sensitively CONTAINS at least one of the giventexts
.static WebElementCondition
or
(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Check if element matches ANY of given conditions.static WebElementCondition
Assert that element contains given text (without checking child elements).static WebElementCondition
ownTextCaseSensitive
(String text) Assert that element contains given text (without checking child elements).static WebElementCondition
partialText
(String expectedText) Assert that given element's text CONTAINS given textstatic WebElementCondition
partialTextCaseSensitive
(String expectedText) Assert that given element's text CONTAINS given text (case-sensitive)static WebElementCondition
partialValue
(String expectedValue) Assert that element contains given "value" attribute as substring NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.static WebElementCondition
Check that element has given the "content" property of the pseudo-elementstatic WebElementCondition
Check that element has given the property value of the pseudo-elementstatic WebElementCondition
selectedText
(String expectedText) Checks on<a>
element that exactly given text is selected (=marked with mouse/keyboard)static WebElementCondition
Asserts that element has the given tag name.static WebElementCondition
Assert that element contains given text as a substring.static WebElementCondition
textCaseSensitive
(String text) Assert that element contains given text as a case-sensitive substringstatic WebElementCondition
Asserts the type attribute of the element to be exact stringstatic WebElementCondition
Assert that element contains given "value" attribute as substring NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.
-
Field Details
-
visible
Checks if element is visibleSample:
$("input").shouldBe(visible);
-
exist
Check if element exist. It can be visible or hidden.Sample:
$("input").should(exist);
-
appear
Synonym forvisible
- may be used for better readabilitySample:
$("#logoutLink").should(appear);
-
disappear
Synonym forhidden
- may be used for better readability:$("#loginLink").should(disappear);
-
interactable
Check if element is interactable:- either is visible, or
- has css property "opacity: 0"
Elements which are transparent (opacity:0) are considered to be invisible, but interactable. User can click, doubleClick etc., and enter text etc. to transparent elements (for all major browsers).
Example:
$("input[type=file]").shouldBe(interactable);
- Since:
- 6.5.0
-
readonly
Check if element has "readonly" attribute (with any value)
Sample:
$("input").shouldBe(readonly);
-
editable
Check if element is "editable":- is
interactable
, and - is
enabled
, and - is not
readonly
Sample:
$("input").shouldBe(editable);
- Since:
- 6.5.0
- is
-
animated
Check that the element is animated. An animated element changes its position or size over time. Implemented for web browser context only.
Sample:
$("popup").shouldBe(animated);
- Since:
- v7.0.7
-
empty
1) For input element, check that value is missing or emptySample:
$("#input").shouldBe(empty)
2) For other elements, check that text is empty
Sample:
$("h2").shouldBe(empty)
-
image
Check if image is loaded. -
focused
Check if browser focus is currently in given element. -
enabled
Checks that element is not disabled- See Also:
-
WebElement.isEnabled()
-
disabled
Checks that element is disabled- See Also:
-
WebElement.isEnabled()
-
selected
Checks that element is selected (inputs like drop-downs etc.)- See Also:
-
WebElement.isSelected()
-
checked
Checks that checkbox is checked- See Also:
-
WebElement.isSelected()
-
clickable
Check if element is clickable:interactable
ANDenabled
.Usually you don't need to use this condition. When you just call
$("button").click()
, Selenide automatically checks that the element is clickable.
Example:
$("input[type=button]").shouldBe(clickable);
- Since:
- 7.2.0
-
-
Constructor Details
-
Condition
public Condition()
-
-
Method Details
-
attribute
Check if element has given attribute (with any value)Sample:
$("#mydiv").shouldHave(attribute("fileId"));
- Parameters:
attributeName
- name of attribute, not null
-
attribute
@CheckReturnValue @Nonnull public static WebElementCondition attribute(String attributeName, String expectedAttributeValue) Sample:
$("#mydiv").shouldHave(attribute("fileId", "12345"));
- Parameters:
attributeName
- name of attributeexpectedAttributeValue
- expected value of attribute
-
attributeMatching
@CheckReturnValue @Nonnull public static WebElementCondition attributeMatching(String attributeName, String attributeRegex) Assert that given element's attribute matches given regular expressionSample:
$("h1").shouldHave(attributeMatching("fileId", ".*12345.*"))
- Parameters:
attributeName
- name of attributeattributeRegex
- regex to match attribute value
-
href
Sample:
$("#mydiv").shouldHave(href("/one/two/three.pdf"));
It looks similar to `$.shouldHave(attribute("href", href))`, but it overcomes the fact that Selenium returns full url (even if "href" attribute in html contains relative url).
- Parameters:
href
- expected value of "href" attribute
-
value
Assert that element contains given "value" attribute as substring NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.Sample:
$("input").shouldHave(value("12345 666 77"));
- Parameters:
expectedValue
- expected value of "value" attribute
-
partialValue
Assert that element contains given "value" attribute as substring NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.Sample:
$("input").shouldHave(partialValue("12345 666 77"));
- Parameters:
expectedValue
- expected value of "value" attribute- Since:
- 6.7.3
-
pseudo
@CheckReturnValue @Nonnull public static WebElementCondition pseudo(String pseudoElementName, String propertyName, String expectedValue) Check that element has given the property value of the pseudo-elementSample:
$("input").shouldHave(pseudo(":first-letter", "color", "#ff0000"));
- Parameters:
pseudoElementName
- pseudo-element name of the element, ":before", ":after", ":first-letter", ":first-line", ":selection"propertyName
- property name of the pseudo-elementexpectedValue
- expected value of the property
-
pseudo
@CheckReturnValue @Nonnull public static WebElementCondition pseudo(String pseudoElementName, String expectedValue) Check that element has given the "content" property of the pseudo-elementSample:
$("input").shouldHave(pseudo(":before", "Hello"));
- Parameters:
pseudoElementName
- pseudo-element name of the element, ":before", ":after"expectedValue
- expected content of the pseudo-element
-
exactValue
Sample:
$("#input").shouldHave(exactValue("John"));
- Parameters:
value
- expected value of input field
-
name
Asserts the name attribute of the element to be exact stringSample:
$("#input").shouldHave(name("username"))
- Parameters:
name
- expected name of input field
-
type
Asserts the type attribute of the element to be exact stringSample:
$("#input").shouldHave(type("checkbox"))
- Parameters:
type
- expected type of input field
-
id
Sample:
$("#input").shouldHave(id("myForm"))
- Parameters:
id
- expected id of input field
-
matchText
Assert that given element's text matches given regular expressionSample:
$("h1").should(matchText("Hello\s*John"))
- Parameters:
regex
- e.g. Kicked.*Chuck Norris - in this case ".*" can contain any characters including spaces, tabs, CR etc.
-
oneOfTexts
Assert that given element's TEXT case-insensitively CONTAINS at least one of the giventexts
. Assertion fails if specified collection is empty.NB! Ignores multiple whitespaces between words.
NB! Nulls and blank strings are not allowed in the specified collection (because any element does contain an empty text).
- Throws:
IllegalArgumentException
- If specified collection containsnull
s or blank strings.- Since:
- 7.0.3
-
oneOfTextsCaseSensitive
@CheckReturnValue @Nonnull public static WebElementCondition oneOfTextsCaseSensitive(String... texts) Assert that given element's TEXT case-sensitively CONTAINS at least one of the giventexts
. Assertion fails if specified collection is empty.NB! Ignores multiple whitespaces between words.
NB! Nulls and blank strings are not allowed in the specified collection (because any element does contain an empty text).
- Throws:
IllegalArgumentException
- If specified collection containsnull
s or blank strings.- Since:
- 7.0.3
-
oneOfExactTexts
Assert that given element's TEXT case-insensitively EQUALS to one of the giventexts
. Assertion fails if specified collection is empty.NB! Ignores multiple whitespaces between words.
- Throws:
IllegalArgumentException
- If specified collection containsnull
elements.- Since:
- 7.0.3
-
oneOfExactTextsCaseSensitive
@CheckReturnValue @Nonnull public static WebElementCondition oneOfExactTextsCaseSensitive(String... texts) Assert that given element's TEXT case-sensitively EQUALS to one of the giventexts
. Assertion fails if specified collection is empty.NB! Ignores multiple whitespaces between words.
- Throws:
IllegalArgumentException
- If specified collection containsnull
elements.- Since:
- 7.0.3
-
partialText
Assert that given element's text CONTAINS given textSample:
$("h1").shouldHave(partialText("ello Joh"))
- Since:
- 6.7.0
-
partialTextCaseSensitive
@CheckReturnValue @Nonnull public static WebElementCondition partialTextCaseSensitive(String expectedText) Assert that given element's text CONTAINS given text (case-sensitive)Sample:
$("h1").should(partialTextCaseSensitive("ELLO jOH"))
- Since:
- 6.7.0
-
text
Assert that element contains given text as a substring.
Sample:
$("h1").shouldHave(text("Hello\s*John"))
NB! Case insensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element. NB! Empty string is not allowed (because any element does contain an empty text).- Throws:
IllegalArgumentException
- if given text is null or empty
-
selectedText
Checks on<a>
element that exactly given text is selected (=marked with mouse/keyboard)Sample:
$("input").shouldHave(selectedText("Text"))
NB! Case sensitive
- Parameters:
expectedText
- expected selected text of the element
-
textCaseSensitive
Assert that element contains given text as a case-sensitive substringSample:
$("h1").shouldHave(textCaseSensitive("Hello\s*John"))
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element
-
exactText
Assert that element has exactly (case-insensitive) given textSample:
$("h1").shouldHave(exactText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element
-
innerText
Assert that element contains given inner text.Sample:
$("h1").shouldHave(innerText("Hello"))
It can be used to check the text of a hidden element.
Case insensitive
NB! Ignores multiple whitespaces between words
-
ownText
Assert that element contains given text (without checking child elements).Sample:
$("h1").shouldHave(ownText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element without its children
-
ownTextCaseSensitive
Assert that element contains given text (without checking child elements).Sample:
$("h1").shouldHave(ownTextCaseSensitive("Hello"))
Case sensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element without its children- Since:
- 6.6.0
-
exactOwnText
Assert that element has given text (without checking child elements).Sample:
$("h1").shouldHave(ownText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element without its children
-
exactOwnTextCaseSensitive
Assert that element has given text (without checking child elements).Sample:
$("h1").shouldHave(exactOwnTextCaseSensitive("Hello"))
Case sensitive
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element without its children- Since:
- 6.6.0
-
exactTextCaseSensitive
Assert that element has exactly the given textSample:
$("h1").shouldHave(exactTextCaseSensitive("Hello"))
NB! Ignores multiple whitespaces between words
- Parameters:
text
- expected text of HTML element
-
tagName
Asserts that element has the given tag name.Sample:
$(".btn-primary").shouldHave(tagName("button"));
- Since:
- 6.7.3
-
cssClass
Asserts that element has the given class. Element may have other classes as well.Sample:
$("input").shouldHave(cssClass("active"));
-
cssValue
@CheckReturnValue @Nonnull public static WebElementCondition cssValue(String propertyName, @Nullable String expectedValue) Checks if css property (style) applies for the element. Both explicit and computed properties are supported.Note that if css property is missing
WebElement.getCssValue(java.lang.String)
return empty string. In this case you should assert against empty string.Sample:
<input style="font-size: 12">
$("input").shouldHave(cssValue("font-size", "12"));
$("input").shouldHave(cssValue("display", "block"));
- Parameters:
propertyName
- the css property (style) name of the elementexpectedValue
- expected value of css property- See Also:
-
WebElement.getCssValue(java.lang.String)
-
domAttribute
Check if element has given dom attribute (with any value)Sample:
$("#mydiv").shouldHave(domAttribute("hidden"));
- Parameters:
domAttributeName
- name of dom attribute, not null- Since:
- 7.4.0
-
domAttribute
@CheckReturnValue @Nonnull public static WebElementCondition domAttribute(String domAttributeName, @Nullable String expectedDomAttributeValue) Sample:
$("#mydiv").shouldHave(domAttributeValue("hidden", "hidden"));
- Parameters:
domAttributeName
- name of dom attributeexpectedDomAttributeValue
- expected value of dom attribute- Since:
- 7.4.0
-
domProperty
Check if element has given dom property (with any value)Sample:
$("#mydiv").shouldHave(domProperty("id"));
- Parameters:
domPropertyName
- name of dom property, not null- Since:
- 7.4.0
-
domProperty
@CheckReturnValue @Nonnull public static WebElementCondition domProperty(String domPropertyName, @Nullable String expectedDomPropertyValue) Sample:
$("#mydiv").shouldHave(domPropertyValue("id", "mydiv"));
- Parameters:
domPropertyName
- name of dom propertyexpectedDomPropertyValue
- expected value of dom property- Since:
- 7.4.0
-
match
@CheckReturnValue @Nonnull public static WebElementCondition match(String description, Predicate<org.openqa.selenium.WebElement> predicate) Checks if element matches the given predicate.Sample:
$("input").should(match("empty value attribute", el -> el.getAttribute("value").isEmpty()));
- Parameters:
description
- the description of the predicatepredicate
- thePredicate
to match
-
not
Negate given condition.Used for methods like $.shouldNot(exist), $.shouldNotBe(visible)
Typically, you don't need to use it.
-
and
@CheckReturnValue @Nonnull public static WebElementCondition and(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Check if element matches ALL given conditions. The method signature makes you to pass at least 2 conditions, otherwise it would be nonsense.- Parameters:
name
- Name of this condition, like "empty" (meaning e.g. empty text AND empty value).condition1
- first condition to matchcondition2
- second condition to matchconditions
- Other conditions to match- Returns:
- logical AND for given conditions.
-
allOf
@CheckReturnValue @Nonnull public static WebElementCondition allOf(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym forand(String, WebElementCondition, WebElementCondition, WebElementCondition...)
. Useful for better readability. -
allOf
@CheckReturnValue @Nonnull public static WebElementCondition allOf(WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym forand(String, WebElementCondition, WebElementCondition, WebElementCondition...)
with "all of" name. Useful for better readability. -
or
@CheckReturnValue @Nonnull public static WebElementCondition or(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Check if element matches ANY of given conditions. The method signature makes you to pass at least 2 conditions, otherwise it would be nonsense.Using "or" checks in tests is probably a flag of bad test design. Consider splitting this "or" check into two different methods or tests.
- Parameters:
name
- Name of this condition, like "error" (meaning e.g. "error" OR "failed").condition1
- first condition to matchcondition2
- second condition to matchconditions
- Other conditions to match- Returns:
- logical OR for given conditions.
- See Also:
-
anyOf
@CheckReturnValue @Nonnull public static WebElementCondition anyOf(String name, WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym foror(String, WebElementCondition, WebElementCondition, WebElementCondition...)
. Useful for better readability. -
anyOf
@CheckReturnValue @Nonnull public static WebElementCondition anyOf(WebElementCondition condition1, WebElementCondition condition2, WebElementCondition... conditions) Synonym foror(String, WebElementCondition, WebElementCondition, WebElementCondition...)
with "any of" name. Useful for better readability. -
be
Used to form human-readable condition expression Example element.should(be(visible),have(text("abc"))- Parameters:
delegate
- next condition to wrap- Returns:
- WebElementCondition
-
have
Used to form human-readable condition expression Example element.should(be(visible),have(text("abc"))- Parameters:
delegate
- next condition to wrap- Returns:
- WebElementCondition
-