예제 #1
0
        public static bool ClickElement(IWebDriver webDriver,
                                        string idToFind,
                                        ByElementType checkType,
                                        int timeInSeconds = TimeinSecond)
        {
            var isClicked = false;

            try
            {
                var webElement = FindElement(webDriver, idToFind, checkType, timeInSeconds);
                if (webElement != null)
                {
                    webElement.Click();
                    isClicked = true;
                }
                else
                {
                    Console.WriteLine("No element exists By Id: {0}, Method: {1}", idToFind, "CommonPage.ClickGoButton");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception Occured For Id:{0}, ErrorMessage:{1}, Method: {2}",
                                  idToFind,
                                  ex.InnerException,
                                  "CommonPage.ClickGoButton");
            }

            return(isClicked);
        }
예제 #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);
        }
예제 #3
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);
        }
예제 #4
0
        internal static By GetByElement(ByElementType checkType, string elementToFind)
        {
            By value = null;

            switch (checkType)
            {
            case ByElementType.ClassName:
                value = By.ClassName(elementToFind);
                break;

            case ByElementType.CssSelector:
                value = By.CssSelector(elementToFind);
                break;

            case ByElementType.Id:
                value = By.Id(elementToFind);
                break;

            case ByElementType.LinkText:
                value = By.LinkText(elementToFind);
                break;

            case ByElementType.Name:
                value = By.Name(elementToFind);
                break;

            case ByElementType.PartialLinkText:
                value = By.PartialLinkText(elementToFind);
                break;

            case ByElementType.TagName:
                value = By.TagName(elementToFind);
                break;

            case ByElementType.XPath:
                value = By.XPath(elementToFind);
                break;
            }

            return(value);
        }