TestSelector.Test.FlokiHelpers (test_selector v0.3.2) View Source
Helpers to find test-selector
elements in HTML using Floki.
Link to this section Summary
Functions
Same as find_test_selectors/2
, but instead of returning a list of elements only
the first elements is returned.
Same as find_test_selectors/3
, but instead of returning a list of elements only
the first elements is returned.
Returns a list of elements by a given test-selector
inside a string or HTML tree.
Returns a list of elements by a given test-selector
and test-value
inside
a string or HTML tree.
Same as find_test_values/2
, but instead of returning a list of elements only
the first elements is returned.
Returns a list of test values from given elements.
Returns a list of elements inside a string or HTML tree.
Link to this section Functions
Specs
find_test_selector(String.t() | Floki.html_tree(), String.t()) :: Floki.html_tree() | nil
Same as find_test_selectors/2
, but instead of returning a list of elements only
the first elements is returned.
It will raise with an error if a conn is supplied as first argument.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_selector(text, "hello")
{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_selector(tree, "foo")
{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}
iex> text = ~S(<a test-selector="hello" test-value="world"></a>)
iex> find_test_selector(text, "foo")
nil
Specs
find_test_selector(String.t() | Floki.html_tree(), String.t(), String.t()) :: Floki.html_tree() | nil
Same as find_test_selectors/3
, but instead of returning a list of elements only
the first elements is returned.
It will raise with an error if a conn is supplied as first argument.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_selector(text, "hello", "world")
{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_selector(tree, "foo", "bar")
{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}
iex> text = ~S(<a test-selector="hello" test-value="world"></a>)
iex> find_test_selector(text, "hello", "bar")
nil
Specs
find_test_selectors(String.t() | Floki.html_tree(), String.t()) :: Floki.html_tree()
Returns a list of elements by a given test-selector
inside a string or HTML tree.
It will raise with an error if a conn is supplied as first argument.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_selectors(text, "hello")
[{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}]
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_selectors(tree, "foo")
[{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> text = ~S(<a test-selector="hello" test-value="world"></a>)
iex> find_test_selectors(text, "foo")
[]
Specs
find_test_selectors(String.t() | Floki.html_tree(), String.t(), String.t()) :: Floki.html_tree()
Returns a list of elements by a given test-selector
and test-value
inside
a string or HTML tree.
It will raise with an error if a conn is supplied as first argument.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_selectors(text, "hello", "world")
[{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}]
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_selectors(tree, "foo", "bar")
[{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> text = ~S(<a test-selector="hello" test-value="world"></a>)
iex> find_test_selectors(text, "hello", "bar")
[]
Specs
find_test_value(String.t() | Floki.html_tree(), String.t()) :: Floki.html_tree()
Same as find_test_values/2
, but instead of returning a list of elements only
the first elements is returned.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_value(text, "bar")
{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_value(tree, "world")
{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}
Specs
find_test_values(String.t() | Floki.html_tree()) :: list()
Returns a list of test values from given elements.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_values(text)
["world", "bar"]
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_values(tree)
["world", "bar"]
Specs
find_test_values(String.t() | Floki.html_tree(), String.t()) :: Floki.html_tree()
Returns a list of elements inside a string or HTML tree.
Examples
iex> text = ~S(<a test-selector="hello" test-value="world"></a><a test-selector="foo" test-value="bar"></a>)
iex> find_test_values(text, "bar")
[{"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> tree = [{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}, {"a", [{"test-selector", "foo"}, {"test-value", "bar"}], []}]
iex> find_test_values(tree, "world")
[{"a", [{"test-selector", "hello"}, {"test-value", "world"}], []}]