首页 > 解决方案 > 等待动画直到在 Selenium 中完成

问题描述

我面临等待动画直到完成的问题。到目前为止,使用 selenium 函数就足够了

等待.直到(预期条件....

但现在不可能了。我有 HTML 中的元素

<div content-c2="" class="nav-loader"></div>

该元素具有以下 CSS 样式:

.nav-header[content-c2] .nav-loader[content-c2] {
width: 100%;
height: 2px;
background: #EE3D42;
float: left;
clear: both;
animation: 1.5s ease-out 0.5s 1 slideInFromLeft;

我需要等到加载程序完成,然后我才能继续执行进一步的硒操作,例如单击,....我想避免使用静态延迟等。有人可以帮我定制动画完成后检查的特定功能? 谢谢提示...

标签: javascriptselenium-webdriver

解决方案


您可以查看位置

waitAnimationComplete = async(selector, newDriver = driver) => {
    const elem = await newDriver.wait(until.elementLocated(By.css(selector)))
    const loc1 = await elem.getRect()

    await newDriver.wait(new Condition('wait animation complete', () => {
        return new Promise((resolve, reject) => {
            elem.getRect()
                .then(loc2 => resolve(loc1.x === loc2.x && loc1.y === loc2.y))
        })
    }))
};

称呼

await waitAnimationComplete('your css selector of button ...')

推荐阅读