Class: Capybara::Driver::Celerity::Node
- Inherits:
-
Node
- Object
- Node
- Capybara::Driver::Celerity::Node
- Defined in:
- lib/capybara/driver/celerity.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #checked? ⇒ Boolean
- #click ⇒ Object
- #drag_to(element) ⇒ Object
- #find(locator) ⇒ Object
- #path ⇒ Object
- #select_option ⇒ Object
- #selected? ⇒ Boolean
- #set(value) ⇒ Object
- #tag_name ⇒ Object
- #text ⇒ Object
- #trigger(event) ⇒ Object
- #unselect_option ⇒ Object
- #value ⇒ Object
- #visible? ⇒ Boolean
Instance Method Details
#[](name) ⇒ Object
7 8 9 10 |
# File 'lib/capybara/driver/celerity.rb', line 7 def [](name) value = native.attribute_value(name.to_sym) return value if value and not value.to_s.empty? end |
#checked? ⇒ Boolean
59 60 61 62 63 |
# File 'lib/capybara/driver/celerity.rb', line 59 def checked? native.checked? rescue # https://github.com/langalex/culerity/issues/issue/33 false end |
#click ⇒ Object
39 40 41 |
# File 'lib/capybara/driver/celerity.rb', line 39 def click native.click end |
#drag_to(element) ⇒ Object
43 44 45 46 47 |
# File 'lib/capybara/driver/celerity.rb', line 43 def drag_to(element) native.fire_event('mousedown') element.native.fire_event('mousemove') element.native.fire_event('mouseup') end |
#find(locator) ⇒ Object
79 80 81 82 83 |
# File 'lib/capybara/driver/celerity.rb', line 79 def find(locator) noko_node = Nokogiri::HTML(driver.body).xpath(native.xpath).first all_nodes = noko_node.xpath(locator).map { |n| n.path }.join(' | ') if all_nodes.empty? then [] else driver.find(all_nodes) end end |
#path ⇒ Object
71 72 73 |
# File 'lib/capybara/driver/celerity.rb', line 71 def path native.xpath end |
#select_option ⇒ Object
24 25 26 |
# File 'lib/capybara/driver/celerity.rb', line 24 def select_option native.click end |
#selected? ⇒ Boolean
65 66 67 68 69 |
# File 'lib/capybara/driver/celerity.rb', line 65 def selected? native.selected? rescue # https://github.com/langalex/culerity/issues/issue/33 false end |
#set(value) ⇒ Object
20 21 22 |
# File 'lib/capybara/driver/celerity.rb', line 20 def set(value) native.set(value) end |
#tag_name ⇒ Object
49 50 51 52 53 |
# File 'lib/capybara/driver/celerity.rb', line 49 def tag_name # FIXME: this might be the dumbest way ever of getting the tag name # there has to be something better... native.to_xml[/^\s*<([a-z0-9\-\:]+)/, 1] end |
#text ⇒ Object
3 4 5 |
# File 'lib/capybara/driver/celerity.rb', line 3 def text native.text end |
#trigger(event) ⇒ Object
75 76 77 |
# File 'lib/capybara/driver/celerity.rb', line 75 def trigger(event) native.fire_event(event.to_s) end |
#unselect_option ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/capybara/driver/celerity.rb', line 28 def unselect_option unless select_node.native.multiple? raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box." end # FIXME: couldn't find a clean way to unselect, so clear and reselect selected_nodes = select_node.find('.//option[@selected]') select_node.native.clear selected_nodes.each { |n| n.click unless n.path == path } end |
#value ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/capybara/driver/celerity.rb', line 12 def value if tag_name == "select" and native.multiple? find(".//option[@selected]").map { |n| if n.has_value? then n.value else n.text end } else native.value end end |
#visible? ⇒ Boolean
55 56 57 |
# File 'lib/capybara/driver/celerity.rb', line 55 def visible? native.visible? end |