public abstract class Condition
extends java.lang.Object
implements com.google.common.base.Predicate<org.openqa.selenium.WebElement>
Modifier and Type | Field and Description |
---|---|
static Condition |
appear
Synonym for
visible - may be used for better readability |
static Condition |
appears
Synonym for
visible - may be used for better readability |
static Condition |
checked
Checks that checkbox is checked
|
static Condition |
disabled
Checks that element is disabled
|
static Condition |
disappear
Synonym for
hidden - may be used for better readability: |
static Condition |
disappears
Synonym for
hidden - may be used for better readability: |
static Condition |
empty
1) For input element, check that value is missing or empty
|
static Condition |
enabled
Checks that element is not disabled
|
static Condition |
exist
Check if element exist.
|
static Condition |
focused
Check if browser focus is currently in given element.
|
static Condition |
hidden
Checks that element is not visible or does not exists.
|
protected java.lang.String |
name |
protected boolean |
nullIsAllowed |
static Condition |
present
|
static Condition |
readonly
Check if element has "readonly" attribute (with any value)
|
static Condition |
selected
Checks that element is selected
|
static Condition |
visible
Checks if element is visible
|
Constructor and Description |
---|
Condition(java.lang.String name) |
Condition(java.lang.String name,
boolean absentElementMatchesCondition) |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
actualValue(org.openqa.selenium.WebElement element)
If element didn't match the condition, returns the actual value of element.
|
static Condition |
and(java.lang.String name,
Condition... condition)
Check if element matches ALL given conditions.
|
abstract boolean |
apply(org.openqa.selenium.WebElement element)
Check if given element matches this condition.
|
boolean |
applyNull() |
static Condition |
attribute(java.lang.String attributeName)
Check if element has given attribute (with any value)
|
static Condition |
attribute(java.lang.String attributeName,
java.lang.String expectedAttributeValue)
Sample:
$("#mydiv").shouldHave(attribute("fileId", "12345")); |
static Condition |
be(Condition delegate)
Used to form human-readable condition expression
Example element.should(be(visible),have(text("abc"))
|
Condition |
because(java.lang.String message)
Should be used for explaining the reason of condition
|
static Condition |
cssClass(java.lang.String cssClass)
Sample:
$("input").shouldHave(cssClass("active")); |
static Condition |
exactText(java.lang.String text)
Sample:
$("h1").shouldHave(exactText("Hello")) |
static Condition |
exactTextCaseSensitive(java.lang.String text)
Sample:
$("h1").shouldHave(exactTextCaseSensitive("Hello")) |
static Condition |
exactValue(java.lang.String value)
Sample:
$("#input").shouldHave(exactValue("John")); |
static Condition |
hasAttribute(java.lang.String attributeName,
java.lang.String attributeValue)
Deprecated.
please use
attribute(String, String) instead
Sample:
|
static Condition |
hasClass(java.lang.String cssClass)
Deprecated.
please use
cssClass(String) instead of this method, which is exactly the same |
static boolean |
hasClass(org.openqa.selenium.WebElement element,
java.lang.String cssClass)
Deprecated.
don't use this method, it is public by accident, and will be turned to private soon
|
static Condition |
hasText(java.lang.String text)
Deprecated.
please use
text(String) instead
Sample: Case insensitive NB! Ignores multiple whitespaces between words |
static Condition |
hasValue(java.lang.String value)
Deprecated.
please use
value(String) instead
Sample: |
static Condition |
have(Condition delegate)
Used to form human-readable condition expression
Example element.should(be(visible),have(text("abc"))
|
static Condition |
id(java.lang.String id)
Sample:
$("#input").shouldHave(id("myForm")) |
static Condition |
matchesText(java.lang.String text)
Sample:
$(".error_message").waitWhile(matchesText("Exception"), 12000) |
static Condition |
matchText(java.lang.String regex)
Assert that given element's text matches given regular expression
|
static Condition |
name(java.lang.String name)
Sample:
$("#input").shouldHave(name("username")) |
static Condition |
not(Condition condition)
Negate given condition.
|
static Condition |
or(java.lang.String name,
Condition... condition)
Check if element matches ANY of given conditions.
|
static Condition |
text(java.lang.String text)
Sample:
$("h1").shouldHave(text("Hello\s*John")) |
static Condition |
textCaseSensitive(java.lang.String text)
Sample:
$("h1").shouldHave(textCaseSensitive("Hello\s*John")) |
java.lang.String |
toString() |
static Condition |
type(java.lang.String type)
Sample:
$("#input").shouldHave(type("checkbox")) |
static Condition |
value(java.lang.String expectedValue)
Assert that element has given "value" attribute as substring
NB! Ignores difference in non-visible characters like spaces, non-breakable spaces, tabs, newlines etc.
|
public static final Condition visible
Sample: $("input").shouldBe(visible);
public static final Condition exist
Sample: $("input").should(exist);
@Deprecated public static final Condition present
public static final Condition hidden
appear
Sample: $("input").shouldBe(hidden);
public static final Condition appear
visible
- may be used for better readability
Sample: $("#logoutLink").should(appear);
public static final Condition appears
visible
- may be used for better readability
$("#logoutLink").waitUntil(appears, 10000);
waitFor(By.id("logoutLink");
public static final Condition disappears
hidden
- may be used for better readability:
Sample: $("#loginLink").waitUntil(disappears, 9000);
public static final Condition disappear
hidden
- may be used for better readability:
$("#loginLink").should(disappear);
public static final Condition readonly
Sample: $("input").shouldBe(readonly);
public static final Condition empty
Sample: $("#input").shouldBe(empty)
Sample: $("h2").shouldBe(empty)
public static final Condition focused
public static final Condition enabled
WebElement.isEnabled()
public static final Condition disabled
WebElement.isEnabled()
public static final Condition selected
WebElement.isSelected()
public static final Condition checked
WebElement.isSelected()
protected final java.lang.String name
protected final boolean nullIsAllowed
public Condition(java.lang.String name)
public Condition(java.lang.String name, boolean absentElementMatchesCondition)
@Deprecated public static Condition hasAttribute(java.lang.String attributeName, java.lang.String attributeValue)
attribute(String, String)
instead
Sample:
$("#mydiv").waitUntil(hasAttribute("fileId", "12345"), 7000);
attributeName
- name of attributeattributeValue
- expected value of attributepublic static Condition attribute(java.lang.String attributeName)
Sample: $("#mydiv").shouldHave(attribute("fileId"));
attributeName
- name of attribute, not nullpublic static Condition attribute(java.lang.String attributeName, java.lang.String expectedAttributeValue)
Sample: $("#mydiv").shouldHave(attribute("fileId", "12345"));
attributeName
- name of attributeexpectedAttributeValue
- expected value of attributepublic static Condition value(java.lang.String expectedValue)
Sample: $("input").shouldHave(value("12345 666 77"));
expectedValue
- expected value of "value" attributepublic static Condition exactValue(java.lang.String value)
Sample: $("#input").shouldHave(exactValue("John"));
value
- expected value of input field@Deprecated public static Condition hasValue(java.lang.String value)
value(String)
instead
Sample: $("#myInput").waitUntil(hasValue("John"), 5000)
value
- expected value of input fieldpublic static Condition name(java.lang.String name)
Sample: $("#input").shouldHave(name("username"))
name
- expected name of input fieldpublic static Condition type(java.lang.String type)
Sample: $("#input").shouldHave(type("checkbox"))
type
- expected type of input fieldpublic static Condition id(java.lang.String id)
Sample: $("#input").shouldHave(id("myForm"))
id
- expected id of input fieldpublic static Condition matchesText(java.lang.String text)
Sample: $(".error_message").waitWhile(matchesText("Exception"), 12000)
matchText(String)
public static Condition matchText(java.lang.String regex)
Sample: $("h1").should(matchText("Hello\s*John"))
regex
- e.g. Kicked.*Chuck Norris - in this case ".*" can contain any characters including spaces, tabs, CR etc.@Deprecated public static Condition hasText(java.lang.String text)
text(String)
instead
Sample: $("h1").waitUntil(hasText("Hello"), 10000)
Case insensitive
NB! Ignores multiple whitespaces between wordstext
- expected text of HTML elementpublic static Condition text(java.lang.String text)
Sample: $("h1").shouldHave(text("Hello\s*John"))
NB! Case insensitive
NB! Ignores multiple whitespaces between words
text
- expected text of HTML elementpublic static Condition textCaseSensitive(java.lang.String text)
Sample: $("h1").shouldHave(textCaseSensitive("Hello\s*John"))
NB! Ignores multiple whitespaces between words
text
- expected text of HTML elementpublic static Condition exactText(java.lang.String text)
Sample: $("h1").shouldHave(exactText("Hello"))
Case insensitive
NB! Ignores multiple whitespaces between words
text
- expected text of HTML elementpublic static Condition exactTextCaseSensitive(java.lang.String text)
Sample: $("h1").shouldHave(exactTextCaseSensitive("Hello"))
NB! Ignores multiple whitespaces between words
text
- expected text of HTML element@Deprecated public static boolean hasClass(org.openqa.selenium.WebElement element, java.lang.String cssClass)
#cssClass(String)} instead of using it
@Deprecated public static Condition hasClass(java.lang.String cssClass)
cssClass(String)
instead of this method, which is exactly the samepublic static Condition cssClass(java.lang.String cssClass)
Sample: $("input").shouldHave(cssClass("active"));
public static Condition not(Condition condition)
public static Condition and(java.lang.String name, Condition... condition)
name
- Name of this condition, like "empty" (meaning e.g. empty text AND empty value).condition
- Conditions to match.public static Condition or(java.lang.String name, Condition... condition)
name
- Name of this condition, like "error" (meaning e.g. "error" OR "failed").condition
- Conditions to match.public static Condition be(Condition delegate)
delegate
- next condition to wrappublic static Condition have(Condition delegate)
delegate
- next condition to wrappublic abstract boolean apply(org.openqa.selenium.WebElement element)
element
- given WebElementpublic final boolean applyNull()
public java.lang.String actualValue(org.openqa.selenium.WebElement element)
element
- given WebElementpublic Condition because(java.lang.String message)
public java.lang.String toString()
toString
in class java.lang.Object