Target

This is the Target class and its API.

Target API

class Target(desc: str | None = None, locator: tuple[str, str] | None = None)

Describe an element with a human-readable string and a locator.

Abilities Required:

BrowseTheWeb

Examples:

Target.the("header search bar").located_by("div.searchbar")

Target.the("welcome message").located_by('//h2[@name = "welcome"]')

Target().located_by((By.ID, "username-field"))
classmethod the(desc: str) Self

Name this Target.

Beginning with a lower-case letter makes the logs look the nicest.

located_by(locator: tuple[str, str] | str) Self

Set the locator for this Target.

Possible values for locator:
  • A tuple of a By classifier and a string (e.g. (By.ID, "welcome"))

  • An XPATH string (e.g. "//div/h3")

  • A CSS selector string (e.g. "div.confetti")

Aliases:
located(locator: tuple[str, str] | str) Self

Alias for :meth:~screenpy_selenium.Target.located_by.

get_locator() tuple[str, str]

Return the stored locator.

Raises:

TargetingError: if no locator was set.

found_by(the_actor: Actor) WebElement

Retrieve the WebElement as viewed by the Actor.

all_found_by(the_actor: Actor) list[WebElement]

Retrieve a list of WebElement objects as viewed by the Actor.

property target_name: str | None

Return the description when set or the 2nd half of the locator.