Module: Selenium::WebDriver::PointerActions
- Included in:
- W3CActionBuilder
- Defined in:
- lib/selenium/webdriver/common/interactions/pointer_actions.rb
Instance Attribute Summary collapse
-
#default_move_duration ⇒ Object
The overridable duration for movement used by methods in this module.
Instance Method Summary collapse
-
#click(element = nil, device: nil) ⇒ W3CActionBuilder
Clicks in the middle of the given element.
-
#click_and_hold(element = nil, device: nil) ⇒ W3CActionBuilder
Clicks (without releasing) in the middle of the given element.
-
#context_click(element = nil, device: nil) ⇒ W3CActionBuilder
Performs a context-click at middle of the given element.
-
#double_click(element = nil, device: nil) ⇒ W3CActionBuilder
Performs a double-click at middle of the given element.
-
#drag_and_drop(source, target, device: nil) ⇒ W3CActionBuilder
A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.
-
#drag_and_drop_by(source, right_by, down_by, device: nil) ⇒ W3CActionBuilder
A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
-
#move_by(right_by, down_by, device: nil) ⇒ W3CActionBuilder
Moves the mouse from its current position by the given offset.
-
#move_to(element, right_by = nil, down_by = nil, device: nil) ⇒ W3CActionBuilder
Moves the mouse to the middle of the given element.
-
#move_to_location(x, y, device: nil) ⇒ W3CActionBuilder
Moves the mouse to a given location in the viewport.
-
#pointer_down(button, device: nil) ⇒ W3CActionBuilder
Presses (without releasing) at the current location of the PointerInput device.
-
#pointer_up(button, device: nil) ⇒ W3CActionBuilder
Releases the pressed mouse button at the current mouse location of the PointerInput device.
-
#release(device: nil) ⇒ W3CActionBuilder
Releases the depressed left mouse button at the current mouse location.
Instance Attribute Details
#default_move_duration ⇒ Object
The overridable duration for movement used by methods in this module
29 30 31 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 29 def default_move_duration @default_move_duration ||= 0.25 # 250 milliseconds end |
Instance Method Details
#click(element = nil, device: nil) ⇒ W3CActionBuilder
Clicks in the middle of the given element. Equivalent to:
driver.action.move_to(element).click
When no element is passed, the current mouse position will be clicked.
235 236 237 238 239 240 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 235 def click(element = nil, device: nil) move_to(element, device: device) if element pointer_down(:left, device: device) pointer_up(:left, device: device) self end |
#click_and_hold(element = nil, device: nil) ⇒ W3CActionBuilder
Clicks (without releasing) in the middle of the given element. This is equivalent to:
driver.action.move_to(element).click_and_hold
189 190 191 192 193 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 189 def click_and_hold(element = nil, device: nil) move_to(element, device: device) if element pointer_down(:left, device: device) self end |
#context_click(element = nil, device: nil) ⇒ W3CActionBuilder
Performs a context-click at middle of the given element. First performs a move_to to the location of the element.
When no element is passed, the current mouse position will be context-clicked.
292 293 294 295 296 297 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 292 def context_click(element = nil, device: nil) move_to(element, device: device) if element pointer_down(:right, device: device) pointer_up(:right, device: device) self end |
#double_click(element = nil, device: nil) ⇒ W3CActionBuilder
Performs a double-click at middle of the given element. Equivalent to:
driver.action.move_to(element).double_click
When no element is passed, the current mouse position will be double-clicked.
264 265 266 267 268 269 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 264 def double_click(element = nil, device: nil) move_to(element, device: device) if element click(device: device) click(device: device) self end |
#drag_and_drop(source, target, device: nil) ⇒ W3CActionBuilder
A convenience method that performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.
318 319 320 321 322 323 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 318 def drag_and_drop(source, target, device: nil) click_and_hold(source, device: device) move_to(target, device: device) release(device: device) self end |
#drag_and_drop_by(source, right_by, down_by, device: nil) ⇒ W3CActionBuilder
A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
342 343 344 345 346 347 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 342 def drag_and_drop_by(source, right_by, down_by, device: nil) click_and_hold(source, device: device) move_by(right_by, down_by, device: device) release(device: device) self end |
#move_by(right_by, down_by, device: nil) ⇒ W3CActionBuilder
Moves the mouse from its current position by the given offset. If the coordinates provided are outside the viewport (the mouse will end up outside the browser window) then the viewport is scrolled to match.
136 137 138 139 140 141 142 143 144 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 136 def move_by(right_by, down_by, device: nil) pointer = get_pointer(device) pointer.create_pointer_move(duration: default_move_duration, x: Integer(right_by), y: Integer(down_by), origin: Interactions::PointerMove::POINTER) tick(pointer) self end |
#move_to(element, right_by = nil, down_by = nil, device: nil) ⇒ W3CActionBuilder
Moves the mouse to the middle of the given element. The element is scrolled into view and its location is calculated using getBoundingClientRect. Then the mouse is moved to optional offset coordinates from the element.
This is adapted to be backward compatible from non-W3C actions. W3C calculates offset from the center point of the element
Note that when using offsets, both coordinates need to be passed.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 98 def move_to(element, right_by = nil, down_by = nil, device: nil) pointer = get_pointer(device) # New actions offset is from center of element if right_by || down_by size = element.size left_offset = (size[:width] / 2).to_i top_offset = (size[:height] / 2).to_i left = -left_offset + (right_by || 0) top = -top_offset + (down_by || 0) else left = 0 top = 0 end pointer.create_pointer_move(duration: default_move_duration, x: left, y: top, element: element) tick(pointer) self end |
#move_to_location(x, y, device: nil) ⇒ W3CActionBuilder
Moves the mouse to a given location in the viewport. If the coordinates provided are outside the viewport (the mouse will end up outside the browser window) then the viewport is scrolled to match.
163 164 165 166 167 168 169 170 171 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 163 def move_to_location(x, y, device: nil) pointer = get_pointer(device) pointer.create_pointer_move(duration: default_move_duration, x: Integer(x), y: Integer(y), origin: Interactions::PointerMove::VIEWPORT) tick(pointer) self end |
#pointer_down(button, device: nil) ⇒ W3CActionBuilder
Presses (without releasing) at the current location of the PointerInput device. This is equivalent to:
driver.action.click_and_hold(nil)
48 49 50 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 48 def pointer_down(, device: nil) (, action: :create_pointer_down, device: device) end |
#pointer_up(button, device: nil) ⇒ W3CActionBuilder
Releases the pressed mouse button at the current mouse location of the PointerInput device.
65 66 67 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 65 def pointer_up(, device: nil) (, action: :create_pointer_up, device: device) end |
#release(device: nil) ⇒ W3CActionBuilder
Releases the depressed left mouse button at the current mouse location.
208 209 210 211 |
# File 'lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 208 def release(device: nil) pointer_up(:left, device: device) self end |