コード例 #1
0
ファイル: Wait.cs プロジェクト: row49382/MAQS
        /// <summary>
        /// Wait for the page to load
        /// </summary>
        /// <returns>True if the page finished loading</returns>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/SeleniumUnitTest.cs" region="WaitUntilPageLoad" lang="C#" />
        /// </example>
        public bool UntilPageLoad()
        {
            DateTime   start  = DateTime.Now;
            string     source = string.Empty;
            IWebDriver driver = SeleniumUtilities.SearchContextToWebDriver(this.searchItem);

            do
            {
                // Give the system a second before checking if the page is updating
                Thread.Sleep(TimeSpan.FromSeconds(1));

                try
                {
                    // Find any element
                    driver.FindElement(By.CssSelector("*"));

                    // Get the page source
                    string newSource = driver.PageSource;

                    // Make sure the souce has not changed and it actully has content
                    if (!string.IsNullOrEmpty(source) && source.Equals(newSource))
                    {
                        return(true);
                    }

                    source = newSource;
                }
                catch
                {
                    // Could be several exceptions - Don't really care as it may just be the page loading
                }
            }while ((DateTime.Now - start) < this.webDriverWait.Timeout);

            // Page was still loading
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Get the low level, none event firing, web driver
        /// </summary>
        /// <param name="searchContext">Web driver or element</param>
        /// <returns>the underlying web driver</returns>
        public static IWebDriver GetLowLevelDriver(ISearchContext searchContext)
        {
            IWebDriver driver = SeleniumUtilities.SearchContextToWebDriver(searchContext);

            return(driver is EventFiringWebDriver ? ((EventFiringWebDriver)driver).WrappedDriver : driver);
        }