技术改变人生!

selenium gallio 'element is no longer attached to the DOM' error

上一篇 / 下一篇  2013-01-25 14:10:45 / 个人分类:selenium

在selenium+galio web测试的时候,经常遇到下面错误提示:
QpenQA.Selenium.StaleElementRefernceException:Element is no longer attached to the DOM.
 
这个错误的原因是:当你点击某个链接的时候,新加载的页面需要等待时间,如果没有加等待函数,可能会引起如上问题,以下是写的在加载控件之前的等待函数。
例子代码:
 
  public static bool WaitForWindowload(IWebDriver driver, int timeout = 20)
            {
                By loadMask = By.ClassName("loadMask");
                var timer = new Stopwatch();
                timer.Start();
           
                while (timer.ElapsedMilliseconds < (timeout * 1000))
                    {
                        if (!ElementExists(driver, loadMask))
                            {
                                return true;
                            }
                        Thread.Sleep(300);
                    }
                return false; //exceeded timeout           
            }

TAG:

 

评分:0

我来说两句

Open Toolbar