⏱️Element.should()

A collection of expected conditions against an Element.

Expectations

Positive Conditions

  • .be_checked()

  • .be_clickable()

  • .be_disabled()

  • .be_enabled()

  • .be_focused()

  • .be_hidden()

  • .be_selected()

  • .be_visible()

  • .contain_text(text: str, case_sensitive=True)

  • .disappear()

  • .have_attr(attr: str, value: Optional[str])

  • .have_class(class_name: str)

  • .have_prop(prop: str, value: str)

  • .have_text(text: str, case_sensitive=True)

  • .have_value(value: any)

Negative Conditions

  • .not_be_focused()

  • .not_have_attr(attr: str, value: Optional[str])

  • .not_have_text(text: str, case_sensitive=True)

  • .not_have_value(value: any)

Syntax

# Use the default wait_time
Element.should().<expectation>

---or---

# Customize the wait_time for this expectation
Element.should(timeout: int).<expectation>

---or---

# Ignore exceptions that you expect to "get in the way"
Element.should(ignored_exceptions: list).<expectation>

---or---

# Customize both fully
Element.should(timeout: int, ignored_exceptions: list).<expectation>

Examples

Is element displayed?
def test_element_visible(py):
    py.visit("https://qap.dev")
    assert py.get("a[href='/about']").should().be_visible()
Does it have text?
def test_element_has_correct_text(py):
    py.visit("https://qap.dev")
    assert py.get("a[href='/about']").should().have_text("About")

Yields

  • Element - If the assertion passes, then the current Element is returned, else an AssertionError is raised if the condition is not met within the specified timeout.

Last updated