Module: Selenium::WebDriver::PointerActions
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb |
Instance Attribute Summary
-
#default_move_duration
rw
By default this is set to 250ms in the
ActionBuilder
constructor It can be overridden with default_move_duration=. - #default_move_duration=(value) rw
Instance Method Summary
-
#click(element = nil, button: nil, device: nil) ⇒ ActionBuilder
Clicks in the middle of the given element.
-
#click_and_hold(element = nil, button: nil, device: nil) ⇒ ActionBuilder
Clicks (without releasing) in the middle of the given element.
-
#context_click(element = nil, device: nil) ⇒ ActionBuilder
Performs a context-click at middle of the given element.
-
#double_click(element = nil, device: nil) ⇒ ActionBuilder
Performs a double-click at middle of the given element.
-
#drag_and_drop(source, target, device: nil) ⇒ ActionBuilder
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) ⇒ ActionBuilder
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, duration: default_move_duration, **opts) ⇒ ActionBuilder
Moves the pointer from its current position by the given offset.
-
#move_to(element, right_by = nil, down_by = nil, **opts) ⇒ ActionBuilder
Moves the pointer to the in-view center point of the given element.
-
#move_to_location(x, y, device: nil, duration: default_move_duration, **opts) ⇒ ActionBuilder
Moves the pointer to a given location in the viewport.
-
#pointer_down(button = :left, device: nil, **opts) ⇒ ActionBuilder
Presses (without releasing) at the current location of the PointerInput device.
-
#pointer_up(button = :left, device: nil, **opts) ⇒ ActionBuilder
Releases the pressed mouse button at the current mouse location of the PointerInput device.
-
#release(button: nil, device: nil) ⇒ ActionBuilder
Releases the depressed left mouse button at the current mouse location.
- #button_action(button, action, device: nil, **opts) private
- #pointer_input(name = nil) private
Instance Attribute Details
#default_move_duration (rw)
By default this is set to 250ms in the ActionBuilder
constructor It can be overridden with default_move_duration=
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 30
def default_move_duration @default_move_duration ||= @duration / 1000.0 # convert ms to seconds end
#default_move_duration=(value) (rw)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 23
attr_writer :default_move_duration
Instance Method Details
#button_action(button, action, device: nil, **opts) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 339
def (, action, device: nil, **opts) pointer = pointer_input(device) pointer.send(action, , **opts) tick(pointer) self end
#click(element = nil, button: nil, device: nil) ⇒ ActionBuilder
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.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 226
def click(element = nil, button: 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, button: nil, device: nil) ⇒ ActionBuilder
Clicks (without releasing) in the middle of the given element. This is equivalent to:
driver.action.move_to(element).click_and_hold
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 180
def click_and_hold(element = nil, button: nil, device: nil) move_to(element, device: device) if element pointer_down( || :left, device: device) self end
#context_click(element = nil, device: nil) ⇒ ActionBuilder
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.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 283
def context_click(element = nil, device: nil) click(element, button: :right, device: device) end
#double_click(element = nil, device: nil) ⇒ ActionBuilder
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.
#drag_and_drop(source, target, device: nil) ⇒ ActionBuilder
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.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 306
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) ⇒ ActionBuilder
A convenience method that performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 330
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, duration: default_move_duration, **opts) ⇒ ActionBuilder
Moves the pointer from its current position by the given offset.
The viewport is not scrolled if the coordinates provided are outside the viewport. MoveTargetOutOfBoundsError will be raised if the offsets are outside the viewport
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 125
def move_by(right_by, down_by, device: nil, duration: default_move_duration, **opts) pointer = pointer_input(device) pointer.create_pointer_move(duration: duration, x: Integer(right_by), y: Integer(down_by), origin: Interactions::PointerMove::POINTER, **opts) tick(pointer) self end
#move_to(element, right_by = nil, down_by = nil, **opts) ⇒ ActionBuilder
Moves the pointer to the in-view center point of the given element. Then the pointer is moved to optional offset coordinates.
The element is not scrolled into view. MoveTargetOutOfBoundsError will be raised if element with offset is outside the viewport
When using offsets, both coordinates need to be passed.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 97
def move_to(element, right_by = nil, down_by = nil, **opts) pointer = pointer_input(opts.delete(:device)) pointer.create_pointer_move(duration: opts.delete(:duration) || default_move_duration, x: right_by || 0, y: down_by || 0, origin: element, **opts) tick(pointer) self end
#move_to_location(x, y, device: nil, duration: default_move_duration, **opts) ⇒ ActionBuilder
Moves the pointer to a given location in the viewport.
The viewport is not scrolled if the coordinates provided are outside the viewport. MoveTargetOutOfBoundsError will be raised if the offsets are outside the viewport
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 153
def move_to_location(x, y, device: nil, duration: default_move_duration, **opts) pointer = pointer_input(device) pointer.create_pointer_move(duration: duration, x: Integer(x), y: Integer(y), origin: Interactions::PointerMove::VIEWPORT, **opts) tick(pointer) self end
#pointer_down(button = :left, device: nil, **opts) ⇒ ActionBuilder
Presses (without releasing) at the current location of the PointerInput device. This is equivalent to:
driver.action.click_and_hold(nil)
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 49
def pointer_down( = :left, device: nil, **opts) (, :create_pointer_down, device: device, **opts) end
#pointer_input(name = nil) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 346
def pointer_input(name = nil) device(name: name, type: Interactions::POINTER) || add_pointer_input(:mouse, 'mouse') end
#pointer_up(button = :left, device: nil, **opts) ⇒ ActionBuilder
Releases the pressed mouse button at the current mouse location of the PointerInput device.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 66
def pointer_up( = :left, device: nil, **opts) (, :create_pointer_up, device: device, **opts) end
#release(button: nil, device: nil) ⇒ ActionBuilder
Releases the depressed left mouse button at the current mouse location.
# File 'rb/lib/selenium/webdriver/common/interactions/pointer_actions.rb', line 199
def release(button: nil, device: nil) pointer_up( || :left, device: device) self end