Class: Mechanize::Page::Button
- Inherits:
-
Object
- Object
- Mechanize::Page::Button
- Defined in:
- lib/mech_js/page/button.rb
Overview
The button class has been designed around usign javascripts events to figure out where mech should be sent
Instance Attribute Summary collapse
-
#mech ⇒ Object
Returns the value of attribute mech.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#dom_id ⇒ Object
This method is a shortcut to get form’s DOM id.
-
#initialize(node, page) ⇒ Button
constructor
Creates a new Mechanize::Page::Button from an button
node
and sourcepage
. -
#js_click ⇒ Object
This method will use use the location.href from the onclick attribute to construct a get method on the agent.
-
#text ⇒ Object
This method uses the text of the button.
Constructor Details
#initialize(node, page) ⇒ Button
Creates a new Mechanize::Page::Button from an button node
and source page
.
15 16 17 18 19 |
# File 'lib/mech_js/page/button.rb', line 15 def initialize node, page @node = node @page = page @mech = page.mech end |
Instance Attribute Details
#mech ⇒ Object
Returns the value of attribute mech.
9 10 11 |
# File 'lib/mech_js/page/button.rb', line 9 def mech @mech end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/mech_js/page/button.rb', line 7 def node @node end |
#page ⇒ Object
Returns the value of attribute page.
8 9 10 |
# File 'lib/mech_js/page/button.rb', line 8 def page @page end |
Instance Method Details
#dom_id ⇒ Object
This method is a shortcut to get form’s DOM id. Common usage:
page.(:dom_id => "submit-btn")
Note that you can also use :id
to get to this method:
page.(:id => "submit-btn")
27 28 29 |
# File 'lib/mech_js/page/button.rb', line 27 def dom_id node['id'] end |
#js_click ⇒ Object
This method will use use the location.href from the onclick attribute to construct a get method on the agent.
42 43 44 45 46 |
# 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 ⇒ Object
This method uses the text of the button. Common usage:
page.(:text => "Cancel")
35 36 37 |
# File 'lib/mech_js/page/button.rb', line 35 def text @node.inner_text.strip end |