gleewright/locator

Locators find elements on a page. They are lazy: creating a locator doesn’t touch the page, and every action re-resolves it, waiting for the element to be attached, visible, stable and enabled as needed.

Create locators from a page with page.get_by_role, page.get_by_text, … and narrow them down with the functions in this module.

Types

A way to find elements on a page. Create one with the get_by_* functions in gleewright/page.

pub type Locator

The states wait_for can wait for.

pub type State {
  Attached
  Detached
  Visible
  Hidden
}

Constructors

  • Attached

    The element is in the page.

  • Detached

    The element is not in the page.

  • Visible

    The element is in the page and visible.

  • Hidden

    The element is not in the page, or is not visible.

Values

pub fn all_inner_texts(
  locator: Locator,
) -> step.Step(List(String))

The rendered text of every matching element.

pub fn and(locator: Locator, other: Locator) -> Locator

Elements matching both locators.

pub fn attribute(
  locator: Locator,
  name: String,
) -> step.Step(option.Option(String))

The value of an attribute of the element.

pub fn blur(locator: Locator) -> step.Step(Nil)

Remove focus from the element.

pub fn check(locator: Locator) -> step.Step(Nil)

Check a checkbox or radio button.

pub fn clear(locator: Locator) -> step.Step(Nil)

Clear an input or textarea.

pub fn click(locator: Locator) -> step.Step(Nil)

Click the element.

pub fn containing(locator: Locator, inner: Locator) -> Locator

Keep only elements that contain an element matching inner. inner is resolved relative to each element, so create it from the page.

pub fn count(locator: Locator) -> step.Step(Int)

How many elements currently match.

pub fn describe(locator: Locator) -> String

A description of the locator, e.g. getByRole('button').

pub fn double_click(locator: Locator) -> step.Step(Nil)

Double click the element.

pub fn fill(locator: Locator, text: String) -> step.Step(Nil)

Replace the value of an input or textarea with the given text.

pub fn first(locator: Locator) -> Locator

The first matching element.

pub fn focus(locator: Locator) -> step.Step(Nil)

Focus the element.

pub fn get_by_alt_text(scope: Locator, text: String) -> Locator

Find images by their alt text.

pub fn get_by_exact_text(scope: Locator, text: String) -> Locator

Find elements whose text is exactly the given text.

pub fn get_by_label(scope: Locator, text: String) -> Locator

Find form controls by the text of their <label> or aria-label.

pub fn get_by_placeholder(
  scope: Locator,
  text: String,
) -> Locator

Find inputs by their placeholder text.

pub fn get_by_role(scope: Locator, role: role.Role) -> Locator

Find elements with the given ARIA role inside this locator.

pub fn get_by_role_exactly_named(
  scope: Locator,
  role: role.Role,
  name: String,
) -> Locator

Like get_by_role_named, but the accessible name must match exactly. An empty name matches only elements with no accessible name.

pub fn get_by_role_named(
  scope: Locator,
  role: role.Role,
  name: String,
) -> Locator

Find elements with the given ARIA role and accessible name inside this locator. The name matches case-insensitively as a substring.

pub fn get_by_test_id(scope: Locator, id: String) -> Locator

Find elements by their data-testid attribute.

pub fn get_by_text(scope: Locator, text: String) -> Locator

Find elements containing the given text (case-insensitive substring).

pub fn get_by_title(scope: Locator, text: String) -> Locator

Find elements by their title attribute.

pub fn hover(locator: Locator) -> step.Step(Nil)

Hover the mouse over the element.

pub fn inner_text(locator: Locator) -> step.Step(String)

The rendered text of the element.

pub fn input_value(locator: Locator) -> step.Step(String)

The current value of an input, textarea or select.

pub fn is_checked(locator: Locator) -> step.Step(Bool)

Whether the checkbox or radio button is currently checked.

pub fn is_enabled(locator: Locator) -> step.Step(Bool)

Whether the element is currently enabled.

pub fn is_visible(locator: Locator) -> step.Step(Bool)

Whether the element is currently visible.

pub fn last(locator: Locator) -> Locator

The last matching element.

pub fn locator(scope: Locator, selector: String) -> Locator

Find elements matching a CSS or XPath selector inside this locator.

pub fn nth(locator: Locator, index: Int) -> Locator

The matching element at the given zero-based index.

pub fn or(locator: Locator, other: Locator) -> Locator

Elements matching either locator.

pub fn press(locator: Locator, key: String) -> step.Step(Nil)

Focus the element and press a key or key combination, e.g. "Enter" or "Control+a".

pub fn scroll_into_view(locator: Locator) -> step.Step(Nil)

Scroll the element into view.

pub fn select_option(
  locator: Locator,
  value: String,
) -> step.Step(Nil)

Select an option in a <select> by its value or label.

pub fn set_input_file(
  locator: Locator,
  path: String,
) -> step.Step(Nil)

Set the file of an <input type="file">.

pub fn text_content(
  locator: Locator,
) -> step.Step(option.Option(String))

The textContent of the element.

pub fn type_text(
  locator: Locator,
  text: String,
) -> step.Step(Nil)

Type text into the element one key at a time, firing keyboard events for each character. Prefer fill unless the page reacts to individual keys.

pub fn uncheck(locator: Locator) -> step.Step(Nil)

Uncheck a checkbox.

pub fn wait_for(locator: Locator, state: State) -> step.Step(Nil)

Wait until the element reaches the given state.

pub fn with_text(locator: Locator, text: String) -> Locator

Keep only elements that contain the given text somewhere inside them.

pub fn without_text(locator: Locator, text: String) -> Locator

Keep only elements that do not contain the given text.

✨ Search Document