コード例 #1
0
        /// <summary>
        /// Method performing a control click on multiple IWebElement objects.
        /// </summary>
        /// <param name="driver">IWebDriver object to execute method.</param>
        /// <param name="elements">The set of elements to perform the clicks.</param>
        public static void ControlClick(this IWebDriver driver, params IWebElement[] elements)
        {
            try
            {
                if (elements == null)
                {
                    return;
                }
                if (elements.Length == 0)
                {
                    return;
                }

                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.KeyDown(Keys.Control);
                foreach (IWebElement element in elements)
                {
                    action.MoveToElement(element);
                    action.MoveToElement(element).Click();
                }
                action.KeyUp(Keys.Control);
                action.Build().Perform();
            }
            catch { }
        }
コード例 #2
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void ContextClick(this IWebDriver driver, IWebElement element)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.MoveToElement(element).ContextClick();
                action.Build().Perform();
            }
            catch { }
        }
コード例 #3
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void Hover(this IWebDriver driver, IWebElement element)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.MoveByOffset(1, 1);
                action.Build().Perform();
            }
            catch { }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="element"></param>
        /// <param name="key"></param>
        public static void Insert(this IWebDriver driver, IWebElement element, string key)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.KeyDown(key);
                action.KeyUp(key.ToString());
                action.Build().Perform();
            }
            catch { }
        }
コード例 #5
0
        public void How_To_Enter_Text_Caps_Lock()
        {
            OpenQA.Selenium.Interactions.Actions action = new OpenQA.Selenium.Interactions.Actions(chromedriver);
            //action.KeyDown(object, "SHIFT");
            action.KeyDown(Keys.Shift);
            action.SendKeys("ab");
            action.Build().Perform();
            string pageTitle = chromedriver.Title;

            //driver.FindElements(By.XPath("")).Count();
            OpenQA.Selenium.Support.UI.SelectElement selectElement = new OpenQA.Selenium.Support.UI.SelectElement(chromedriver.FindElement(By.XPath("")));
            //selectElement.
        }
コード例 #6
0
 /// <summary>
 /// Drags the <paramref name="sourceElement"/> to the <paramref name="destinationElement"/>.
 /// </summary>
 /// <param name="sourceElement"></param>
 /// <param name="destinationElement"></param>
 public void DragAndDrop(IWebElement sourceElement, IWebElement destinationElement)
 {
     try
     {
         var builder = new OpenQA.Selenium.Interactions.Actions(driver);
         builder.DragAndDrop(sourceElement, destinationElement);
         builder.Build().Perform();
     } catch (Exception e)
     {
         MyLogger.Log.Error($"Failed to drag source element: {sourceElement} to destination element: {destinationElement}. {e.Message}");
         throw e;
     }
 }
コード例 #7
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void ContextClick(this IWebElement element)
        {
            try
            {
                var wrappedElement = element as IWrapsDriver;
                var driver         = wrappedElement.WrappedDriver;
                var action         = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.MoveToElement(element).ContextClick();
                action.Build().Perform();
            }
            catch { }
        }
コード例 #8
0
        /// <summary>
        /// Method performing specific key pressed.
        /// </summary>
        /// <param name="element">IWebElement element that receives the click action.</param>
        /// <param name="keystr"></param>
        public static void Insert(this IWebElement element, string keystr)
        {
            try
            {
                var wrappedElement = element as IWrapsDriver;
                var driver         = wrappedElement.WrappedDriver;
                var action         = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.KeyDown(keystr);
                action.KeyUp(keystr.ToString());
                action.Build().Perform();
            }
            catch { }
        }
コード例 #9
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void ClickAndWait(this IWebDriver driver, IWebElement element, string title, int timespan = 5)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);
                var wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(timespan));

                action.MoveToElement(element);
                action.MoveToElement(element).Click();
                action.Build().Perform();

                wait.Until(d => d.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));
            }
            catch { }
        }
