Class: Capybara::Poltergeist::Node
- Inherits:
-
Driver::Node
- Object
- Driver::Node
- Capybara::Poltergeist::Node
- Defined in:
- lib/capybara/poltergeist/node.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#page_id ⇒ Object
readonly
Returns the value of attribute page_id.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](name) ⇒ Object
- #all_text ⇒ Object
- #as_json ⇒ Object private
- #attributes ⇒ Object
- #browser ⇒ Object
- #checked? ⇒ Boolean
- #click(keys = [], offset = {}) ⇒ Object
- #command(name, *args) ⇒ Object
- #disabled? ⇒ Boolean
- #double_click(keys = [], offset = {}) ⇒ Object
- #drag_by(x, y) ⇒ Object
- #drag_to(other) ⇒ Object
- #find(method, selector) ⇒ Object
- #find_css(selector) ⇒ Object
- #find_xpath(selector) ⇒ Object
- #hover ⇒ Object
-
#initialize(driver, page_id, id) ⇒ Node
constructor
A new instance of Node.
- #parents ⇒ Object
- #path ⇒ Object
- #property(name) ⇒ Object
- #right_click(keys = [], offset = {}) ⇒ Object
- #select_option ⇒ Object
- #selected? ⇒ Boolean
- #send_keys(*keys) ⇒ Object (also: #send_key)
- #set(value, options = {}) ⇒ Object
- #tag_name ⇒ Object
- #to_json ⇒ Object private
- #trigger(event) ⇒ Object
- #unselect_option ⇒ Object
- #value ⇒ Object
- #visible? ⇒ Boolean
- #visible_text ⇒ Object
Constructor Details
#initialize(driver, page_id, id) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 12 |
# File 'lib/capybara/poltergeist/node.rb', line 7 def initialize(driver, page_id, id) super(driver, self) @page_id = page_id @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/capybara/poltergeist/node.rb', line 5 def id @id end |
#page_id ⇒ Object (readonly)
Returns the value of attribute page_id.
5 6 7 |
# File 'lib/capybara/poltergeist/node.rb', line 5 def page_id @page_id end |
Instance Method Details
#==(other) ⇒ Object
170 171 172 |
# File 'lib/capybara/poltergeist/node.rb', line 170 def ==(other) (page_id == other.page_id) && command(:equals, other.id) end |
#[](name) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/capybara/poltergeist/node.rb', line 67 def [](name) # Although the attribute matters, the property is consistent. Return that in # preference to the attribute for links and images. if (tag_name == 'img' and name == 'src') or (tag_name == 'a' and name == 'href' ) #if attribute exists get the property value = command(:attribute, name) && command(:property, name) return value end value = property(name) value = command(:attribute, name) if value.nil? || value.is_a?(Hash) value end |
#all_text ⇒ Object
47 48 49 |
# File 'lib/capybara/poltergeist/node.rb', line 47 def all_text filter_text command(:all_text) end |
#as_json ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
189 190 191 |
# File 'lib/capybara/poltergeist/node.rb', line 189 def as_json(*) { ELEMENT: {page_id: @page_id, id: @id} } end |
#attributes ⇒ Object
82 83 84 |
# File 'lib/capybara/poltergeist/node.rb', line 82 def attributes command :attributes end |
#browser ⇒ Object
14 15 16 |
# File 'lib/capybara/poltergeist/node.rb', line 14 def browser driver.browser end |
#checked? ⇒ Boolean
130 131 132 |
# File 'lib/capybara/poltergeist/node.rb', line 130 def checked? self[:checked] end |
#click(keys = [], offset = {}) ⇒ Object
142 143 144 |
# File 'lib/capybara/poltergeist/node.rb', line 142 def click(keys=[], offset={}) command :click, keys, offset end |
#command(name, *args) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/capybara/poltergeist/node.rb', line 18 def command(name, *args) browser.send(name, page_id, id, *args) rescue BrowserError => error case error.name when 'Poltergeist.ObsoleteNode' raise ObsoleteNode.new(self, error.response) when 'Poltergeist.MouseEventFailed' raise MouseEventFailed.new(self, error.response) else raise end end |
#disabled? ⇒ Boolean
138 139 140 |
# File 'lib/capybara/poltergeist/node.rb', line 138 def disabled? command :disabled? end |
#double_click(keys = [], offset = {}) ⇒ Object
150 151 152 |
# File 'lib/capybara/poltergeist/node.rb', line 150 def double_click(keys=[], offset={}) command :double_click, keys, offset end |
#drag_by(x, y) ⇒ Object
162 163 164 |
# File 'lib/capybara/poltergeist/node.rb', line 162 def drag_by(x, y) command :drag_by, x, y end |
#drag_to(other) ⇒ Object
158 159 160 |
# File 'lib/capybara/poltergeist/node.rb', line 158 def drag_to(other) command :drag, other.id end |
#find(method, selector) ⇒ Object
35 36 37 |
# File 'lib/capybara/poltergeist/node.rb', line 35 def find(method, selector) command(:find_within, method, selector).map { |id| self.class.new(driver, page_id, id) } end |
#find_css(selector) ⇒ Object
43 44 45 |
# File 'lib/capybara/poltergeist/node.rb', line 43 def find_css(selector) find :css, selector end |
#find_xpath(selector) ⇒ Object
39 40 41 |
# File 'lib/capybara/poltergeist/node.rb', line 39 def find_xpath(selector) find :xpath, selector end |
#hover ⇒ Object
154 155 156 |
# File 'lib/capybara/poltergeist/node.rb', line 154 def hover command :hover end |
#parents ⇒ Object
31 32 33 |
# File 'lib/capybara/poltergeist/node.rb', line 31 def parents command(:parents).map { |parent_id| self.class.new(driver, page_id, parent_id) } end |
#path ⇒ Object
179 180 181 |
# File 'lib/capybara/poltergeist/node.rb', line 179 def path command :path end |
#property(name) ⇒ Object
63 64 65 |
# File 'lib/capybara/poltergeist/node.rb', line 63 def property(name) command :property, name end |
#right_click(keys = [], offset = {}) ⇒ Object
146 147 148 |
# File 'lib/capybara/poltergeist/node.rb', line 146 def right_click(keys=[], offset={}) command :right_click, keys, offset end |
#select_option ⇒ Object
113 114 115 |
# File 'lib/capybara/poltergeist/node.rb', line 113 def select_option command :select, true end |
#selected? ⇒ Boolean
134 135 136 |
# File 'lib/capybara/poltergeist/node.rb', line 134 def selected? !!self[:selected] end |
#send_keys(*keys) ⇒ Object Also known as: send_key
174 175 176 |
# File 'lib/capybara/poltergeist/node.rb', line 174 def send_keys(*keys) command :send_keys, keys end |
#set(value, options = {}) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/capybara/poltergeist/node.rb', line 90 def set(value, = {}) warn "Options passed to Node#set but Poltergeist doesn't currently support any - ignoring" unless .empty? if tag_name == 'input' case self[:type] when 'radio' click when 'checkbox' click if value != checked? when 'file' files = value.respond_to?(:to_ary) ? value.to_ary.map(&:to_s) : value.to_s command :select_file, files else command :set, value.to_s end elsif tag_name == 'textarea' command :set, value.to_s elsif self[:isContentEditable] command :delete_text send_keys(value.to_s) end end |
#tag_name ⇒ Object
122 123 124 |
# File 'lib/capybara/poltergeist/node.rb', line 122 def tag_name @tag_name ||= command(:tag_name) end |
#to_json ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
184 185 186 |
# File 'lib/capybara/poltergeist/node.rb', line 184 def to_json(*) JSON.generate as_json end |
#trigger(event) ⇒ Object
166 167 168 |
# File 'lib/capybara/poltergeist/node.rb', line 166 def trigger(event) command :trigger, event end |
#unselect_option ⇒ Object
117 118 119 120 |
# File 'lib/capybara/poltergeist/node.rb', line 117 def unselect_option command(:select, false) or raise(Capybara::UnselectNotAllowed, "Cannot unselect option from single select box.") end |
#value ⇒ Object
86 87 88 |
# File 'lib/capybara/poltergeist/node.rb', line 86 def value command :value end |
#visible? ⇒ Boolean
126 127 128 |
# File 'lib/capybara/poltergeist/node.rb', line 126 def visible? command :visible? end |
#visible_text ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/capybara/poltergeist/node.rb', line 51 def visible_text if Capybara::VERSION.to_f < 3.0 filter_text command(:visible_text) else command(:visible_text).to_s .gsub(/\A[[:space:]&&[^\u00a0]]+/, "") .gsub(/[[:space:]&&[^\u00a0]]+\z/, "") .gsub(/\n+/, "\n") .tr("\u00a0", ' ') end end |