Test Element Values and State

Test the values and state of HTML elements and controls.

The state of controls includes whether or not they exist, are enabled, or are assigned one or more specific CSS classes.

Command
Explanation
test that <locator> is checkedtest that checkbox "Accept Terms" is checkedPasses if the checkbox is checked
test that <locator> is not checkedtest that checkbox "Subscribe me to the newsletter" is not checkedPasses if the checkbox is not checked
test that <locator> has class <CSS class>test that button "Submit" has class "selected"Passes if the element has the given class (possibly among others).
test that <locator> does not have class <CSS class>test that button "Submit" does not have class "selected"Passes if the element does not have the given class.
test that <locator> has classes <list of CSS classes>test that button "Submit" has classes "selected" and "disabled"Passes if the element has all of the given classes (possibly among others).
test that <locator> does not have classes <list of CSS classes>test that button "Submit" does not have classes "selected" and "disabled"

Passes if the element does not have all of the given classes.

If the element has any subset of the listed classes, but not the full set, the command fails. In the example at left, if the button has class "selected" but not "disabled" the command will fail.

test that <locator> is emptytest that textbox "Description" is emptyTests that any value-bearing element has a value. In this example, text box "Description" has a value.
test that <locator> is not emptytest that textbox "Description" is not emptyA value-bearing element is not empty if it contains any non-whitespace characters.
test that <locator> is enabledtest that checkbox "Accept Terms" is enabledPasses if a control that can be enabled/disabled is, in fact, enabled. Elements that cannot be enabled/disabled (e.g., divs) are always enabled (if they exist).
test that <locator> is disabledtest that checkbox "Accept Terms" is disabledPasses only if the control can be enabled/disabled, and is, in fact disabled. Elements that cannot be enabled/disabled (e.g., divs) are always enabled (if they exist).
test that <locator> existstest that element at xpath "//div[@id='notification']/span" exists

Passes if exactly one matching element exists on the page. If there are no matching elements, or multiple matching elements, this command will fail.

If the application under test dynamically adds elements to the page in response to the user's actions, you may want to give the browser some time to complete the addition. See the wait up to <duration> until <locator> exists command form in the "Wait for Changes" section, below.

test that <locator> does not existtest that element at selector "div.queryResults" does not exist

Passes if there is not exactly one matching elements on the page. If there are no matching elements, or multiple matching elements, this test will fail.

If the application under test dynamically adds elements to the page in response to the user's actions, you may want to give the browser some time to complete the addition. See the wait up to <duration> until <locator> exists command form in the "Wait for Changes" section, below.

test that <locator> is visibletest that element at selector "div.adminTab" is visible

Test whether an element is visible or hidden. 

An element that is visible on the page, but not shown in the current viewport (e.g. because it has not been scrolled into view), is visible.

Both tests will fail if the element does not exist.

test that <locator> is hiddentest that element at selector "div.adminTab" is hidden
test that <locator> is selectedtest that radio button "Male" is selected

Test whether a radio button is selected or not. 

Both tests will fail if the element does not exist.

test that <locator> is not selectedtest that radio button "Female" is not selected
test that <locator> equals <value>test that textbox "Name" equals "Nikola Tesla"

Test whether an element's value equals, starts with, ends with, or contains a value (or not). Comparisons are case sensitive.

These will all fail if exactly one of the element indicated is not found.

test that <locator> does not equal <value>test that textbox "Name" does not equal "Thomas Edison"
test that <locator> starts with <value>test that textbox "Name" starts with "Nikola"
test that <locator> does not start with <value>test that textbox "Name" does not start with "Thomas"
test that <locator> ends with <value>test that textbox "Name" ends with "Tesla"
test that <locator> does not end with <value>test that textbox "Name" does not end with "Edison"
test that <locator> contains <value>test that textbox "Name" contains "la Tes"
test that <locator> does not contain <value>test that textbox "Name" does not contain "mas Ed"
test that <locator> matches <regular expression>test that textbox "Name" matches "(\w+)\s+(\w+)"

Tests whether the value of an element matches Java regular expressions, or not.

The locator must return exactly one element, or these tests will fail.

test that <locator> does not match <Java regular expression>test that textbox "Name" does not match "(\w+)\s+Edison"