Beispiel #1
0
        /// <summary>
        /// JavaScript method to scroll an element into the view
        /// </summary>
        /// <param name="searchContext">Web driver or element</param>
        /// <param name="x">Horizontal direction</param>
        /// <param name="y">Vertical direction</param>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/ElementHandlerUnitTests.cs" region="ExecuteScrolling" lang="C#" />
        /// </example>
        public static void ExecuteScrolling(this ISearchContext searchContext, int x, int y)
        {
            string scrollCommand         = string.Format("scroll({0}, {1});", x, y);
            IJavaScriptExecutor executor = SeleniumUtilities.SearchContextToJavaScriptExecutor(searchContext);

            executor.ExecuteScript(scrollCommand);
        }
Beispiel #2
0
        /// <summary>
        /// Method to click an element via JavaScript
        /// Used for scenarios where normal click can't reach, such as hidden or hover triggered elements.
        /// </summary>
        /// <param name="searchContext">Web driver or element</param>
        /// <param name="by">The By element to use</param>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/ElementHandlerUnitTests.cs" region="ClickByJavascript" lang="C#" />
        /// </example>
        public static void ClickElementByJavaScript(this ISearchContext searchContext, By by)
        {
            IWebElement element = searchContext.FindElement(by);

            IJavaScriptExecutor executor = SeleniumUtilities.SearchContextToJavaScriptExecutor(searchContext);

            executor.ExecuteScript("arguments[0].click();", element);
        }
Beispiel #3
0
        /// <summary>
        /// JavaScript method to scroll an element into the view
        /// </summary>
        /// <param name="searchContext">Web driver or element</param>
        /// <param name="by">By selector</param>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/ElementHandlerUnitTests.cs" region="ScrollIntoView" lang="C#" />
        /// </example>
        public static void ScrollIntoView(this ISearchContext searchContext, By by)
        {
            IWebElement element = searchContext.FindElement(by);

            IJavaScriptExecutor executor = SeleniumUtilities.SearchContextToJavaScriptExecutor(searchContext);

            executor.ExecuteScript("arguments[0].scrollIntoView(true);", element);
        }
Beispiel #4
0
        /// <summary>
        /// Method to click an element via JavaScript
        /// Used for scenarios where normal click can't reach, such as hidden or hover triggered elements.
        /// </summary>
        /// <param name="element">Element to click</param>
        public static void ClickElementByJavaScript(this IWebElement element)
        {
            IJavaScriptExecutor executor = SeleniumUtilities.SearchContextToJavaScriptExecutor(element);

            executor.ExecuteScript("arguments[0].click();", element);
        }