add clicked buttons
parent
b4c5e33037
commit
dc9f937ccc
|
@ -68,7 +68,8 @@ class Mechanize
|
|||
@agent.history.pop
|
||||
end
|
||||
|
||||
def submit(form)
|
||||
def submit(form, button=nil)
|
||||
form.add_button_to_query(button) if button
|
||||
case form.method.upcase
|
||||
when "POST"
|
||||
post_form(form.action, form, request_headers)
|
||||
|
|
|
@ -29,7 +29,7 @@ class MechanizeCr::Form
|
|||
@action = node.fetch("action", "")
|
||||
@method = node.fetch("method", "GET").upcase
|
||||
@name = node.fetch("name", "")
|
||||
#@clicked_buttons = []
|
||||
@clicked_buttons = Array(FormContent::Button).new
|
||||
#@page = page
|
||||
#@mech = mech
|
||||
|
||||
|
@ -115,6 +115,10 @@ class MechanizeCr::Form
|
|||
end
|
||||
end
|
||||
|
||||
@clicked_buttons.each do |b|
|
||||
successful_controls << b
|
||||
end
|
||||
|
||||
successful_controls.each do |ctrl|
|
||||
value = ctrl.query_value
|
||||
next if value[0] == ""
|
||||
|
@ -122,4 +126,18 @@ class MechanizeCr::Form
|
|||
end
|
||||
query
|
||||
end
|
||||
|
||||
# This method adds a button to the query. If the form needs to be
|
||||
# submitted with multiple buttons, pass each button to this method.
|
||||
private def add_button_to_query(button)
|
||||
unless button.node == @node
|
||||
message =
|
||||
"#{button.inspect} does not belong to the same page as " \
|
||||
"the form #{@name.inspect} in #{@page.uri}"
|
||||
|
||||
raise ArgumentError, message
|
||||
end
|
||||
|
||||
@clicked_buttons << button
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue