Пример #1
0
        private static IWebElement Find(By by)
        {
            int attempt     = 0;
            int maxAttempts = 12;

            IWebElement   result = null;
            WebDriverWait wait   = new WebDriverWait(Driver.driver, new TimeSpan(0, 0, 2));

            while (attempt < maxAttempts && result == null)
            {
                attempt++;
                try
                {
                    if (wait.IsElementPresent(by))
                    {
                        result = wait.Until(d => Driver.driver.FindElement(by));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (attempt >= maxAttempts)
                    {
                        ConsoleLogger.Log(ex);
                        break;
                    }
                }
            }
            if (result == null)
            {
                throw new Exception("Failed to Identify an object " + by.ToString());
            }
            return(result);
        }