Class: Capybara::Driver::Envjs::Node
- Inherits:
-
Node
- Object
- Node
- Capybara::Driver::Envjs::Node
- Defined in:
- lib/capybara/driver/envjs_driver.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #click ⇒ Object
- #drag_to(element) ⇒ Object
- #find(locator) ⇒ Object
- #select_option ⇒ Object
- #set(value) ⇒ Object
- #tag_name ⇒ Object
- #text ⇒ Object
- #trigger(event) ⇒ Object
- #unselect_option ⇒ Object
- #value ⇒ Object
- #visible? ⇒ Boolean
Instance Method Details
#[](name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/capybara/driver/envjs_driver.rb', line 30 def [](name) attr_name = name.to_s attr_name == "class" and attr_name = "className" case when 'select' == tag_name && 'value' == attr_name if native['multiple'] find(".//option[@selected='selected']").map { |option| option.native[:value] || option.native.innerText } else native.value end else native[attr_name] end end |
#click ⇒ Object
77 78 79 |
# File 'lib/capybara/driver/envjs_driver.rb', line 77 def click _event(self,"MouseEvents",'click',true,true, :button => 1) end |
#drag_to(element) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/capybara/driver/envjs_driver.rb', line 81 def drag_to(element) # distance stuff is arbitrary at this point, to make jquery.ui happy ... _event(self,"MouseEvents",'mousedown',true,true, :button => 1, :pageX => 0, :pageY => 0) _event(element,"MouseEvents",'mousemove',true,true, :button => 1, :pageX => 1, :pageY => 1) _event(element,"MouseEvents",'mousemove',true,true, :button => 1, :pageX => 0, :pageY => 0) _event(element,"MouseEvents",'mouseup',true,true, :button => 1, :pageX => 0, :pageY => 0) end |
#find(locator) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/capybara/driver/envjs_driver.rb', line 97 def find(locator) window = @driver.browser["window"] null = @driver.browser["null"] type = window["XPathResult"]["ANY_TYPE"] result_set = window.document.evaluate(locator, native, null, type, null) nodes = [] while n = result_set.iterateNext() nodes << Node.new(@driver, n) end nodes end |
#select_option ⇒ Object
66 67 68 |
# File 'lib/capybara/driver/envjs_driver.rb', line 66 def select_option native.selected = true end |
#set(value) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/capybara/driver/envjs_driver.rb', line 53 def set(value) case native.tagName when "TEXTAREA" native.innerText = value else case native.getAttribute("type") when "checkbox", "radio" native.click if native.checked != value else; native.setAttribute("value",value) end end end |
#tag_name ⇒ Object
89 90 91 |
# File 'lib/capybara/driver/envjs_driver.rb', line 89 def tag_name native.tagName.downcase end |
#text ⇒ Object
26 27 28 |
# File 'lib/capybara/driver/envjs_driver.rb', line 26 def text native.innerText end |
#trigger(event) ⇒ Object
109 110 111 112 |
# File 'lib/capybara/driver/envjs_driver.rb', line 109 def trigger event # FIX: look up class and attributes _event(self, "", event.to_s, true, true ) end |
#unselect_option ⇒ Object
70 71 72 73 74 75 |
# File 'lib/capybara/driver/envjs_driver.rb', line 70 def unselect_option if !select_node['multiple'] raise Capybara::UnselectNotAllowed, "Cannot unselect option from single select box." end native.removeAttribute('selected') end |
#value ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/capybara/driver/envjs_driver.rb', line 45 def value if tag_name == 'textarea' native.innerText else self[:value] end end |
#visible? ⇒ Boolean
93 94 95 |
# File 'lib/capybara/driver/envjs_driver.rb', line 93 def visible? find("./ancestor-or-self::*[contains(@style, 'display:none') or contains(@style, 'display: none')]").empty? end |