automation - WebDriverIO : scrollIntoView action scrolls element outside Viewport?

标签 automation automated-tests webdriver-io

我正在使用 WebDriverIO ("webdriverio": "^7.14.1")。通常,scrollIntoView() 操作会按预期工作。但有时,它会将元素滚动到视口(viewport)之外,例如,它将元素滚动到隐藏/ View 之外的页面顶部一行(我希望您理解这一点)。

现在,这种情况经常发生在我身上,所以我的测试因此不稳定。

await $('#licenseName').scrollIntoView();

有什么建议可以克服这个问题吗?谢谢

最佳答案

我可以使用 scrollIntoViewOptions 解决此问题,如下所示:

await $('#licenseName').scrollIntoView({block:'center'});

元素滚动到屏幕中心,因此始终位于视口(viewport)中。

关于automation - WebDriverIO : scrollIntoView action scrolls element outside Viewport?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72615558/

相关文章:

java - NTLM 身份验证的哪些参数可以自动化,以及如何使用 java 实现?

typescript - 在没有 "webdriver-manager start"的情况下运行 Protractor 测试

javascript - Chrome (58v) webdriverio 未运行,firefox 正在运行

node.js - 如何在运行测试套件时仅启动/停止 NodeJS 服务器一次

ubuntu - ansible:sudo -iu 用于交互式 shell

testing - QTP/UFT中Browser和Page的作用是什么?

python - 自动实例Python

Selenium如何制作点击并按住按钮

java - testcontainers oracle 数据库容器在创建数据库用户之前启动

testing - 如何使用 WebDriverIO 获取可见元素