Class: Capybara::Driver::Webkit::Node

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

Constant Summary collapse

NBSP =
"\xC2\xA0"

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/capybara/driver/webkit/node.rb', line 10

def [](name)
  value = invoke("attribute", name)
  if name == 'checked' || name == 'disabled'
    value == 'true'
  else
    value
  end
end

#allow_unattached_nodes?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/capybara/driver/webkit/node.rb', line 98

def allow_unattached_nodes?
  !automatic_reload?
end

#attached?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/capybara/driver/webkit/node.rb', line 106

def attached?
  browser.command("Node", "isAttached", native) == "true"
end

#automatic_reload?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/capybara/driver/webkit/node.rb', line 102

def automatic_reload?
  Capybara.respond_to?(:automatic_reload) && Capybara.automatic_reload
end

#browserObject



110
111
112
# File 'lib/capybara/driver/webkit/node.rb', line 110

def browser
  driver.browser
end

#checked?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/capybara/driver/webkit/node.rb', line 64

def checked?
  self['checked']
end

#clickObject



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

def click
  invoke "click"
end

#disabled?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/capybara/driver/webkit/node.rb', line 68

def disabled?
  self['disabled']
end

#drag_to(element) ⇒ Object



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

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

#find(xpath) ⇒ Object



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

def find(xpath)
  invoke("findWithin", xpath).split(',').map do |native|
    self.class.new(driver, native)
  end
end

#invoke(name, *args) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/capybara/driver/webkit/node.rb', line 90

def invoke(name, *args)
  if allow_unattached_nodes? || attached?
    browser.command "Node", name, native, *args
  else
    raise Capybara::Driver::Webkit::NodeNotAttachedError
  end
end

#multiple_select?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/capybara/driver/webkit/node.rb', line 114

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

#pathObject



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

def path
  invoke "path"
end

#select_optionObject



31
32
33
# File 'lib/capybara/driver/webkit/node.rb', line 31

def select_option
  invoke "selectOption"
end

#selected?Boolean

Returns:

  • (Boolean)


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

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

#set(value) ⇒ Object



27
28
29
# File 'lib/capybara/driver/webkit/node.rb', line 27

def set(value)
  invoke "set", value
end

#submit(opts = {}) ⇒ Object



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

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

#tag_nameObject



52
53
54
# File 'lib/capybara/driver/webkit/node.rb', line 52

def tag_name
  invoke "tagName"
end

#textObject



6
7
8
# File 'lib/capybara/driver/webkit/node.rb', line 6

def text
  invoke("text").gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip
end

#trigger(event) ⇒ Object



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

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

#unselect_optionObject



35
36
37
38
39
40
41
42
# File 'lib/capybara/driver/webkit/node.rb', line 35

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

#valueObject



19
20
21
22
23
24
25
# File 'lib/capybara/driver/webkit/node.rb', line 19

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

#visible?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/capybara/driver/webkit/node.rb', line 56

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