Class: Playwright::Mouse

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/mouse.rb

Overview

The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.

NOTE: If you want to debug where the mouse moved, you can use the [Trace viewer](../trace-viewer-intro.md) or [Playwright Inspector](../running-tests.md). A red dot showing the location of the mouse will be shown for every mouse action.

Every ‘page` object has its own Mouse, accessible with [`property: Page.mouse`].

“‘python sync # using ‘page.mouse’ to trace a 100x100 square. page.mouse.move(0, 0) page.mouse.down() page.mouse.move(0, 100) page.mouse.move(100, 100) page.mouse.move(100, 0) page.mouse.move(0, 0) page.mouse.up() “`

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#click(x, y, button: nil, clickCount: nil, delay: nil) ⇒ Object

Shortcut for [‘method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`].



23
24
25
26
27
28
29
30
# File 'lib/playwright_api/mouse.rb', line 23

def click(
      x,
      y,
      button: nil,
      clickCount: nil,
      delay: nil)
  wrap_impl(@impl.click(unwrap_impl(x), unwrap_impl(y), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay)))
end

#dblclick(x, y, button: nil, delay: nil) ⇒ Object

Shortcut for [‘method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`], [`method: Mouse.down`] and [`method: Mouse.up`].



35
36
37
# File 'lib/playwright_api/mouse.rb', line 35

def dblclick(x, y, button: nil, delay: nil)
  wrap_impl(@impl.dblclick(unwrap_impl(x), unwrap_impl(y), button: unwrap_impl(button), delay: unwrap_impl(delay)))
end

#down(button: nil, clickCount: nil) ⇒ Object

Dispatches a ‘mousedown` event.



41
42
43
# File 'lib/playwright_api/mouse.rb', line 41

def down(button: nil, clickCount: nil)
  wrap_impl(@impl.down(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount)))
end

#move(x, y, steps: nil) ⇒ Object

Dispatches a ‘mousemove` event.



47
48
49
# File 'lib/playwright_api/mouse.rb', line 47

def move(x, y, steps: nil)
  wrap_impl(@impl.move(unwrap_impl(x), unwrap_impl(y), steps: unwrap_impl(steps)))
end

#up(button: nil, clickCount: nil) ⇒ Object

Dispatches a ‘mouseup` event.



53
54
55
# File 'lib/playwright_api/mouse.rb', line 53

def up(button: nil, clickCount: nil)
  wrap_impl(@impl.up(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount)))
end

#wheel(deltaX, deltaY) ⇒ Object

Dispatches a ‘wheel` event. This method is usually used to manually scroll the page. See [scrolling](../input.md#scrolling) for alternative ways to scroll.

NOTE: Wheel events may cause scrolling if they are not handled, and this method does not wait for the scrolling to finish before returning.



62
63
64
# File 'lib/playwright_api/mouse.rb', line 62

def wheel(deltaX, deltaY)
  wrap_impl(@impl.wheel(unwrap_impl(deltaX), unwrap_impl(deltaY)))
end