コード例 #10
0
        /// <summary>
        /// Method performing a mouse click with hold and no release.
        /// </summary>
        /// <param name="driver">IWevDriver provided.</param>
        /// <param name="element">IWebElement element that receives the click and hold action.</param>
        public static void ClickAndHold(this IWebDriver driver, IWebElement element)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.MoveToElement(element).ClickAndHold();
                action.Build().Perform();
            }
            catch (Exception e)
            {
                throw new InternalActionException(string.Format("Unable to click and hold object \"{0}\".\r\nSee:\r\n\t- {1}{2}", element,
                                                                e.Message, (e.InnerException == null ? "" : string.Format("\r\n\t- {0}", e.InnerException.Message))), e);
            }
        }
コード例 #11
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void HoverAndWait(this IWebDriver driver, IWebElement element, By newObject, int timespan = 5)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);
                var wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(timespan));

                action.MoveToElement(element);
                action.MoveByOffset(1, 1);
                action.Build().Perform();

                wait.Until(ExpectedConditions.ElementExists(newObject));
                wait.Until(ExpectedConditions.ElementIsVisible(newObject));
            }
            catch { }
        }
コード例 #12
0
        /// <summary>
        /// Method performing a drag and drop of a given element onto another element (preferably a container).
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="dragElement">Element to drag onto the drop element.</param>
        /// <param name="dropElement">The drop element (a container).</param>
        public static void DragAndDrop(this IWebDriver driver, IWebElement dragElement, IWebElement dropElement)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(dragElement).Build().Perform();
                action.MoveToElement(dragElement).ClickAndHold();
                action.MoveToElement(dropElement).Release(dropElement);
                action.Build().Perform();
            }
            catch (Exception e)
            {
                throw new InternalActionException(string.Format("Unable to drag object \"{0}\" onto drop area with object \"{1}\".\r\nSee:\r\n\t- {2}{3}", dragElement, dropElement,
                                                                e.Message, (e.InnerException == null ? "" : string.Format("\r\n\t- {0}", e.InnerException.Message))), e);
            }
        }
コード例 #13
0
 /// <summary>
 /// Drags the <paramref name="sourceElement"/> to the <paramref name="destinationElement"/>.
 /// </summary>
 /// <param name="sourceElement"></param>
 /// <param name="destinationElement"></param>
 public void DragAndDrop(By sourceElement, By destinationElement)
 {
     try
     {
         var builder = new OpenQA.Selenium.Interactions.Actions(driver);
         builder.ClickAndHold(driver.FindElement(sourceElement));
         builder.MoveToElement(driver.FindElement(destinationElement));
         builder.Release();
         builder.Build();
         builder.Perform();
     }
     catch (Exception e)
     {
         MyLogger.Log.Error($"Failed to drag source element: {sourceElement} to destination element: {destinationElement}. {e.Message}");
         throw e;
     }
 }
コード例 #14
0
        /// <summary>
        /// Method is performing a mouse hover on a given IWebElement object.
        /// </summary>
        /// <param name="element">IWebElement element that receives the click action.</param>
        public static void Hover(this IWebElement element)
        {
            try
            {
                var wrappedElement = element as IWrapsDriver;
                var driver         = wrappedElement.WrappedDriver;
                var action         = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(element);
                action.MoveByOffset(1, 1);
                action.Build().Perform();
            }
            catch (Exception e)
            {
                throw new InternalActionException(string.Format("Unable to perform a mouse hover on object \"{0}\".\r\nSee:\r\n\t- {1}{2}", element,
                                                                e.Message, (e.InnerException == null ? "" : string.Format("\r\n\t- {0}", e.InnerException.Message))), e);
            }
        }
コード例 #15
0
ファイル: Mouse.cs プロジェクト: DuCalixte/Selenium.Actions
        public static void ClickAndWait(this IWebElement element, By newObject, int timespan = 5)
        {
            try
            {
                var wrappedElement = element as IWrapsDriver;
                var driver         = wrappedElement.WrappedDriver;
                var action         = new OpenQA.Selenium.Interactions.Actions(driver);
                var wait           = new WebDriverWait(driver, TimeSpan.FromSeconds(timespan));

                action.MoveToElement(element);
                action.MoveToElement(element).Click();
                action.Build().Perform();

                wait.Until(ExpectedConditions.ElementExists(newObject));
                wait.Until(ExpectedConditions.ElementIsVisible(newObject));
            }
            catch { }
        }
