philss / floki

Floki is a simple HTML parser that enables search for nodes using CSS selectors.
https://hex.pm/packages/floki
MIT License
2.07k stars 156 forks source link

Include input values in the result of `Floki.text/2` #391

Closed stefanchrobot closed 1 year ago

stefanchrobot commented 2 years ago

Feature goal

Include the values of <input ...> elements in Floki.text/2.

This would be helpful for making assertions on pages that have edit forms:

test "the form is prefilled with the current entity" do
  # ...
  text = Floki.text(html)

  assert text =~ "current value"
end

This could be implemented as an option for Floki.text/2:

Floki.text(html, inputs: true)

or

Floki.text(html, inputs: ["text"])
philss commented 2 years ago

This would be a nice feature!

I think inputs: true is better. Since we need to consider the select and radio tags, maybe form_values: true could be a better name. WDYT?

A PR is welcome :) Please let me know if you need guidance here.

stefanchrobot commented 2 years ago

Cool, let me write some more tests that need checkboxes and radios and I'll come back with a PR. form_values: true sounds best.

Benjamin-Philip commented 2 years ago

Can I work on this?

stefanchrobot commented 2 years ago

Sure, feel free to do so! I wasn't able to find time to get back to this. Some comments: