Class: Ferrum::Mouse
- Inherits:
-
Object
- Object
- Ferrum::Mouse
- Defined in:
- lib/ferrum/mouse.rb
Constant Summary collapse
- VALID_BUTTONS =
%w[none left middle right back forward].freeze
Instance Method Summary collapse
- #click(x:, y:, delay: 0, timeout: 0, **options) ⇒ Object
- #down(**options) ⇒ Object
-
#initialize(page) ⇒ Mouse
constructor
A new instance of Mouse.
-
#move(x:, y:, steps: 1) ⇒ Object
FIXME: steps.
- #up(**options) ⇒ Object
Constructor Details
#initialize(page) ⇒ Mouse
Returns a new instance of Mouse.
7 8 9 10 |
# File 'lib/ferrum/mouse.rb', line 7 def initialize(page) @page = page @x = @y = 0 end |
Instance Method Details
#click(x:, y:, delay: 0, timeout: 0, **options) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ferrum/mouse.rb', line 12 def click(x:, y:, delay: 0, timeout: 0, **) move(x: x, y: y) down(**) sleep(delay) # Potential wait because if network event is triggered then we have to wait until it's over. up(timeout: timeout, **) self end |
#down(**options) ⇒ Object
21 22 23 |
# File 'lib/ferrum/mouse.rb', line 21 def down(**) tap { mouse_event(type: "mousePressed", **) } end |
#move(x:, y:, steps: 1) ⇒ Object
FIXME: steps
30 31 32 33 34 |
# File 'lib/ferrum/mouse.rb', line 30 def move(x:, y:, steps: 1) @x, @y = x, y @page.command("Input.dispatchMouseEvent", type: "mouseMoved", x: @x, y: @y) self end |
#up(**options) ⇒ Object
25 26 27 |
# File 'lib/ferrum/mouse.rb', line 25 def up(**) tap { mouse_event(type: "mouseReleased", **) } end |