class Mechanize::Page::Button
The button class has been designed around usign javascripts events to figure out where mech should be sent
Attributes
mech[RW]
node[R]
page[RW]
Public Class Methods
new(node, page)
click to toggle source
Creates a new Mechanize::Page::Button
from an button node
and source page
.
# File lib/mech_js/page/button.rb, line 15 def initialize node, page @node = node @page = page @mech = page.mech end
Public Instance Methods
dom_id()
click to toggle source
This method is a shortcut to get form's DOM id. Common usage:
page.button_with(:dom_id => "submit-btn")
Note that you can also use :id
to get to this method:
page.button_with(:id => "submit-btn")
# File lib/mech_js/page/button.rb, line 27 def dom_id node['id'] end
js_click()
click to toggle source
This method will use use the location.href from the onclick attribute to construct a get method on the agent.
# File lib/mech_js/page/button.rb, line 42 def js_click href = node.attributes['onclick'].to_s.match(/location.href='(.*)'/)[1] full_uri = URI::HTTP.build({scheme: page.uri.scheme, host: page.uri.host, path: href}) mech.get(full_uri) end
text()
click to toggle source
This method uses the text of the button. Common usage:
page.button_with(:text => "Cancel")
# File lib/mech_js/page/button.rb, line 35 def text @node.inner_text.strip end