Hound.Helpers.Page

Provides element finders, form fillers and page-related functions

Summary

Functions

Gets element on page that is currently in focus

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

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

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

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

Gets the HTML source of current page

Gets the title of the current page

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

Macros

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

Functions

element_in_focus()

Specs

element_in_focus :: Dict.t

Gets element on page that is currently in focus.

find_all_elements(strategy, selector, retries \\ 5)

Specs

find_all_elements(atom, String.t, Integer.t) :: List.t

Finds elements on current page. Returns an array of element IDs 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_elements(:name, "username")
find_elements(:class, "example")
find_elements(:id, "example")
find_elements(:css, ".example")
find_elements(:tag, "footer")
find_elements(:link_text, "Home")
find_all_within_element(element_id, strategy, selector, retries \\ 5)

Specs

find_all_within_element(String.t, atom, String.t, Integer.t) :: List.t

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

  • The first argument is the element ID of 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 ID to search within
parent_element_id = find_element(:class, "container")

find_all_within_element(parent_element_id, :name, "username")
find_all_within_element(parent_element_id, :class, "example")
find_all_within_element(parent_element_id, :id, "example")
find_all_within_element(parent_element_id, :css, ".example")
find_all_within_element(parent_element_id, :tag, "footer")
find_all_within_element(parent_element_id, :link_text, "Home")
find_element(strategy, selector, retries \\ 5)

Specs

find_element(String.t, String.t, Integer.t) :: Dict.t

Finds element on current page. It returns an element ID 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_element(:name, "username")
find_element(:class, "example")
find_element(:id, "example")
find_element(:css, ".example")
find_element(:tag, "footer")
find_element(:link_text, "Home")
find_within_element(element_id, strategy, selector, retries \\ 5)

Specs

find_within_element(String.t, atom, String.t, Integer.t) :: Dict.t

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

  • The first argument is the element ID of 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 ID to search within
parent_element_id = find_element(:class, "container")

find_within_element(parent_element_id, :name, "username")
find_within_element(parent_element_id, :class, "example")
find_within_element(parent_element_id, :id, "example")
find_within_element(parent_element_id, :css, ".example")
find_within_element(parent_element_id, :tag, "footer")
find_within_element(parent_element_id, :link_text, "Home")
page_source()

Specs

page_source :: String.t

Gets the HTML source of current page.

page_title()

Specs

page_title :: String.t

Gets the title of the current page.

send_keys(keys)

Specs

send_keys(List.t | 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
send_text(keys)

Specs

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.

visible_page_text()

Specs

visible_page_text :: String.t

Gets the visible text of current page.

Macros

with_keys(keys, blocks)

Holds on to the spcified 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