# class:mouse
### class: Mouse v0.9.0
Mouse 类在相对于视口左上角的主框架 CSS 像素中运行。
每个 `page` 对象都有它自己的 Mouse 对象,使用见 [`page.mouse`](#?product=Puppeteer&version=v1.11.0&show=api-pagemouse)。
```
// 使用 ‘page.mouse’ 追踪 100x100 的矩形。await page.mouse.move(0, 0);await page.mouse.down();await page.mouse.move(0, 100);await page.mouse.move(100, 100);await page.mouse.move(100, 0);await page.mouse.move(0, 0);await page.mouse.up();
```
#### Methods
- [mouse.click(x, y, \[options\])](#?product=Puppeteer&version=v1.11.0&show=api-mouseclickx-y-options)v0.9.0
- [mouse.down(\[options\])](#?product=Puppeteer&version=v1.11.0&show=api-mousedownoptions)v0.9.0
- [mouse.move(x, y, \[options\])](#?product=Puppeteer&version=v1.11.0&show=api-mousemovex-y-options)v0.9.0
- [mouse.up(\[options\])](#?product=Puppeteer&version=v1.11.0&show=api-mouseupoptions)v0.9.0
### Methods
#### mouse.click(x, y, \[options\])v0.9.0
- `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")>
- `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")>
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>
- `button` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> `left` ,`right` 或 `middle`,默认是 `left`。
- `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 默认是 1。见 [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")。
- `delay` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 在毫秒内且在 `mousedown` 和 `mouseup` 之间等待的时间。 默认为0。
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")>
[`mouse.move`](#?product=Puppeteer&version=v1.11.0&show=api-mousemovex-y-options),[`mouse.down`](#?product=Puppeteer&version=v1.11.0&show=api-mousedownoptions) 和 [`mouse.up`](#?product=Puppeteer&version=v1.11.0&show=api-mouseupoptions) 的快捷方式。
#### mouse.down(\[options\])v0.9.0
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>
- `button` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> `left`,`right` 或 `middle`,默认是 `left`。
- `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 默认是 1。见 [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")。
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")>
触发一个 `mousedown` 事件。
#### mouse.move(x, y, \[options\])v0.9.0
- `x` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")>
- `y` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")>
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>
- `steps` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 默认是 1。中间触发 `mousemove` 事件。
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")>
触发一个 `mousemove` 事件。
#### mouse.up(\[options\])v0.9.0
- `options` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>
- `button` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> `left`,`right`,或 `middle`,默认是 `left`。
- `clickCount` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 默认是 1。见 [UIEvent.detail](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail")。
- returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")>
触发一个 `mouseup` 事件。
![](images/pptr.png)
puppeteer.js中文网|class:mouse
puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档
puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。
- Introduction
- 版本记录
- 概要
- puppeteer-vs-puppeteer-core
- 环境变量
- error-handling
- working-with-chrome-extensions
- class:puppeteer
- class:browserfetcher
- class:browser
- class:page
- class:worker
- class:accessibility
- class:keyboard
- class:mouse
- class:touchscreen
- class:tracing
- class:dialog
- class:consolemessage
- class:frame
- class:executioncontext
- class:jshandle
- class:elementhandle
- class:request
- class:response
- class:securitydetails
- class:target
- class:cdpsession
- class:coverage
- class:timeouterror