コード例 #1
0
ファイル: Extension.cs プロジェクト: jluiz027/Seleniumplus
        /// <summary>
        /// Tenta recuperar o elemento web enquanto as condições (timeout, howManyTimes) forem satisfeitas
        /// </summary>
        /// <param name="driver">IWebDriver</param>
        /// <param name="howManyTimes">Quantidade limite de tentativas (-1 para infinitas)</param>
        /// <param name="searchMechanism">Mecanismo de busca para buscar elemento (IWebElement) vide classe OpenQA.Selenium.By</param>
        /// <param name="timeBetweenTriesSeconds">Intervalo de tempo, em segundos, entre tentativas consecutivas</param>
        /// Set this value to false if you don't want to thrown known exceptions from this framework. In this case null value will be returned if the element was not found.</param>
        /// <param name="premissaWeb">Premissas para serem verificadas antes de realizar as tentativas</param>
        public static IWebElement TryGetElement(this IWebDriver driver, int howManyTimes, int timeBetweenTriesSeconds, By searchMechanism, bool throwExceptions = true, IPremissaWeb premissaWeb = null)
        {
            premissaWeb?.Verificar();

            var countTentativas = 0;
            var horarioInicio   = DateTime.Now;

            while (true)
            {
                try
                {
                    CheckTimeOutAndTry(howManyTimes, horarioInicio, ref countTentativas);

                    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeBetweenTriesSeconds));
                    //var myDynamicElement = wait.Until(d => d.FindElement(searchMechanism));
                    var myDynamicElement = driver.FindElement(searchMechanism);
                    return(myDynamicElement);
                }
                catch (TryEnoughTimesToGetException)
                {
                    if (throwExceptions)
                    {
                        throw;
                    }

                    return(null);
                }
                catch (Exception e)
                {
                    Thread.Sleep(timeBetweenTriesSeconds * 1000);
                    Console.WriteLine(e.Message);
                }
            }
        }
コード例 #2
0
ファイル: Extension.cs プロジェクト: jluiz027/Seleniumplus
        /// <summary>
        /// Tenta recuperar o elemento web enquanto as condições (timeout, howManyTimes) forem satisfeitas
        /// </summary>
        /// <param name="driver">IWebDriver</param>
        /// <param name="howManyTimes">Quantidade limite de tentativas (-1 para infinitas)</param>
        /// <param name="searchMechanism">Mecanismo de busca para buscar elemento (IWebElement) vide classe OpenQA.Selenium.By</param>
        /// <param name="throwExceptions">Indica se exceções conhecidas neste namespace devem ser disparadas. Se false retornará nulo caso não consiga encontrar o elemento. -</param>
        /// <param name="timeBetweenTriesSeconds">Intervalo de tempo, em segundos, entre tentativas consecutivas</param>
        /// <param name="premissaWeb">Premissas para serem verificadas antes de realizar as tentativas</param>
        public static ICollection <IWebElement> TryGetElements(this IWebDriver driver, int howManyTimes, int timeBetweenTriesSeconds, By searchMechanism, bool throwExceptions = true, IPremissaWeb premissaWeb = null)
        {
            premissaWeb?.Verificar();

            var countTentativas = 0;
            var horarioInicio   = DateTime.Now;

            while (true)
            {
                try
                {
                    CheckTimeOutAndTry(howManyTimes, horarioInicio, ref countTentativas);

                    var wait             = new WebDriverWait(driver, TimeSpan.FromSeconds(timeBetweenTriesSeconds));
                    var myDynamicElement = wait.Until(d => d.FindElements(searchMechanism));
                    return(myDynamicElement);
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }