cleanup Form#params by using the xpath gem

This commit is contained in:
Thomas Walpole 2013-02-13 16:01:51 -08:00
parent b252d8f988
commit dd698daee8
2 changed files with 10 additions and 4 deletions

View File

@ -16,9 +16,15 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
def params(button)
params = {}
element_query="((.//input|.//select|.//textarea)[not(@form)])"
element_query+="|((//input|//select|//textarea)[@form='#{native[:id]}'])" if native[:id]
native.xpath("(#{element_query})[not(@disabled)]").map do |field|
form_element_types=[:input, :select, :textarea]
form_elements_xpath=XPath.generate do |x|
xpath=x.descendant(*form_element_types).where(~x.attr(:form))
xpath=xpath.union(x.anywhere(*form_element_types).where(x.attr(:form) == native[:id])) if native[:id]
xpath.where(~x.attr(:disabled))
end.to_s
native.xpath(form_elements_xpath).map do |field|
case field.name
when 'input'
if %w(radio checkbox).include? field['type']

2
xpath

@ -1 +1 @@
Subproject commit df56bb355a0a79c886444a95632ff4182d559041
Subproject commit 4c7c3351f970f14635e670239e11f81fffb07717