Esempio n. 1
0
        private static IWebElement FindElement(IWebDriver webDriver,
                                               string elementToFind,
                                               ByElementType checkType,
                                               int timeInSeconds = TimeinSecond)
        {
            IWebElement webElement = null;

            try
            {
                var checkElementExists = CheckElementExists(webDriver, elementToFind, checkType, timeInSeconds);
                if (checkElementExists)
                {
                    var by = CommonPageHelper.GetByElement(checkType, elementToFind);
                    webElement = webDriver.FindElement(by);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occured For Id:{0}, ErrorMessage:{1}, Method: {2}",
                                  elementToFind,
                                  ex.InnerException,
                                  "CommonPage.FindElement");

                webElement = null;
            }
            return(webElement);
        }
Esempio n. 2
0
        private static bool CheckElementExists(IWebDriver webDriver,
                                               string elementToFind,
                                               ByElementType checkType,
                                               int timeinSeconds = TimeinSecond)
        {
            var elementFound = false;

            try
            {
                _wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeinSeconds));

                var by = CommonPageHelper.GetByElement(checkType, elementToFind);

                elementFound = _wait.Until(ExpectedConditions.ElementExists(by)) != null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occured For Id:{0}, ErrorMessage:{1}, Method: {2}",
                                  elementToFind,
                                  ex.InnerException,
                                  "CommonPage.CheckElementExists");
            }

            return(elementFound);
        }