add clicked buttons

This commit is contained in:
Kanezoh 2021-06-29 17:46:52 +09:00
parent b4c5e33037
commit dc9f937ccc
2 changed files with 21 additions and 2 deletions

View File

@ -68,7 +68,8 @@ class Mechanize
@agent.history.pop @agent.history.pop
end end
def submit(form) def submit(form, button=nil)
form.add_button_to_query(button) if button
case form.method.upcase case form.method.upcase
when "POST" when "POST"
post_form(form.action, form, request_headers) post_form(form.action, form, request_headers)

View File

@ -29,7 +29,7 @@ class MechanizeCr::Form
@action = node.fetch("action", "") @action = node.fetch("action", "")
@method = node.fetch("method", "GET").upcase @method = node.fetch("method", "GET").upcase
@name = node.fetch("name", "") @name = node.fetch("name", "")
#@clicked_buttons = [] @clicked_buttons = Array(FormContent::Button).new
#@page = page #@page = page
#@mech = mech #@mech = mech
@ -115,6 +115,10 @@ class MechanizeCr::Form
end end
end end
@clicked_buttons.each do |b|
successful_controls << b
end
successful_controls.each do |ctrl| successful_controls.each do |ctrl|
value = ctrl.query_value value = ctrl.query_value
next if value[0] == "" next if value[0] == ""
@ -122,4 +126,18 @@ class MechanizeCr::Form
end end
query query
end 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 end