AssertHTML v0.0.1 AssertHTML View Source
AssertHTML is an Elixir library for parsing and extracting data from HTML and XML with CSS.
Link to this section Summary
Functions
Asserts an element in HTML
Asserts an text element in HTML
Asserts an text element in HTML
Gets an element’s attribute value
Gets an element’s attribute value via CSS selector
Returns part of HTML by CSS selector
Gets text from HTML element
Link to this section Types
Link to this type
attribute_name() View Source
HTML element attribute name
Link to this type
attributes()
View Source
attributes()
View Source
attributes() :: []
attributes() :: []
Link to this opaque
css_selector() View Source (opaque)
CSS selector
Supported selectors
| Pattern | Description |
|---|---|
| * | any element |
| E | an element of type E |
| E[foo] | an E element with a "foo" attribute |
| E[foo="bar"] | an E element whose "foo" attribute value is exactly equal to "bar" |
| E[foo~="bar"] | an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" |
| E[foo^="bar"] | an E element whose "foo" attribute value begins exactly with the string "bar" |
| E[foo$="bar"] | an E element whose "foo" attribute value ends exactly with the string "bar" |
| E[foo*="bar"] | an E element whose "foo" attribute value contains the substring "bar" |
| E[foo|="en"] | an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en" |
| E:nth-child(n) | an E element, the n-th child of its parent |
| E:first-child | an E element, first child of its parent |
| E:last-child | an E element, last child of its parent |
| E:nth-of-type(n) | an E element, the n-th child of its type among its siblings |
| E:first-of-type | an E element, first child of its type among its siblings |
| E:last-of-type | an E element, last child of its type among its siblings |
| E.warning | an E element whose class is "warning" |
| E#myid | an E element with ID equal to "myid" |
| E:not(s) | an E element that does not match simple selector s |
| E F | an F element descendant of an E element |
| E > F | an F element child of an E element |
| E + F | an F element immediately preceded by an E element |
| E ~ F | an F element preceded by an E element |
Link to this opaque
html()
View Source
(opaque)
html()
View Source
(opaque)
html()
html()
Link to this section Functions
Link to this function
assert_html_attributes(html, css_selector, attributes, subl_html_fn \\ nil)
View Source
assert_html_attributes(html, css_selector, attributes, subl_html_fn \\ nil)
View Source
assert_html_attributes(
html(),
css_selector(),
attributes(),
(... -> any()) | nil
) :: html() | no_return()
assert_html_attributes( html(), css_selector(), attributes(), (... -> any()) | nil ) :: html() | no_return()
Link to this function
assert_html_selector(html, css_selector)
View Source
assert_html_selector(html, css_selector)
View Source
assert_html_selector(html(), css_selector()) :: html() | no_return()
assert_html_selector(html(), css_selector()) :: html() | no_return()
Asserts an element in HTML
Raise error if selector not found
Link to this function
assert_html_text(html, value) View Source
Asserts an text element in HTML
Examples
iex> html = ~S{<h1 class="title">Header</h1>}
...> assert_html_text(html, "Header")
~S{<h1 class="title">Header</h1>}
iex> html = ~S{<h1 class="title">Header</h1>}
...> try do
...> assert_html_text(html, "HEADER")
...> rescue
...> e in ExUnit.AssertionError -> e
...> end
%ExUnit.AssertionError{
args: :ex_unit_no_meaningful_value,
expr: ~S("Header" == "HEADER"),
left: "Header",
message: "Comparison (using ==) failed in:",
right: "HEADER"
}
Link to this function
assert_html_text(html, css_selector, value)
View Source
assert_html_text(html, css_selector, value)
View Source
assert_html_text(html(), css_selector(), value()) :: html() | no_return()
assert_html_text(html(), css_selector(), value()) :: html() | no_return()
Asserts an text element in HTML
Examples
iex> html = ~S{<div class="container"> <h1 class="title">Hello World</h1> </div>}
...> assert_html_text(html, "h1", "Hello World") == html
true
iex> html = ~S{<div class="container"> <h1 class="title">Hello World</h1> </div>}
...> assert_html_text(html, ".title", ~r{World})
~S{<div class="container"> <h1 class="title">Hello World</h1> </div>}
Link to this function
html_attribute(html, attribute_name)
View Source
html_attribute(html, attribute_name)
View Source
html_attribute(html(), attribute_name()) :: value() | nil
html_attribute(html(), attribute_name()) :: value() | nil
Gets an element’s attribute value
Returns nil if attribute not found
Examples
iex> html_attribute(~S{<div class="foo bar">text</div>}, "class")
"foo bar"
iex> html_attribute(~S{<div>text</div>}, "id")
nil
iex> html = ~S{<div class="foo">Some & text</div>}
...> html_attribute(html, "text")
"Some & text"
Link to this function
html_attribute(html, css_selector, name)
View Source
html_attribute(html, css_selector, name)
View Source
html_attribute(html(), css_selector(), attribute_name()) :: value() | nil
html_attribute(html(), css_selector(), attribute_name()) :: value() | nil
Gets an element’s attribute value via CSS selector
iex> html = ~S{<div class="foo bar"></div><div class="zoo bar"></div>}
...> html_attribute(html, ".zoo", "class")
"zoo bar"
Link to this function
html_selector(html, css_selector)
View Source
html_selector(html, css_selector)
View Source
html_selector(html(), css_selector()) :: html() | nil
html_selector(html(), css_selector()) :: html() | nil
Returns part of HTML by CSS selector
Examples
iex> html = ~S{ <p><div class="foo"><h1>Header</h1</div></p> }
...> html_selector(html, "p .foo")
~S{<div class="foo"><h1>Header</h1></div>}
iex> html = ~S{ <p><div class="foo"><h1>Header</h1</div></p> }
...> html_selector(html, "h1")
"<h1>Header</h1>"
Link to this function
html_text(html, css_selector)
View Source
html_text(html, css_selector)
View Source
html_text(html(), css_selector()) :: String.t() | nil
html_text(html(), css_selector()) :: String.t() | nil
Gets text from HTML element
Examples
iex> html = ~S{<div class="container"> <h1 class="title">Header</h1> </div>}
...> html_text(html, ".title")
"Header"
Link to this function
refute_html_selector(html, css_selector)
View Source
refute_html_selector(html, css_selector)
View Source
refute_html_selector(html(), css_selector()) :: html() | no_return()
refute_html_selector(html(), css_selector()) :: html() | no_return()
Link to this function
refute_html_text(html, value) View Source
Link to this function
refute_html_text(html, css_selector, value)
View Source
refute_html_text(html, css_selector, value)
View Source
refute_html_text(html(), css_selector(), value()) :: html() | no_return()
refute_html_text(html(), css_selector(), value()) :: html() | no_return()