hound v1.0.4 Hound.Helpers.Page View Source

Provides element finders, form fillers and page-related functions

Link to this section Summary

Functions

Gets element on page that is currently in focus

Finds elements on current page. Returns an array of elements that can be used with other element functions

Finds elements within a specific element. Returns an array of elements that can be used with other element functions

Finds element on current page. It returns an element that can be used with other element functions

Finds element within a specific element. Returns an element to use with element helper functions

Gets the HTML source of current page

Gets the title of the current page

Same as find_element/3, but returns the a tuple with {:error, error} instead of raising

Same as find_within_element/4, but returns a {:error, err} tuple instead of raising

Send sequence of key strokes to active element. The keys are accepted as a list of atoms

Send character keys to active element

Gets the visible text of current page

Holds on to the specified modifier keys when the block is executing

Link to this section Functions

Link to this function element_in_focus() View Source
element_in_focus() :: map

Gets element on page that is currently in focus.

Link to this function find_all_elements(strategy, selector, retries \\ 5) View Source
find_all_elements(atom, String.t, non_neg_integer) :: list

Finds elements on current page. Returns an array of elements that can be used with other element functions.

  • The first argument is the strategy.
  • The second argument is the selector.

Valid selector strategies are :css, :class, :id, :name, :tag, :xpath, :link_text and :partial_link_text

find_all_elements(:name, "username")
find_all_elements(:class, "example")
find_all_elements(:id, "example")
find_all_elements(:css, ".example")
find_all_elements(:tag, "footer")
find_all_elements(:link_text, "Home")
Link to this function find_all_within_element(element, strategy, selector, retries \\ 5) View Source
find_all_within_element(Hound.Element.t, atom, String.t, non_neg_integer) :: list

Finds elements within a specific element. Returns an array of elements that can be used with other element functions.

  • The first argument is the element within which you want to search.
  • The second argument is the strategy.
  • The third argument is the selector.

Valid selector strategies are :css, :class, :id, :name, :tag, :xpath, :link_text and :partial_link_text

# First get an element to search within
parent_element = find_element(:class, "container")

find_all_within_element(parent_element, :name, "username")
find_all_within_element(parent_element, :class, "example")
find_all_within_element(parent_element, :id, "example")
find_all_within_element(parent_element, :css, ".example")
find_all_within_element(parent_element, :tag, "footer")
find_all_within_element(parent_element, :link_text, "Home")
Link to this function find_element(strategy, selector, retries \\ 5) View Source
find_element(Hound.Element.strategy, String.t, non_neg_integer) :: Hound.Element.t

Finds element on current page. It returns an element that can be used with other element functions.

  • The first argument is the strategy.
  • The second argument is the selector.

Valid selector strategies are :css, :class, :id, :name, :tag, :xpath, :link_text and :partial_link_text raises if the element is not found or an error happens.

find_element(:name, "username")
find_element(:class, "example")
find_element(:id, "example")
find_element(:css, ".example")
find_element(:tag, "footer")
find_element(:link_text, "Home")
Link to this function find_within_element(element, strategy, selector, retries \\ 5) View Source
find_within_element(Hound.Element.t, Hound.Element.strategy, String.t, non_neg_integer) :: Hound.Element.t

Finds element within a specific element. Returns an element to use with element helper functions.

  • The first argument is the element within which you want to search.
  • The second argument is the strategy.
  • The third argument is the selector.

Valid selector strategies are :css, :class, :id, :name, :tag, :xpath, :link_text and :partial_link_text

# First get an element to search within
parent_element = find_element(:class, "container")

find_within_element(parent_element, :name, "username")
find_within_element(parent_element, :class, "example")
find_within_element(parent_element, :id, "example")
find_within_element(parent_element, :css, ".example")
find_within_element(parent_element, :tag, "footer")
find_within_element(parent_element, :link_text, "Home")
Link to this function page_source() View Source
page_source() :: String.t

Gets the HTML source of current page.

Gets the title of the current page.

Link to this function search_element(strategy, selector, retries \\ 5) View Source
search_element(Hound.Element.strategy, String.t, non_neg_integer) ::
  {:ok, Hound.Element.t} |
  {:error, any}

Same as find_element/3, but returns the a tuple with {:error, error} instead of raising

Link to this function search_within_element(element, strategy, selector, retries \\ 5) View Source
search_within_element(Hound.Element.t, Hound.Element.strategy, String.t, non_neg_integer) ::
  {:ok, Hound.Element.t} |
  {:error, any}

Same as find_within_element/4, but returns a {:error, err} tuple instead of raising

Link to this function send_keys(keys) View Source
send_keys(list | atom) :: :ok

Send sequence of key strokes to active element. The keys are accepted as a list of atoms.

send_keys :backspace
send_keys :tab

If you send the modifier keys shift, control, alt and command, they are held on and not released until you send the :null key.

To perform other actions while holding on to modifier keys, use the with_keys macro.

The following are the atoms representing the keys:

  • :alt - alt key
  • :shift - shift key
  • :command - command key (or meta key)
  • :control - control key
  • :escape - escape key
  • :backspace - backspace key
  • :tab - tab key
  • :clear - clear
  • :return - return key
  • :enter - enter key
  • :cancel - cancel key
  • :help - help key
  • :pause - pause key
  • :num0 - numpad 0
  • :num1 - numpad 1
  • :num2 - numpad 2
  • :num3 - numpad 3
  • :num4 - numpad 4
  • :num5 - numpad 5
  • :num6 - numpad 6
  • :num7 - numpad 7
  • :num8 - numpad 8
  • :num9 - numpad 9
  • :add - add key
  • :subtract - subtract key
  • :multiply - multiply key
  • :divide - divide key
  • :seperator - seperator key
Link to this function send_text(keys) View Source
send_text(String.t) :: :ok

Send character keys to active element.

send_text "test"
send_text "whatever happens"

To send key strokes like tab, enter, etc, take a look at send_keys.

Link to this function visible_page_text() View Source
visible_page_text() :: String.t

Gets the visible text of current page.

Link to this macro with_keys(keys, blocks) View Source (macro)

Holds on to the specified modifier keys when the block is executing.

# Simulates Ctrl + e
with_keys :control do
  send_text "e"
end

# Simulates Ctrl + Shift + e
with_keys [:control, :shift] do
  send_text "e"
end

The following are the modifier keys:

  • :alt - alt key
  • :shift - shift key
  • :command - command key (or meta key)
  • :control - control key
  • :escape - escape key