硒-遵循快速加载指示器 [英] Selenium - follow fast loading indicator

查看:50
本文介绍了硒-遵循快速加载指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试一个数据表,该表在每次更改时都有一个加载指示器. 有时,此指标非常快. 为了遵循这些非常快速的UI更改,硒是否有最佳实践? (例如加载指示器).

I need to test a data table, which on every change has a loading indicator. Sometimes this indicator is very fast. Is there any best practice for selenium in order to follow these very fast UI changes? (Such as loading indicator).

推荐答案

我使用以下c#向dom查询具有已知加载值的ID和类,并等待它们不出现.使用driver.FindElement(By *)尝试声明元素存在于给定的标识符中,而不是搜索它,这将导致错误,并且不是我们要寻找的行为.

I use the following c# to query the dom for id's and classes with known loading values and wait for them to not be present. Using driver.FindElement(By*) attempts to declare the element is present at a given identifier rather than searching for it, which will cause errors and isn't the behavior we're looking for.

public IWebDriver WaitForPage()
    {// Query document for loading elements until none found
        var wait = new WebDriverWait(driver,MyDefaultTimeout)
        .Until( 
            e => ((IJavaScriptExecutor)e) 
                .ExecuteScript(@"
                    var MyDefaultTimeout = 500; 
                    var loaded = false;
                    do {
                        var elementClasses = document.getElementsByClassName('//*[contains(@class=\'is-loading\') or contains(@class=\'fa-gear\') or contains(@class=\'loading\') and not(@class=\'displayed\')]');
                        var elementIds = document.getElementById('//*[contains(@id=\'hover-gear\') or contains(@id=\loading-gear\')]');
                        if((!elementClasses === null) || (!elementIds === null)){
                            setTimeout(function() { loaded = false }, MyDefaultTimeout);
                            }
                        else{ 
                            if(!document.readyState === 'complete'){
                                setTimeout(function() { loaded = false }, MyDefaultTimeout);
                                }
                            else{ 
                                loaded = true;
                                return document.readyState;
                                }
                            }
                        }
                    while(loaded === false);", null))
                .Equals("complete");
        return driver;
    }

这篇关于硒-遵循快速加载指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