WebDriverClient (web_driver_client v0.3.0)

Copy Markdown View Source

Webdriver API client.

Summary

Sessions

Ends a session

Returns the list of sessions

Starts a new session

Navigation

Returns the web browsers current url

Returns page source of the top-most window.

Returns page title of the top-most window.

Navigates the browser to the given url

Elements

Clears the value of a text input or text area element

Fetches the currently active (focused) element

Fetches the value of an element's attribute

Sends a request to the server to see if an element is displayed

Fetches the value of an element's property

Fetches the visitble text of an element

Finds the first element using the given search strategy

Finds the elements using the given search strategy

Sends a sequence of keystrokes to the currently active element.

Sends a sequence of keystrokes to an element

Alerts

Accepts the currently active alert dialog.

Dismisses the currently active alert dialog.

Fetches the text from the currently active alert.

Sends keystrokes to the currently active Javascript prompt dialog.

Logging

Fetches the log types from the server

Fetches log entries for the requested log type.

Functions

Deletes all cookies visible to the current page

Fetches all cookies visible to the current web page.

Fetches server status

Returns the size of the current window

Sets the size of the window

Takes a screenshot of the current page.

Sessions

end_session(session)

@spec end_session(WebDriverClient.Session.t()) :: :ok | {:error, reason()}

Ends a session

fetch_sessions(config)

@spec fetch_sessions(WebDriverClient.Config.t()) ::
  {:ok, [WebDriverClient.Session.t()]} | {:error, reason()}

Returns the list of sessions

start_session(config, payload)

@spec start_session(WebDriverClient.Config.t(), map()) ::
  {:ok, WebDriverClient.Session.t()} | {:error, reason()}

Starts a new session

Elements

clear_element(session, element)

@spec clear_element(WebDriverClient.Session.t(), WebDriverClient.Element.t()) ::
  :ok | {:error, reason()}

Clears the value of a text input or text area element

click_element(session, element)

@spec click_element(WebDriverClient.Session.t(), WebDriverClient.Element.t()) ::
  :ok | {:error, reason()}

Clicks an element

fetch_active_element(session)

@spec fetch_active_element(WebDriverClient.Session.t()) ::
  {:ok, WebDriverClient.Element.t()} | {:error, reason()}

Fetches the currently active (focused) element

fetch_element_attribute(session, element, attribute_name)

@spec fetch_element_attribute(
  WebDriverClient.Session.t(),
  WebDriverClient.Element.t(),
  attribute_name()
) :: {:ok, String.t()} | {:error, reason()}

Fetches the value of an element's attribute

fetch_element_displayed(session, element)

@spec fetch_element_displayed(
  WebDriverClient.Session.t(),
  WebDriverClient.Element.t()
) ::
  {:ok, boolean()} | {:error, reason()}

Sends a request to the server to see if an element is displayed

fetch_element_property(session, element, property_name)

@spec fetch_element_property(
  WebDriverClient.Session.t(),
  WebDriverClient.Element.t(),
  property_name()
) ::
  {:ok, String.t()} | {:error, reason()}

Fetches the value of an element's property

Only supported using :w3c protocol.

fetch_element_text(session, element)

@spec fetch_element_text(WebDriverClient.Session.t(), WebDriverClient.Element.t()) ::
  {:ok, String.t()} | {:error, reason()}

Fetches the visitble text of an element

find_element(session, element_location_strategy, element_selector)

Finds the first element using the given search strategy

If no element is found, a WebDriverClient.WebDriverError is returned

find_elements(session, element_location_strategy, element_selector)

@spec find_elements(
  WebDriverClient.Session.t(),
  element_location_strategy(),
  element_selector()
) ::
  {:ok, [WebDriverClient.Element.t()]} | {:error, reason()}

Finds the elements using the given search strategy

find_elements_from_element(session, element, element_location_strategy, element_selector)

@spec find_elements_from_element(
  WebDriverClient.Session.t(),
  WebDriverClient.Element.t(),
  element_location_strategy(),
  element_selector()
) :: {:ok, [WebDriverClient.Element.t()] | {:error, reason()}}

Finds elements that are children of the given element

send_keys(session, keys)

@spec send_keys(WebDriverClient.Session.t(), keys()) :: :ok | {:error, reason()}

Sends a sequence of keystrokes to the currently active element.

Only supported with :jwp protocol. Prefer send_keys_to_element/3 for improved compatibility.

send_keys_to_element(session, element, keys)

@spec send_keys_to_element(
  WebDriverClient.Session.t(),
  WebDriverClient.Element.t(),
  keys()
) ::
  :ok | {:error, reason()}