コード例 #16
0
        /// <summary>
        /// Method performing a mouse click action on an IWebElement element and wait page with specific title.
        /// </summary>
        /// <param name="driver">IWebDriver provided.</param>
        /// <param name="element">IWebElement element that receives the click action.</param>
        /// <param name="title">The new page title expected after click action.</param>
        /// <param name="timespan">The maximum time to wait for the page title.</param>
        public static void ClickAndWait(this IWebDriver driver, IWebElement element, string title, int timespan = 5)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);
                var wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(timespan));

                action.MoveToElement(element);
                action.MoveToElement(element).Click();
                action.Build().Perform();

                wait.Until(d => d.Title.Equals(title, StringComparison.CurrentCultureIgnoreCase));
            }
            catch (Exception e)
            {
                throw new InternalActionException(string.Format("Unable to click on object \"{0}\" or wait for new title \"{1}\".\r\nSee:\r\n\t- {2}{3}", element, title,
                                                                e.Message, (e.InnerException == null ? "" : string.Format("\r\n\t- {0}", e.InnerException.Message))), e);
            }
        }
コード例 #17
0
        /// <summary>
        /// Method performing a multi-click selection given two IWebElement objects. Use on a list of objects, it should also select all elements found within the given objects.
        /// </summary>
        /// <param name="driver">IWebDriver object to execute method.</param>
        /// <param name="firstElement">First IWebElement object onto which first click is performed.</param>
        /// <param name="secondElement">Second IWebElement object onto which second click is performed.</param>
        public static void ShiftClick(this IWebDriver driver, IWebElement firstElement, IWebElement secondElement)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(firstElement);
                action.MoveToElement(firstElement).Click();

                action.KeyDown(Keys.Shift);

                action.MoveToElement(secondElement);
                action.MoveToElement(secondElement).Click();

                action.KeyUp(Keys.Shift);
                action.Build().Perform();
            }
            catch { }
        }
コード例 #18
0
        /// <summary>
        /// Method is performing a mouse hover on a given IWebElement object, it then waits for specific length of time for a new IWebElement object to be visible given its path.
        /// </summary>
        /// <param name="driver">IWebDriver object provided.</param>
        /// <param name="element">IWebElement element that receives the click action.</param>
        /// <param name="path">Path of element that needs to be visible after the mouse hover action.</param>
        /// <param name="timespan">The maximum time to wait for the element to be visible.</param>
        public static void HoverAndWait(this IWebDriver driver, IWebElement element, By path, int timespan = 5)
        {
            try
            {
                var action = new OpenQA.Selenium.Interactions.Actions(driver);
                var wait   = new WebDriverWait(driver, TimeSpan.FromSeconds(timespan));

                action.MoveToElement(element);
                action.MoveByOffset(1, 1);
                action.Build().Perform();

                wait.Until(ExpectedConditions.ElementExists(path));
                wait.Until(ExpectedConditions.ElementIsVisible(path));
            }
            catch (Exception e)
            {
                throw new InternalActionException(string.Format("Unable to perform a mouse hover on object \"{0}\" or wait for new object to be visible \"{1}\".\r\nSee:\r\n\t- {2}{3}", element, path,
                                                                e.Message, (e.InnerException == null ? "" : string.Format("\r\n\t- {0}", e.InnerException.Message))), e);
            }
        }
コード例 #19
0
        /// <summary>
        /// Method performing a control click on multiple IWebElement objects.
        /// </summary>
        /// <param name="firstElement">First IWebElement object onto which first click is performed.</param>
        /// <param name="elements">The set of elements to perform the clicks.</param>
        public static void ControlClick(this IWebElement firstElement, params IWebElement[] elements)
        {
            try
            {
                var wrappedElement = firstElement as IWrapsDriver;
                var driver         = wrappedElement.WrappedDriver;
                var action         = new OpenQA.Selenium.Interactions.Actions(driver);

                action.MoveToElement(firstElement);
                action.MoveToElement(firstElement).Click();

                action.KeyDown(Keys.Control);
                foreach (IWebElement element in elements)
                {
                    action.MoveToElement(element);
                    action.MoveToElement(element).Click();
                }
                action.KeyUp(Keys.Control);
                action.Build().Perform();
            }
            catch { }
        }