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_info_field is that, the field is cleared before entering the new value

Enters value into field

Checks if two element IDs 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 ID

Types

Functions

attribute_value(element, attribute_name)

Specs

attribute_value(element, String.t) :: String.t | nil

Gets an element’s attribute value.

element_id = find_element(:name, "example")
attribute_value(element_id, "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(element) :: :ok

Clears textarea or input field’s value

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

You can also directly pass the selector as a tuple.

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

Specs

click(element) :: :ok

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

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

You can also directly pass the selector as a tuple.

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

Specs

css_property(element, String.t) :: String.t

Gets an element’s computed CSS property.

element_id = find_element(:name, "example")
css_property(element_id, "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?(element) :: true | false

Checks if an element is currently displayed.

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

You can also pass the selector as a tuple.

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

Specs

element_enabled?(element) :: true | false

Checks if an input field is enabled.

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

You can also pass the selector as a tuple.

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

Specs

element_location(element) :: tuple

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

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

You can also pass the selector as a tuple.

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

Specs

element_size(element) :: tuple

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

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

You can also pass the selector as a tuple.

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

Specs

fill_field(element, String.t) :: :ok

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

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

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

fill_field({:id, "example"}, "John Doe")
input_into_field(element, input)

Specs

input_into_field(element, 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_id = find_element(:id, "example")
input_into_field(element_id, "John Doe")

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

input_into_field({:id, "example"}, "John Doe")
same_element?(element_id1, element_id2)

Specs

same_element?(String.t, String.t) :: true | false

Checks if two element IDs refer to the same DOM element.

element_id1 = find_element(:name, "username")
element_id2 = find_element(:id, "user_name")
same_element?(element_id1, element_id2)
selected?(element)

Specs

selected?(element) :: true | false

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

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

You can also pass the selector as a tuple.

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

Specs

submit_element(element) :: :ok

Sends a submit event to any field or form element.

element_id = find_element(:name, "username")
submit(element_id)

You can also directly pass the selector as a tuple.

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

Specs

tag_name(element) :: String.t

Gets an element’s tag name.

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

You can also directly pass the selector as a tuple.

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

Specs

visible_text(element) :: String.t

Gets visible text of element. Requires the element ID.

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

You can also directly pass the selector as a tuple.

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