hound v1.1.1 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
attribute_value(element, attribute_name)
View Source
attribute_value(Hound.Element.selector(), String.t()) :: String.t() | nil
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)
View Source
clear_field(Hound.Element.selector()) :: :ok
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)
View Source
click(Hound.Element.selector()) :: :ok
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)
View Source
css_property(Hound.Element.selector(), String.t()) :: String.t()
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")
element_displayed?(element)
View Source
element_displayed?(Hound.Element.selector()) :: true | false
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)
View Source
element_enabled?(Hound.Element.selector()) :: boolean()
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)
View Source
element_location(Hound.Element.selector()) ::
{non_neg_integer(), non_neg_integer()}
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)
View Source
element_size(Hound.Element.selector()) :: {non_neg_integer(), non_neg_integer()}
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)
View Source
fill_field(Hound.Element.selector(), String.t()) :: :ok
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)
View Source
has_class?(Hound.Element.selector(), String.t()) :: boolean()
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)
View Source
inner_html(Hound.Element.selector()) :: String.t()
inner_html(Hound.Element.selector()) :: String.t()
inner_text(element)
View Source
inner_text(Hound.Element.selector()) :: String.t()
inner_text(Hound.Element.selector()) :: String.t()
input_into_field(element, input)
View Source
input_into_field(Hound.Element.selector(), String.t()) :: :ok
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")
move_to(element, xoffset, yoffset)
View Source
move_to(Hound.Element.selector(), integer(), integer()) :: :ok
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)
outer_html(element)
View Source
outer_html(Hound.Element.selector()) :: String.t()
outer_html(Hound.Element.selector()) :: String.t()
same_element?(element1, element2)
View Source
same_element?(Hound.Element.t(), Hound.Element.t()) :: boolean()
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)
View Source
selected?(Hound.Element.selector()) :: boolean()
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)
View Source
submit_element(Hound.Element.selector()) :: :ok
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)
View Source
tag_name(Hound.Element.selector()) :: String.t()
tag_name(Hound.Element.selector()) :: String.t()
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)
View Source
visible_text(Hound.Element.selector()) :: String.t()
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"})