# `Playwright.Mouse`
[🔗](https://github.com/ftes/playwright_ex/blob/v1.65.0-rc.3/lib/playwright/api/mouse.ex#L7)

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

> #### Tip {: .tip}
>
> If you want to debug where the mouse moved, you can use the [Trace viewer](https://playwright.dev/docs/trace-viewer-intro) or [Playwright Inspector](https://playwright.dev/docs/running-tests). 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 `Playwright.Page.mouse/1`.

```elixir
# Using Page.mouse/1 to trace a 100x100 square.
mouse = Page.mouse(page)
Mouse.move!(mouse, 0, 0)
Mouse.down!(mouse)
Mouse.move!(mouse, 0, 100)
Mouse.move!(mouse, 100, 100)
Mouse.move!(mouse, 100, 0)
Mouse.move!(mouse, 0, 0)
Mouse.up!(mouse)
```

*Since Playwright 1.8.*

The examples alias the modules they use (`alias Playwright.{Locator, Page}`).

# `click_options`

```elixir
@type click_options() ::
  [button: :left | :right | :middle, click_count: integer(), delay: number()]
  | %{
      optional(:button) =&gt; :left | :right | :middle,
      optional(:click_count) =&gt; integer(),
      optional(:delay) =&gt; number()
    }
```

Options of `click/4`, see its docs.

# `dblclick_options`

```elixir
@type dblclick_options() ::
  [button: :left | :right | :middle, delay: number()]
  | %{
      optional(:button) =&gt; :left | :right | :middle,
      optional(:delay) =&gt; number()
    }
```

Options of `dblclick/4`, see its docs.

# `down_options`

```elixir
@type down_options() ::
  [button: :left | :right | :middle, click_count: integer()]
  | %{
      optional(:button) =&gt; :left | :right | :middle,
      optional(:click_count) =&gt; integer()
    }
```

Options of `down/2`, see its docs.

# `move_options`

```elixir
@type move_options() :: [{:steps, integer()}] | %{optional(:steps) =&gt; integer()}
```

Options of `move/4`, see its docs.

# `t`

```elixir
@type t() :: %Playwright.Mouse{_page: term()}
```

A `Mouse` handle. Compare handles with `==`, their fields are internal.

# `up_options`

```elixir
@type up_options() ::
  [button: :left | :right | :middle, click_count: integer()]
  | %{
      optional(:button) =&gt; :left | :right | :middle,
      optional(:click_count) =&gt; integer()
    }
```

Options of `up/2`, see its docs.

# `click`

```elixir
@spec click(t(), number(), number(), click_options()) ::
  :ok | {:error, Playwright.error()}
```

Shortcut for `Playwright.Mouse.move/4`, `Playwright.Mouse.down/2`, `Playwright.Mouse.up/2`.

*Since Playwright 1.8.*

## Arguments

* `x` - X coordinate relative to the main frame's viewport in CSS pixels.
* `y` - Y coordinate relative to the main frame's viewport in CSS pixels.

## Options

* `:button` (`:left` | `:right` | `:middle`) - Defaults to `:left`.
* `:click_count` (`t:integer/0`) - defaults to 1. See [`UIEvent.detail`](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail).
* `:delay` (`t:number/0`) - Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.

# `click!`

```elixir
@spec click!(t(), number(), number(), click_options()) :: :ok
```

Like `click/4`, but returns the value and raises on error.

# `dblclick`

```elixir
@spec dblclick(t(), number(), number(), dblclick_options()) ::
  :ok | {:error, Playwright.error()}
```

Shortcut for `Playwright.Mouse.move/4`, `Playwright.Mouse.down/2`, `Playwright.Mouse.up/2`, `Playwright.Mouse.down/2` and
`Playwright.Mouse.up/2`.

*Since Playwright 1.8.*

## Arguments

* `x` - X coordinate relative to the main frame's viewport in CSS pixels.
* `y` - Y coordinate relative to the main frame's viewport in CSS pixels.

## Options

* `:button` (`:left` | `:right` | `:middle`) - Defaults to `:left`.
* `:delay` (`t:number/0`) - Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0.

# `dblclick!`

```elixir
@spec dblclick!(t(), number(), number(), dblclick_options()) :: :ok
```

Like `dblclick/4`, but returns the value and raises on error.

# `down`

```elixir
@spec down(t(), down_options()) :: :ok | {:error, Playwright.error()}
```

Dispatches a `mousedown` event.

*Since Playwright 1.8.*

## Options

* `:button` (`:left` | `:right` | `:middle`) - Defaults to `:left`.
* `:click_count` (`t:integer/0`) - defaults to 1. See [`UIEvent.detail`](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail).

# `down!`

```elixir
@spec down!(t(), down_options()) :: :ok
```

Like `down/2`, but returns the value and raises on error.

# `move`

```elixir
@spec move(t(), number(), number(), move_options()) ::
  :ok | {:error, Playwright.error()}
```

Dispatches a `mousemove` event.

*Since Playwright 1.8.*

## Arguments

* `x` - X coordinate relative to the main frame's viewport in CSS pixels.
* `y` - Y coordinate relative to the main frame's viewport in CSS pixels.

## Options

* `:steps` (`t:integer/0`) - Defaults to 1. Sends `n` interpolated `mousemove` events to represent travel between Playwright's current cursor position and the provided destination. When set to 1, emits a single `mousemove` event at the destination location.

# `move!`

```elixir
@spec move!(t(), number(), number(), move_options()) :: :ok
```

Like `move/4`, but returns the value and raises on error.

# `up`

```elixir
@spec up(t(), up_options()) :: :ok | {:error, Playwright.error()}
```

Dispatches a `mouseup` event.

*Since Playwright 1.8.*

## Options

* `:button` (`:left` | `:right` | `:middle`) - Defaults to `:left`.
* `:click_count` (`t:integer/0`) - defaults to 1. See [`UIEvent.detail`](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail).

# `up!`

```elixir
@spec up!(t(), up_options()) :: :ok
```

Like `up/2`, but returns the value and raises on error.

# `wheel`

```elixir
@spec wheel(t(), number(), number()) :: :ok | {:error, Playwright.error()}
```

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

> #### Note {: .info}
>
> Wheel events may cause scrolling if they are not handled, and this method does not
> wait for the scrolling to finish before returning.

*Since Playwright 1.15.*

## Arguments

* `delta_x` - Pixels to scroll horizontally.
* `delta_y` - Pixels to scroll vertically.

# `wheel!`

```elixir
@spec wheel!(t(), number(), number()) :: :ok
```

Like `wheel/3`, but returns the value and raises on error.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
