TestSelector.Test.FlokiHelpers.find_test_selector

You're seeing just the function find_test_selector, go back to TestSelector.Test.FlokiHelpers module for more information.
Link to this function

find_test_selector(input, selector)

View Source

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
Link to this function

find_test_selector(input, selector, value)

View Source

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