public static TestRunner EnterTextIntoElement(this TestRunner runner, By targetElement, string text)
        {
            if (!runner.ValidatePageContainsElement(targetElement))
            {
                var message = $"Page [{runner.driver.Url}] does not contain an element identified by [{targetElement}].";

                throw new Exception(message);
            }

            Console.WriteLine("Finding element [{0}]", targetElement);

            var inputField = runner.driver.FindElement(targetElement);

            var displayText = text
                              .Replace(Keys.Backspace, "{Backspace}")
                              .Replace(Keys.Enter, "{Enter}");

            //.Replace(Environment.NewLine, "{CarrageReturn}")

            Console.WriteLine("Loading [{0}] into Element [{1}]", displayText, targetElement);

            inputField.SendKeys(text);

            return(runner);
        }
Beispiel #2
0
        public static TestRunner ClickElement(this TestRunner runner, By clickableElement)
        {
            if (!runner.ValidatePageContainsElement(clickableElement))
            {
                var message = $"Page [{runner.driver.Url}] does not contain an element identified by [{clickableElement}].";

                return(runner);
            }

            Console.WriteLine("Finding element [{0}]", clickableElement);

            var button = runner.driver.FindElement(clickableElement);

            // try 3 times
            var retry = 0;

            while (true)
            {
                try
                {
                    button.Click();
                    return(runner);
                }
                catch (Exception exc)
                {
                    runner.Pause(1000);

                    retry++;
                    if (retry != 3)
                    {
                        continue;
                    }

                    else
                    {
                        throw;
                    }
                }
            }
        }