contains

The command to get a single Element containing the given text.

Syntax

py.contains(text: str) -> Element
py.contains(text: str, timeout: int) -> Element

---or---

Element.contains(text: str) -> Element
Element.contains(timeout: int) -> Element

Usage

correct usage
# Yield Element in .nav containing "About"
py.get(".nav").contains("About")

---or---

# Yield first Element in document containing 'Hello'
py.contains("Hello")

---or--- # store in a variable

element = py.contains("About")

---or--- # chain an Element command

py.contains("About").click()

---or--- # control the timeout in any of the above usages

py.contains("Deck Builder", timeout=5).click()
incorrect usage
# Errors, 'title' does not yield Element
py.title().contains("QAP")

---or---

# Errors, 'get_cookies' does not yield Element
py.get_cookies().contains("Cooke Monster")

Arguments

  • text (str) - The text to look for

  • timeout=None (int) - The number of seconds for this command to succeed.

    • timeout=None will use the default wait_time in pylenium.json

    • timeout=0 will poll the DOM immediately with no wait

    • Any value greater than zero will override the default wait_time

It does not need to be an exact match

Yields

  • Element - The first element that is found, even if multiple elements match the query

Last updated