butterbee/action

The action module contains functions to perform actions on nodes.

Perform actions by passing the functions in this module to either the node.do or node.get functions.

Example

This example performs a click on the node with the css selector a.logo:

let example = driver.new(browser.Firefox)
  |> driver.goto("https://gleam.run/")
  |> get.node(by.css("a.logo"))
  |> node.do(action.click(key.LeftClick))

Values

pub fn click(
  mouse_button: key.MouseButton,
) -> fn(webdriver.WebDriver(remote_value.NodeRemoteValue)) -> webdriver.WebDriver(
  definition.CommandResponse,
)

Performs a click on the given node

pub fn click_action(
  mouse_button: Int,
) -> List(perform_actions.PointerSourceAction)

A helper function that simulates a full click action. Shorthand for pressing a mouse button, then releasing it.

pub fn enter_keys(
  keys: String,
) -> fn(webdriver.WebDriver(remote_value.NodeRemoteValue)) -> webdriver.WebDriver(
  definition.CommandResponse,
)

Simulates a user entering the given keys into the browser.

NOTE: It is not recommended to use this function for entering text into text fields. Use the node.set_value(value) function instead.

pub fn enter_keys_action(
  keys: String,
) -> List(perform_actions.KeySourceAction)

A helper function to convert a list of keysactions that simulates the user pressing the keys. Shorthand for clicking in a key, letting it go, and pressing the next key.

pub fn move_to_element(
  shared_id: String,
) -> List(perform_actions.PointerSourceAction)

A helper function that moves the mouse to the given node.

pub fn perform(
  driver: webdriver.WebDriver(remote_value.NodeRemoteValue),
  params: perform_actions.PerformActionsParameters,
) -> Result(definition.CommandResponse, @internal ButterbeeError)

Perform a custom action on a node, useful for creating more complex input actions.

Example params

let params =
  perform_actions.default(context)
  |> perform_actions.with_actions([
    // with_actions expects a list of actions
    // actions can be pointer actions, wheel actions, key actions, and a pause action.
    // These actions are performed in the order they are listed.
    perform_actions.with_key_actions(
      "entering " <> keys,
      list.new() |> list.append(enter_keys_action(key_list)),
    ),
  ])

Example usage

The example below performs a custom action on a node

let example = driver.new()
  |> driver.goto("https://packages.gleam.run/")
  |> query.node(by.css("input[aria-label='Package name, to search']"))
  |> node.do(action.perform(params))
Search Document