在 Navigator.click() 方法中, scrollIntoView() 发生在堆栈中的确切位置?

In the Navigator.click() method where exactly in the stack does the scrollIntoView() occur?

使用 Geb 和 WebElement,在执行单击之前,首先将 Web 元素滚动到视图中。我 运行 在这里遇到了一个问题,因为在屏幕顶部有一个 Webdriver 看不到的 'menu' 栏。这导致 chrome 抛出一个 webdriver 异常,指出该元素在 x,y 点不可点击,因为 webDriver 将元素滚动到菜单横幅下。

如果我查看 NonEmptyNavigator 的实现和随后的远程 webElement,我找不到 scrollIntoView() 在代码中出现的位置。我想在 scrollIntoView() 和实际的点击操作之间放置一些代码,以便我可以稍微偏移 ScrollIntoView() 以便执行点击。 Navigator.click() 在堆栈中的确切位置发生滚动到视图中吗?

调用 WebElement.click() 时在单击之前将元素滚动到视图中发生在浏览器端方法的实现内部,因此您不会在 Geb 或 [=13= 中找到任何关于将任何内容滚动到视图中的参考].这是 link 在浏览器端发生滚动的示例,来自 Marionette 的(Firefox WebDriver 实现)代码库:https://searchfox.org/mozilla-central/source/testing/marionette/interaction.js#148.

如果您希望在单击之前手动将元素滚动到视图中,您可能需要编写一个 Geb 模块并在其中覆盖 click()

class ViewPortOffsetModule extends Module {
    Navigator click() {
        //put your implementation of scrolling the element to view here, most probably using the js executor

        super.click()
    }
}

然后在您的内容定义中:

static content = {
    elementNeedingOffsetWhenScrollingIntoView { $("#my-element").module(ViewPortOffsetModule) }
}

现在,如果您在 ViewPortOffsetModule 中正确实现了滚动到视图中,则调用 elementNeedingOffsetWhenScrollingIntoView.click() 将在单击元素之前将元素滚动到具有偏移量的视图中。