hover([选项])
注意
此功能存在已知问题。详情请参考 #471。
鼠标悬停在元素上。
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
options | 对象 | null | |
options.force | 布尔值 | false | 将其设置为 true 将绕过可操作性检查(可见、稳定、启用)。 |
options.modifiers | 字符串数组 | null | 操作期间按下的 Alt 、Control 、Meta 或 Shift 修饰键。如果未指定,则使用当前按下的修饰键。 |
options.noWaitAfter | 布尔值 | false | 如果设置为 true ,并且执行此操作导致发生导航,则不会等待其完成。 |
options.position | 对象 | null | 相对于元素左上角使用的点。如果未提供,则使用元素的可见点。 |
options.position.x | 数字 | 0 | x 坐标。 |
options.position.y | 数字 | 0 | y 坐标。 |
options.timeout | 数字 | 30000 | 最大超时时间,单位为毫秒。传入 0 以禁用超时。默认值将被 BrowserContext 或 Page 上的 setDefaultTimeout 选项覆盖。 |
options.trial | 布尔值 | 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 = page.locator('#off-screen');
await offScreenElement.hover();
}