跳至主要内容

scrollIntoView

将元素滚动到视口(MDN 参考)。

用法
$(selector).scrollIntoView(scrollIntoViewOptions)
参数
名称类型详情
scrollIntoViewOptionsobject, booleanElement.scrollIntoView() 的选项(默认:{ block: 'start', inline: 'nearest' }
示例
scrollIntoView.js
it('should demonstrate the scrollIntoView command', async () => {
const elem = await $('#myElement');
// scroll to specific element
await elem.scrollIntoView();
// center element within the viewport
await elem.scrollIntoView({ block: 'center', inline: 'center' });
});

欢迎!我如何帮助您?

WebdriverIO AI Copilot