hound v1.1.0 Hound.Helpers.Element View Source

Functions to work with an element

Link to this section 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

Moves the mouse to a given position within the given element. X and Y are relatively to the element and start from top left

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

Link to this section Functions

Link to this function

attribute_value(element, attribute_name) View Source
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")
Link to this function

clear_field(element) View Source
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 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"})
Link to this function

css_property(element, property_name) View Source
css_property(Hound.Element.selector(), String.t()) :: String.t()

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")
Link to this function

element_displayed?(element) View Source
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.

Link to this function

element_enabled?(element) View Source
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"})

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"})

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"})
Link to this function

fill_field(element, input) View Source
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")
Link to this function

has_class?(element, class) View Source
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")
Link to this function

input_into_field(element, input) View Source
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")
Link to this function

move_to(element, xoffset, yoffset) View Source
move_to(Hound.Element.selector(), integer(), integer()) :: :ok

Moves the mouse to a given position within the given element. X and Y are relatively to the element and start from top left.

element = find_element(:id, "example")
move_to(element, 10, 10)

You can also directly pass the selector as a tuple.

move_to({:id, "example"}, 10, 10)
Link to this function

same_element?(element1, element2) View Source
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)

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"})
Link to this function

submit_element(element) View Source
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"})

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"})
Link to this function

visible_text(element) View Source
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"})