Exemple #1
0
        public static void CloseAlertIfExist(this IWebDriver driver)
        {
            var alert = driver.SwitchTo().Alert();

            CustomTestContext.WriteLine("Alert text: {0}.", alert.Text);
            CustomTestContext.WriteLine("Click Cancel");
            alert.Dismiss();
        }
Exemple #2
0
        public static void SendHotKeys(this IWebDriver driver, string key, bool control = false, bool shift = false, bool alt = false)
        {
            var keysCombinationDescriptor = new StringBuilder();

            if (control)
            {
                keysCombinationDescriptor.Append("Ctrl+");
            }
            if (alt)
            {
                keysCombinationDescriptor.Append("Alt+");
            }
            if (shift)
            {
                keysCombinationDescriptor.Append("Shift+");
            }
            keysCombinationDescriptor.Append(key);

            CustomTestContext.WriteLine($"Press {keysCombinationDescriptor}");
            var actions = new Actions(driver);

            if (control)
            {
                actions.KeyDown(Keys.Control);
            }
            if (shift)
            {
                actions.KeyDown(Keys.Shift);
            }
            if (alt)
            {
                actions.KeyDown(Keys.Alt);
            }

            Thread.Sleep(500);
            actions.SendKeys(key);

            if (control)
            {
                actions.KeyUp(Keys.Control);
            }
            if (shift)
            {
                actions.KeyUp(Keys.Shift);
            }
            if (alt)
            {
                actions.KeyUp(Keys.Alt);
            }

            actions.Build().Perform();
        }
Exemple #3
0
 public static void Scroll(this IWebElement webElement)
 {
     try
     {
         webElement.scrollToWebElement();
     }
     catch (StaleElementReferenceException staleElementReferenceException)
     {
         CustomTestContext.WriteLine(
             "StaleElementReferenceException: Scroll: " + webElement.TagName, staleElementReferenceException);
         webElement.scrollToWebElement();
     }
 }
Exemple #4
0
        //public static void FindElement(this IWebElement webElement, By by)
        //{
        //    webElement.FindElement(by);
        //}

        public static void HoverElement(this IWebElement webElement)
        {
            try
            {
                var actionBuilder = new Actions(getDriverFromWebElement(webElement));
                actionBuilder.MoveToElement(webElement).Build().Perform();
            }
            catch (StaleElementReferenceException staleElementReferenceException)
            {
                CustomTestContext.WriteLine(
                    "StaleElementReferenceException: HoverElement.", staleElementReferenceException);
                var actionBuilder = new Actions(getDriverFromWebElement(webElement));
                actionBuilder.MoveToElement(webElement).Build().Perform();
            }
        }
Exemple #5
0
        public static void DoubleClick(this IWebElement webElement)
        {
            var driver = getDriverFromWebElement(webElement);

            try
            {
                var action = new Actions(driver);
                action.DoubleClick(webElement);
                action.Perform();
            }
            catch (StaleElementReferenceException staleElementReferenceException)
            {
                CustomTestContext.WriteLine(
                    "StaleElementReferenceException: DoubleClickElement: "
                    + webElement.TagName, staleElementReferenceException);
                var action = new Actions(driver);
                action.DoubleClick(webElement);
                action.Perform();
            }
        }