元素命令无法完成,因为该元素在页面上不可见

An element command could not be completed because the element is not visible on the page

我正在使用 webdriver.io 创建自动测试。我有一个无限滚动的页面,我试图在页面向下滚动时点击按钮,但一段时间后我收到消息:An element command could not be completed because the element is not visible on the page.

这是我抛出错误的代码:

var scroll_value = 0;

$$('button[value="Undo"]').filter(function (link) {
   link.click().pause(1500);
   scroll_value += 100;
   browser.scroll(0, scroll_value);
});

我设法通过将正文添加到我的选择器来修复它,例如:$("body #elem").click(); 并使用:

browser.execute(function() {
    document.getElementById('elem').scrollIntoView();
})