Sends a sequence of keystrokes to an element

Alerts

accept_alert(session)

@spec accept_alert(WebDriverClient.Session.t()) :: :ok | {:error, reason()}

Accepts the currently active alert dialog.

Usually this is the equivalent to clicking ok on a dialog.

dismiss_alert(session)

@spec dismiss_alert(WebDriverClient.Session.t()) :: :ok | {:error, reason()}

Dismisses the currently active alert dialog.

For confirm() and prompt() dialogs, this is equivalent to clicking the 'Cancel' button. For alert() dialogs, this is equivalent to clicking the 'OK' button.

fetch_alert_text(session)

@spec fetch_alert_text(WebDriverClient.Session.t()) :: :ok | {:error, reason()}

Fetches the text from the currently active alert.

send_alert_text(session, text)

@spec send_alert_text(WebDriverClient.Session.t(), String.t()) ::
  :ok | {:error, reason()}

Sends keystrokes to the currently active Javascript prompt dialog.

Logging

fetch_log_types(session)

@spec fetch_log_types(WebDriverClient.Session.t()) ::
  {:ok, [log_type()]} | {:error, reason()}

Fetches the log types from the server

fetch_logs(session, log_type)

@spec fetch_logs(WebDriverClient.Session.t(), log_type()) ::
  {:ok, [WebDriverClient.LogEntry.t()]} | {:error, reason()}

Fetches log entries for the requested log type.

Types

attribute_name()

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

basic_reason()

element_location_strategy()

@type element_location_strategy() :: :css_selector | :xpath

element_selector()

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

key_code()

@type key_code() ::
  :null
  | :cancel
  | :help
  | :backspace
  | :tab
  | :clear
  | :return
  | :enter
  | :shift
  | :left_shift
  | :control
  | :left_control
  | :alt
  | :left_alt
  | :pause
  | :escape
  | :space
  | :page_up
  | :page_down
  | :end
  | :home
  | :left
  | :arrow_left
  | :up
  | :arrow_up
  | :right
  | :arrow_right
  | :down
  | :arrow_down
  | :insert
  | :delete
  | :semicolon
  | :equals
  | :numpad0
  | :numpad1
  | :numpad2
  | :numpad3
  | :numpad4
  | :numpad5
  | :numpad6
  | :numpad7
  | :numpad8
  | :numpad9
  | :multiply
  | :add
  | :separator
  | :subtract
  | :decimal
  | :divide
  | :f1
  | :f2
  | :f3
  | :f4
  | :f5
  | :f6
  | :f7
  | :f8
  | :f9
  | :f10
  | :f11
  | :f12
  | :meta
  | :command
  | :left_meta
  | :right_shift
  | :right_control
  | :right_alt
  | :right_meta
  | :numpad_page_up
  | :numpad_page_down
  | :numpad_end
  | :numpad_home
  | :numpad_left
  | :numpad_up
  | :numpad_right
  | :numpad_down
  | :numpad_insert
  | :numpad_delete

keys()

@type keys() :: keystroke() | [keystroke()]

keystroke()

@type keystroke() :: String.t() | key_code()

log_type()

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

property_name()

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

protocol()

@type protocol() :: WebDriverClient.Config.protocol()

reason()

size_opt()

@type size_opt() :: {:width, pos_integer()} | {:height, pos_integer()}

url()

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

Functions

delete_cookies(session)

@spec delete_cookies(WebDriverClient.Session.t()) :: :ok | {:error, reason()}

Deletes all cookies visible to the current page

fetch_cookies(session)

@spec fetch_cookies(WebDriverClient.Session.t()) ::
  {:ok, [WebDriverClient.Cookie.t()]} | {:error, reason()}

Fetches all cookies visible to the current web page.

fetch_server_status(config)

@spec fetch_server_status(WebDriverClient.Config.t()) ::
  {:ok, WebDriverClient.ServerStatus.t()} | {:error, reason()}

Fetches server status

fetch_window_size(session)

@spec fetch_window_size(WebDriverClient.Session.t()) ::
  {:ok, WebDriverClient.Size.t()} | {:error, reason()}

Returns the size of the current window

set_cookie(session, name, value, opts \\ [])

Sets a cookie

set_window_size(session, opts \\ [])

@spec set_window_size(WebDriverClient.Session.t(), [size_opt()]) ::
  :ok | {:error, reason()}

Sets the size of the window

take_screenshot(session)

@spec take_screenshot(WebDriverClient.Session.t()) ::
  {:ok, binary()} | {:error, reason()}

Takes a screenshot of the current page.