Class: Capybara::Selenium::Node
Instance Attribute Summary
Attributes inherited from Driver::Node
#driver, #native
Instance Method Summary
collapse
#initialize, #inspect, #path, #trigger
Instance Method Details
#[](name) ⇒ Object
6
7
8
9
10
|
# File 'lib/capybara/selenium/node.rb', line 6
def [](name)
native.attribute(name.to_s)
rescue Selenium::WebDriver::Error::WebDriverError
nil
end
|
#click ⇒ Object
48
49
50
|
# File 'lib/capybara/selenium/node.rb', line 48
def click
resynchronize { native.click }
end
|
#drag_to(element) ⇒ Object
52
53
54
|
# File 'lib/capybara/selenium/node.rb', line 52
def drag_to(element)
resynchronize { driver.browser.action.drag_and_drop(native, element.native).perform }
end
|
#find(locator) ⇒ Object
72
73
74
|
# File 'lib/capybara/selenium/node.rb', line 72
def find(locator)
native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
end
|
#select_option ⇒ Object
37
38
39
|
# File 'lib/capybara/selenium/node.rb', line 37
def select_option
resynchronize { native.click } unless selected?
end
|
#selected? ⇒ Boolean
Also known as:
checked?
65
66
67
68
|
# File 'lib/capybara/selenium/node.rb', line 65
def selected?
selected = native.selected?
selected and selected != "false"
end
|
#set(value) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/capybara/selenium/node.rb', line 20
def set(value)
if tag_name == 'input' and type == 'radio'
click
elsif tag_name == 'input' and type == 'checkbox'
click if value ^ native.attribute('checked').to_s.eql?("true")
elsif tag_name == 'input' and type == 'file'
resynchronize do
native.send_keys(value.to_s)
end
elsif tag_name == 'textarea' or tag_name == 'input'
resynchronize do
native.clear
native.send_keys(value.to_s)
end
end
end
|
#tag_name ⇒ Object
56
57
58
|
# File 'lib/capybara/selenium/node.rb', line 56
def tag_name
native.tag_name.downcase
end
|
#text ⇒ Object
2
3
4
|
# File 'lib/capybara/selenium/node.rb', line 2
def text
native.text
end
|
#unselect_option ⇒ Object
41
42
43
44
45
46
|
# File 'lib/capybara/selenium/node.rb', line 41
def unselect_option
if select_node['multiple'] != 'multiple' and select_node['multiple'] != 'true'
raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box."
end
resynchronize { native.click } if selected?
end
|
#value ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/capybara/selenium/node.rb', line 12
def value
if tag_name == "select" and self[:multiple] and not self[:multiple] == "false"
native.find_elements(:xpath, ".//option").select { |n| n.selected? }.map { |n| n[:value] || n.text }
else
native[:value]
end
end
|
#visible? ⇒ Boolean
60
61
62
63
|
# File 'lib/capybara/selenium/node.rb', line 60
def visible?
displayed = native.displayed?
displayed and displayed != "false"
end
|