hover([options])
警告
将鼠标悬停在元素上。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
options | object | null | |
options.force | boolean | false | 将其设置为 true 将绕过操作可行性检查 (visible , stable , enabled )。 |
options.modifiers | string[] | null | 操作期间按下的 Alt 、Control 、Meta 或 Shift 修改键。如果未指定,则使用当前按下的修改键。 |
options.noWaitAfter | boolean | false | 如果设置为 true 且执行此操作导致页面导航,则不会等待导航完成。 |
options.position | object | null | 相对于元素左上角的坐标点。如果未提供,则使用元素的可见点。 |
options.position.x | number | 0 | x 坐标。 |
options.position.y | number | 0 | y 坐标。 |
options.timeout | number | 30000 | 最大超时时间(毫秒)。传递 0 可禁用超时。默认值会被 BrowserContext 或 Page 的 setDefaultTimeout 选项覆盖。 |
options.trial | boolean | false | 将其设置为 true 将只执行操作可行性检查而不执行实际操作。 |
返回值
类型 | 描述 |
---|---|
Promise<void> | 当悬停操作完成时兑现的 Promise。 |
示例
import { browser } from 'k6/browser';
export const options = {
scenarios: {
browser: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
await page.goto('https://test.k6.io/browser.php');
const offScreenElement = await page.$('#off-screen');
await offScreenElement.hover();
await page.close();
}