hound v1.0.2 Hound.Helpers.Element

Functions to work with an element

Summary

Functions

Gets an element’s attribute value

Clears textarea or input field’s value

Click on an element. You can also use this to click on checkboxes and radio buttons

Gets an element’s computed CSS property

Checks if an element is currently displayed

Checks if an input field is enabled

Gets an element’s location on page. It returns the location as a tuple of the form {x, y}

Gets an element’s size in pixels. It returns the size as a tuple of the form {width, height}

Sets a field’s value. The difference with input_into_field is that, the field is cleared before entering the new value

Checks if an element has a given class

Enters value into field

Checks if two elements refer to the same DOM element

Checks if a radio input group or checkbox has any value selected

Sends a submit event to any field or form element

Gets an element’s tag name

Gets visible text of element. Requires the element

Functions

attribute_value(element, attribute_name)

Specs

attribute_value(Hound.Element.selector, String.t) ::
  String.t |
  nil

Gets an element’s attribute value.

element = find_element(:name, "example")
attribute_value(element, "data-greeting")

You can also pass the selector as a tuple, for the first argument

attribute_value({:name, "example"}, "data-greeting")
clear_field(element)

Specs

clear_field(Hound.Element.selector) :: :ok

Clears textarea or input field’s value

element = find_element(:class, "example")
clear_field(element)

You can also directly pass the selector as a tuple.

clear_field({:class, "example"})
click(element)

Specs

click(Hound.Element.selector) :: :ok

Click on an element. You can also use this to click on checkboxes and radio buttons.

element = find_element(:id, ".example")
click(element)

You can also directly pass the selector as a tuple.

click({:id, "example"})
css_property(element, property_name)

Specs

Gets an element’s computed CSS property.

element = find_element(:name, "example")
css_property(element, "display")

You can also pass the selector as a tuple, for the first argument

css_property({:name, "example"}, "display")
element_displayed?(element)

Specs

element_displayed?(Hound.Element.selector) ::
  true |
  false

Checks if an element is currently displayed.

element = find_element(:name, "example")
element_displayed?(element)

You can also pass the selector as a tuple.

element_displayed?({:name, "example"})

Note: If you’d like to check presence of elements in the DOM use element?/2, element_displayed?/1 will only consider elements that are always present in the DOM, either in visible or hidden state.

element_enabled?(element)

Specs

element_enabled?(Hound.Element.selector) :: boolean

Checks if an input field is enabled.

element = find_element(:name, "example")
element_enabled?(element)

You can also pass the selector as a tuple.

element_enabled?({:name, "example"})
element_location(element)

Specs

element_location(Hound.Element.selector) :: {non_neg_integer, non_neg_integer}

Gets an element’s location on page. It returns the location as a tuple of the form {x, y}.

element = find_element(:name, "example")
element_location(element)

You can also pass the selector as a tuple.

element_location({:name, "example"})
element_size(element)

Specs

element_size(Hound.Element.selector) :: {non_neg_integer, non_neg_integer}

Gets an element’s size in pixels. It returns the size as a tuple of the form {width, height}.

element = find_element(:name, "example")
element_location(element)

You can also pass the selector as a tuple.

element_location({:name, "example"})
fill_field(element, input)

Specs

fill_field(Hound.Element.selector, String.t) :: :ok

Sets a field’s value. The difference with input_into_field is that, the field is cleared before entering the new value.

element = find_element(:id, "example")
fill_field(element, "John Doe")

You can also pass the selector as a tuple, for the first argument.

fill_field({:id, "example"}, "John Doe")
has_class?(element, class)

Specs

has_class?(Hound.Element.selector, String.t) :: boolean

Checks if an element has a given class.

element = find_element(:class, "another_example")
has_class?(element, "another_class")

You can also pass the selector as a tuple, for the first argument

has_class?({:class, "another_example"}, "another_class")
inner_html(element)

Specs

inner_text(element)

Specs

input_into_field(element, input)

Specs

input_into_field(Hound.Element.selector, String.t) :: :ok

Enters value into field.

It does not clear the field before entering the new value. Anything passed is added to the value already present.

element = find_element(:id, "example")
input_into_field(element, "John Doe")

You can also pass the selector as a tuple, for the first argument.

input_into_field({:id, "example"}, "John Doe")
same_element?(element1, element2)

Specs

same_element?(Hound.Element.t, Hound.Element.t) :: boolean

Checks if two elements refer to the same DOM element.

element1 = find_element(:name, "username")
element2 = find_element(:id, "user_name")
same_element?(element1, element2)
selected?(element)

Specs

selected?(Hound.Element.selector) :: boolean

Checks if a radio input group or checkbox has any value selected.

element = find_element(:name, "example")
selected?(element)

You can also pass the selector as a tuple.

selected?({:name, "example"})
submit_element(element)

Specs

submit_element(Hound.Element.selector) :: :ok

Sends a submit event to any field or form element.

element = find_element(:name, "username")
submit_element(element)

You can also directly pass the selector as a tuple.

submit_element({:name, "username"})
tag_name(element)

Specs

Gets an element’s tag name.

element = find_element(:class, "example")
tag_name(element)

You can also directly pass the selector as a tuple.

tag_name({:class, "example"})
visible_text(element)

Specs

visible_text(Hound.Element.selector) :: String.t

Gets visible text of element. Requires the element.

element = find_element(:css, ".example")
visible_text(element)

You can also directly pass the selector as a tuple.

visible_text({:css, ".example"})