Class: Capybara::Webkit::Node

Inherits:
Driver::Node
  • Object
show all
Defined in:
lib/capybara/webkit/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(driver, base, browser) ⇒ Node

Returns a new instance of Node.



3
4
5
6
# File 'lib/capybara/webkit/node.rb', line 3

def initialize(driver, base, browser)
  super(driver, base)
  @browser = browser
end

Instance Method Details

#==(other) ⇒ Object



168
169
170
# File 'lib/capybara/webkit/node.rb', line 168

def ==(other)
  invoke("equals", other.native)
end

#[](name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/capybara/webkit/node.rb', line 17

def [](name)
  name = name.to_s
  tn = tag_name
  if (tn == "img" && name == "src") || (tn == "a" && name == "href")
    # Although the attribute matters, the property is consistent. Return that in
    # preference to the attribute for links and images.
    # if attribute exists get the property
    val = invoke(:attribute, name) && invoke(:property, name)
  else
    val = invoke(:property, name)
    val = invoke(:attribute, name) if val.nil? || val.is_a?(Hash)
  end
  val
end

#all_textObject



13
14
15
# File 'lib/capybara/webkit/node.rb', line 13

def all_text
  Capybara::Helpers.normalize_whitespace(invoke("allText"))
end

#allow_unattached_nodes?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/capybara/webkit/node.rb', line 149

def allow_unattached_nodes?
  !automatic_reload?
end

#attached?Boolean

Returns:

  • (Boolean)


157
158
159
160
161
162
# File 'lib/capybara/webkit/node.rb', line 157

def attached?
  warn "[DEPRECATION] The Capybara::Webkit::Node#attached? " \
    "method is deprecated without replacement."
  result = @browser.command("Node", "isAttached", native)
  JSON.parse(result, quirks_mode: true)
end

#automatic_reload?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/capybara/webkit/node.rb', line 153

def automatic_reload?
  session_option(:automatic_reload)
end

#checked?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/capybara/webkit/node.rb', line 104

def checked?
  !!self["checked"]
end

#click(keys = [], offset = {}) ⇒ Object



72
73
74
# File 'lib/capybara/webkit/node.rb', line 72

def click(keys = [], offset = {})
  invoke("leftClick", keys.to_json, offset.to_json)
end

#disabled?Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
114
115
116
# File 'lib/capybara/webkit/node.rb', line 108

def disabled?
  xpath = "parent::optgroup[@disabled] | " \
    "ancestor::select[@disabled] | " \
    "parent::fieldset[@disabled] | " \
    "ancestor::*[not(self::legend) or " \
    "preceding-sibling::legend][parent::fieldset[@disabled]]"

  self["disabled"] || !find_xpath(xpath).empty?
end

#double_click(keys = [], offset = {}) ⇒ Object



76
77
78
# File 'lib/capybara/webkit/node.rb', line 76

def double_click(keys = [], offset = {})
  invoke("doubleClick", keys.to_json, offset.to_json)
end

#drag_to(element) ⇒ Object



88
89
90
# File 'lib/capybara/webkit/node.rb', line 88

def drag_to(element)
  invoke 'dragTo', element.native
end

#find_css(selector) ⇒ Object



138
139
140
141
142
# File 'lib/capybara/webkit/node.rb', line 138

def find_css(selector)
  invoke("findCssWithin", selector).split(',').map do |native|
    self.class.new(driver, native, @browser)
  end
end

#find_xpath(xpath) ⇒ Object Also known as: find



130
131
132
133
134
# File 'lib/capybara/webkit/node.rb', line 130

def find_xpath(xpath)
  invoke("findXpathWithin", xpath).split(',').map do |native|
    self.class.new(driver, native, @browser)
  end
end

#hoverObject



84
85
86
# File 'lib/capybara/webkit/node.rb', line 84

def hover
  invoke("hover")
end

#inner_htmlObject



40
41
42
# File 'lib/capybara/webkit/node.rb', line 40

def inner_html
  invoke 'getInnerHTML'
end

#inner_html=(value) ⇒ Object



44
45
46
# File 'lib/capybara/webkit/node.rb', line 44

def inner_html=(value)
  invoke 'setInnerHTML', value
end

#invoke(name, *args) ⇒ Object



144
145
146
147
# File 'lib/capybara/webkit/node.rb', line 144

def invoke(name, *args)
  result = @browser.command "Node", name, allow_unattached_nodes?, native, *args
  JSON.parse(result, quirks_mode: true)
end

#multiple_select?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/capybara/webkit/node.rb', line 164

def multiple_select?
  self.tag_name == "select" && self["multiple"]
end

#pathObject



118
119
120
# File 'lib/capybara/webkit/node.rb', line 118

def path
  invoke "path"
end

#right_click(keys = [], offset = {}) ⇒ Object



80
81
82
# File 'lib/capybara/webkit/node.rb', line 80

def right_click(keys = [], offset = {})
  invoke("rightClick", keys.to_json, offset.to_json)
end

#select_optionObject



59
60
61
# File 'lib/capybara/webkit/node.rb', line 59

def select_option
  invoke "selectOption"
end

#selected?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/capybara/webkit/node.rb', line 100

def selected?
  invoke("selected") == true
end

#send_keys(*keys) ⇒ Object



53
54
55
56
57
# File 'lib/capybara/webkit/node.rb', line 53

def send_keys(*keys)
  # Currently unsupported keys specified by Capybara
  # :separator
  invoke("sendKeys", convert_to_named_keys(keys).to_json)
end

#set(value, options = {}) ⇒ Object



48
49
50
51
# File 'lib/capybara/webkit/node.rb', line 48

def set(value, options = {})
  warn "Options passed to Node#set but capybara-webkit doesn't currently support any - ignoring" unless options.empty?
  invoke "set", *[value].flatten
end

#submit(opts = {}) ⇒ Object



122
123
124
# File 'lib/capybara/webkit/node.rb', line 122

def submit(opts = {})
  invoke "submit"
end

#tag_nameObject



92
93
94
# File 'lib/capybara/webkit/node.rb', line 92

def tag_name
  invoke "tagName"
end

#trigger(event) ⇒ Object



126
127
128
# File 'lib/capybara/webkit/node.rb', line 126

def trigger(event)
  invoke "trigger", event
end

#unselect_optionObject



63
64
65
66
67
68
69
70
# File 'lib/capybara/webkit/node.rb', line 63

def unselect_option
  select = find_xpath("ancestor::select").first
  if select.multiple_select?
    invoke "unselectOption"
  else
    raise Capybara::UnselectNotAllowed
  end
end

#valueObject



32
33
34
35
36
37
38
# File 'lib/capybara/webkit/node.rb', line 32

def value
  if multiple_select?
    self.find_xpath(".//option").select(&:selected?).map(&:value)
  else
    invoke "value"
  end
end

#visible?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/capybara/webkit/node.rb', line 96

def visible?
  invoke("visible") == true
end

#visible_textObject Also known as: text



8
9
10
# File 'lib/capybara/webkit/node.rb', line 8

def visible_text
  Capybara::Helpers.normalize_whitespace(invoke("text"))
end