Selenium WebDriver throws Timeout exceptions sporadically

前端 未结 8 1366
感情败类
感情败类 2020-12-01 07:43

Using selenium for ui tests on our project. We are running the newest version 2.30.0. We use Firefox WebDriver and are running Firefox 19.0.

Generally said the ui te

8条回答
  •  春和景丽
    2020-12-01 08:08

    I had the same issue as well but only on Firefox driver. Turns out it might be related to when you use the driver Navigate method and it tries to interact too fast with the page. Calling below code fix it for me on Navigate (I also recommend to use it before FindElement as well):

    public void VerifyPageIsLoaded()
    {
        var pageLoaded = false;
    
        for (var i = 0; i < DefaultTimeout.Timeout.Seconds; i++)
        {
            Thread.Sleep(1000);
    
            if (WebDriver.ExecuteJavaScript("return document.readyState").Equals("complete"))
            //jQuery.active might cause problems on some browser or browserstack so I commented it out
            //&& WebDriver.ExecuteJavaScript("return jQuery.active == 0").Equals(true))
            {
                pageLoaded = true;
                break;
            }
    
            Thread.Sleep(1000);
        }
    
        if (!pageLoaded)
        {
            throw new Exception("Page was not with complete state)!");
        }
    }
    

提交回复
热议问题