Hound.Helpers.Element

Provides functions related to elements.

Summary

attribute_value(element, attribute_name)

Gets an element’s attribute value

clear_field(element)

Clears textarea or input field’s value

click(element)

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

css_property(element, property_name)

Gets an element’s computed CSS property

element_displayed?(element)

Checks if an element is currently displayed

element_enabled?(element)

Checks if an input field is enabled

element_location(element)

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

element_size(element)

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

fill_field(element, input)

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

input_into_field(element, input)

Enters value into field

same_element?(element_id1, element_id2)

Checks if two element IDs refer to the same DOM element

selected?(element)

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

submit_element(element)

Sends a submit event to any field or form element

tag_name(element)

Gets an element’s tag name

visible_text(element)

Gets visible text of element. Requires the element ID

Types

Functions

attribute_value(element, attribute_name)

Specs:

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:

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 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:

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:

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:

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:

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:

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:

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:

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:

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