Mouse
Mouse
提供了一种与虚拟鼠标交互的方法。
方法 | 描述 |
---|---|
click(x, y[, options]) | 鼠标单击 `x` 和 `y` 坐标。 |
dblclick(x, y[, options]) | 鼠标双击 `x` 和 `y` 坐标。 |
down([options]) | 在鼠标当前位置分派 `mousedown` 事件。 |
up([options]) | 在鼠标当前位置分派 `mouseup` 事件。 |
move(x, y[, options]) | 在鼠标当前位置分派 `mousemove` 事件。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
}
}
export default async function () {
const page = await browser.newPage();
await page.goto('https://test.k6.io/', {
waitUntil: 'networkidle'
});
// Obtain ElementHandle for news link and navigate to it
// by clicking in the 'a' element's bounding box
const newsLinkBox = await page.$('a[href="/news.php"]');
const boundingBox = await newsLinkBox.boundingBox();
const x = newsLinkBox.x + newsLinkBox.width / 2; // center of the box
const y = newsLinkBox.y;
await page.mouse.click(x, y);
await page.close();
}