Class that helps to define Kind and value for html elements.
示例#1
0
        /// <summary>
        /// Returns a text representation of the grid or table html like element
        /// </summary>
        /// <param name="rowLocator">The row locator.</param>
        /// <param name="columnLocator">The column locator</param>
        /// <returns>
        /// Text representation of the grid or table html like element
        /// </returns>
        public string[][] GetTable(ElementLocator rowLocator, ElementLocator columnLocator)
        {
            var table = this.webElement;
            var rows = table.FindElements(rowLocator.ToBy());

            var result = new string[rows.Count][];
            var i = 0;

            foreach (var row in rows)
            {
                var cells = row.GetElements(columnLocator);
                result[i] = new string[cells.Count];

                var j = 0;
                foreach (var cell in cells)
                {
                    result[i][j++] = cell.Text;
                }
            }

            return result;
        }
        /// <summary>
        /// The scroll into middle.
        /// </summary>
        /// <param name="webDriver">The web driver.</param>
        /// <param name="locator">The locator.</param>
        public static void ScrollIntoMiddle(this IWebDriver webDriver, ElementLocator locator)
        {
            var js = (IJavaScriptExecutor)webDriver;
            var element = webDriver.GetElement(locator);

            if (webDriver != null)
            {
                int height = webDriver.Manage().Window.Size.Height;

                var hoverItem = (ILocatable)element;
                var locationY = hoverItem.LocationOnScreenOnceScrolledIntoView.Y;
                js.ExecuteScript(string.Format(CultureInfo.InvariantCulture, "javascript:window.scrollBy(0,{0})", locationY - (height / 2)));
            }
        }
 /// <summary>
 /// Waits for element until is displayed and enabled.
 /// </summary>
 /// <param name="webDriver">The web driver.</param>
 /// <param name="locator">The locator.</param>
 /// <param name="timeout">The timeout.</param>
 public static void WaitForElement(this IWebDriver webDriver, ElementLocator locator, double timeout)
 {
     var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeout));
     wait.Until(driver => webDriver.GetElement(locator).Displayed & webDriver.GetElement(locator).Enabled);
 }
 /// <summary>
 /// Waits the until element is no longer found.
 /// </summary>
 /// <param name="webDriver">The web driver.</param>
 /// <param name="locator">The locator.</param>
 /// <param name="timeout">The timeout.</param>
 public static void WaitUntilElementIsNoLongerFound(this IWebDriver webDriver, ElementLocator locator, double timeout)
 {
     var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeout));
     wait.Until(driver => webDriver.GetElements(locator).Count == 0);
 }
 /// <summary>
 /// The element is present.
 /// </summary>
 /// <param name="webDriver">The web driver.</param>
 /// <param name="locator">The locator.</param>
 /// <param name="customTimeout">The timeout.</param>
 /// <returns>
 /// The <see cref="bool" />.
 /// </returns>
 public static bool IsElementPresent(this IWebDriver webDriver, ElementLocator locator, double customTimeout)
 {
     try
     {
         webDriver.GetDisplayedElement(locator, customTimeout);
         return true;
     }
     catch (WebDriverTimeoutException)
     {
         return false;
     }
 }
 /// <summary>
 /// Waits the until element is no longer found.
 /// </summary>
 /// <example>Sample code to check page title: <code>
 /// this.Driver.WaitUntilElementIsNoLongerFound(dissapearingInfo, BaseConfiguration.ShortTimeout);
 /// </code></example>
 /// <param name="webDriver">The web driver.</param>
 /// <param name="locator">The locator.</param>
 /// <param name="timeout">The timeout.</param>
 public static void WaitUntilElementIsNoLongerFound(this IWebDriver webDriver, ElementLocator locator, double timeout)
 {
     var wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeout));
     wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException), typeof(NoSuchElementException));
     wait.Until(driver => webDriver.GetElements(locator).Count == 0);
 }