Wallabidi.Element (wallabidi v0.4.0)

Copy Markdown View Source

Defines an Element Struct and interactions with Elements.

Typically these functions are used in conjunction with a find:

page
|> find(Query.css(".some-element"), fn(element) -> Element.click(element) end)

These functions can be used to create new actions specific to your application:

def create_todo(todo_field, todo_text) do
  todo_field
  |> Element.click()
  |> Element.fill_in(with: todo_text)
  |> Element.send_keys([:enter])
end

Retrying

Unlike Browser the actions in Element do not retry if the element becomes stale. Instead an exception will be raised.

Summary

Functions

Gets the value of the element's attribute.

Returns the BiDi/CDP WebSocket pid for an Element or Session, walking up the parent chain to find the root Session's :bidi_pid.

Clears any value set in the element.

Clicks the element.

Fills in the element with the specified value.

Hovers on the element.

Returns a tuple {x, y} with the coordinates of the left-top corner of given element.

Returns the root Session for an Element or Session.

Returns a boolean based on whether or not the element is selected.

Sends keys to the element.

Sets the value of the element.

Returns a tuple {width, height} with the size of the given element.

Taps the element.

Gets the element's text value.

Touches and holds the element on its top-left corner plus an optional offset.

Scroll on the screen from the given element by the given offset using touch events.

Returns the Element's value.

Returns a boolean based on whether or not the element is visible.

Types

attr()

@type attr() :: String.t()

handle()

@type handle() ::
  String.t()
  | nil
  | {:lv_element, String.t(), non_neg_integer(), String.t()}
  | {:lazy, list(), non_neg_integer(), String.t() | nil}

keys_to_send()

@type keys_to_send() :: String.t() | [atom() | String.t()]

t()

@type t() :: %Wallabidi.Element{
  driver: module(),
  handle: handle(),
  id: String.t(),
  parent: term(),
  screenshots: list(),
  session_url: String.t(),
  url: String.t()
}

value()

@type value() :: String.t() | number() | :selected | :unselected

Functions

attr(element, name)

@spec attr(t(), attr()) :: String.t() | nil

Gets the value of the element's attribute.

bidi_pid(arg1)

@spec bidi_pid(t() | Wallabidi.Session.t()) :: pid() | nil

Returns the BiDi/CDP WebSocket pid for an Element or Session, walking up the parent chain to find the root Session's :bidi_pid.

clear(element)

@spec clear(t()) :: t()

Clears any value set in the element.

click(element, retry_count \\ 0)

Clicks the element.

fill_in(element, list)

@spec fill_in(t(), [{:with, String.t() | number()}]) :: t()

Fills in the element with the specified value.

hover(element)

@spec hover(t()) :: t()

Hovers on the element.

location(element)

@spec location(t()) :: {non_neg_integer(), non_neg_integer()}

Returns a tuple {x, y} with the coordinates of the left-top corner of given element.

root_session(s)

@spec root_session(t() | Wallabidi.Session.t()) :: Wallabidi.Session.t()

Returns the root Session for an Element or Session.

Element parent chains can nest (e.g. element → element → session); this walks up to the Session at the root.

selected?(element)

@spec selected?(t()) :: boolean()

Returns a boolean based on whether or not the element is selected.

Note

This only really makes sense for options, checkboxes, and radio buttons. Everything else will simply return false because they have no notion of "selected".

send_keys(element, text)

@spec send_keys(t(), keys_to_send()) :: t()

Sends keys to the element.

set_value(element, value)

@spec set_value(t(), value()) :: t()

Sets the value of the element.

size(element)

@spec size(t()) :: {non_neg_integer(), non_neg_integer()}

Returns a tuple {width, height} with the size of the given element.

tap(element)

@spec tap(t()) :: t()

Taps the element.

text(element)

@spec text(t()) :: String.t()

Gets the element's text value.

If the element is not visible, the return value will be "".

touch_down(element, x_offset \\ 0, y_offset \\ 0)

@spec touch_down(t(), integer(), integer()) :: t()

Touches and holds the element on its top-left corner plus an optional offset.

touch_scroll(element, x_offset, y_offset)

@spec touch_scroll(t(), integer(), integer()) :: t()

Scroll on the screen from the given element by the given offset using touch events.

value(element)

@spec value(t()) :: String.t()

Returns the Element's value.

visible?(element)

@spec visible?(t()) :: boolean()

Returns a boolean based on whether or not the element is visible.