Element State Checks

isDisplayed, isEnabled, isSelected

<input type="checkbox" id="remember-me" checked>
<button id="checkout" disabled>Checkout</button>
<p class="error-message" style="display:none">Invalid email or password</p>
System.out.println(driver.findElement(By.id("remember-me")).isSelected());        // checkbox / radio ticked?
System.out.println(driver.findElement(By.id("checkout")).isEnabled());           // can it be clicked?
System.out.println(driver.findElement(By.cssSelector(".error-message")).isDisplayed()); // visible?

Example

Output (empty cart, page just loaded):

Run StateTest.main()

Example output

true
false
false

Present vs Displayed

SituationfindElements(...).size()isDisplayed()
element in HTML and visible1true
element in HTML but hidden (display:none)1false
element not in HTML0cannot call: findElement throws NoSuchElementException

Tip: To check "the error is NOT shown", first check presence with findElements, then isDisplayed() only if it is present.