Acts as a base class for all objects that can contain DOM elements
Ejemplo n.º 1
0
        private static IWebElement GetWebElement(ElementsContainer elementsContainer, By by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector, string description)
        {
            if (elementsContainer == null)
            {
                throw new ArgumentNullException("elementsContainer");
            }
            if (by == null)
            {
                throw new ArgumentNullException("by");
            }
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            var searchContext    = elementsContainer.GetSearchContext();
            var matchingElements = searchContext.FindElements(by);
            var selectedElement  = selector(matchingElements);

            if (selectedElement == null)
            {
                throw new NoSuchElementException(string.Format("Element '{0}' could not be found or is not available", description));
            }

            return(selectedElement);
        }
Ejemplo n.º 2
0
        private static IDOMRoot SafeGetDOMRoot(ElementsContainer otherElement, string paramName)
        {
            if (otherElement == null)
            {
                throw new ArgumentNullException(paramName);
            }

            return(otherElement.DOMRoot);
        }
Ejemplo n.º 3
0
        private static IWebElement GetWebElement(ElementsContainer elementsContainer, By @by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector)
        {
            if (elementsContainer == null)
            {
                throw new ArgumentNullException("elementsContainer");
            }
            if (by == null)
            {
                throw new ArgumentNullException("by");
            }
            if (selector == null)
            {
                throw new ArgumentNullException("selector");
            }

            var searchContext    = elementsContainer.GetSearchContext();
            var matchingElements = searchContext.FindElements(@by);

            return(selector(matchingElements));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Initialized a new instance of <see cref="BrowserElement"/> given its container, a specific 'By' filter and description
 /// </summary>
 /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param>
 /// <param name="by">A filter mechanism used to find the element. If multiple elements match the filter, the first one is used</param>
 /// <param name="description">The description of the new element</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null</exception>
 public BrowserElement(ElementsContainer container, By by, string description)
     : this(SafeGetDOMRoot(container, "container"), () => container.GetSearchContext().FindElement(by), description)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of <see cref="BrowserElement"/> given its container, a 'By' filter a selector and description
 /// </summary>
 /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param>
 /// <param name="by">A filter mechanism used to filter the matching elements</param>
 /// <param name="selector">A delegate that is used to select the sepecific element from the filtered elements</param>
 /// <param name="description">The description of the new element</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null</exception>
 public BrowserElement(ElementsContainer container, By by, Func<IReadOnlyCollection<IWebElement>, IWebElement> selector, string description)
     : this(SafeGetDOMRoot(container, "container"), () => GetWebElement(container, by, selector, description), description)
 {
 }
Ejemplo n.º 6
0
        private static IDOMRoot SafeGetDOMRoot(ElementsContainer otherElement, string paramName)
        {
            if (otherElement == null)
                throw new ArgumentNullException(paramName);

            return otherElement.DOMRoot;
        }
Ejemplo n.º 7
0
        private static IWebElement GetWebElement(ElementsContainer elementsContainer, By by, Func<IReadOnlyCollection<IWebElement>, IWebElement> selector, string description)
        {
            if (elementsContainer == null)
                throw new ArgumentNullException("elementsContainer");
            if (by == null)
                throw new ArgumentNullException("by");
            if (selector == null)
                throw new ArgumentNullException("selector");

            var searchContext = elementsContainer.GetSearchContext();
            var matchingElements = searchContext.FindElements(by);
            var selectedElement = selector(matchingElements);
            if (selectedElement == null)
                throw new NoSuchElementException(string.Format("Element '{0}' could not be found or is not available", description));

            return selectedElement;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initialized a new instance of <see cref="BrowserElement"/> given its container, a specific 'By' filter and description
 /// </summary>
 /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param>
 /// <param name="by">A filter mechanism used to find the element. If multiple elements match the filter, the first one is used</param>
 /// <param name="description">The description of the new element</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null</exception>
 public BrowserElement(ElementsContainer container, By by, string description)
     : this(SafeGetDOMRoot(container, "container"), () => container.GetSearchContext().FindElement(by), description)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of <see cref="BrowserElement"/> given its container, a 'By' filter a selector and description
 /// </summary>
 /// <param name="container">The container that contains the relevant element. Typically this is a <see cref="Browser"/>, <see cref="BrowserWindow"/>, <see cref="Frame"/> or a containing <see cref="BrowserElement"/></param>
 /// <param name="by">A filter mechanism used to filter the matching elements</param>
 /// <param name="selector">A delegate that is used to select the sepecific element from the filtered elements</param>
 /// <param name="description">The description of the new element</param>
 /// <exception cref="ArgumentNullException">Any of the arguments is null</exception>
 public BrowserElement(ElementsContainer container, By by, Func <IReadOnlyCollection <IWebElement>, IWebElement> selector, string description)
     : this(SafeGetDOMRoot(container, "container"), () => GetWebElement(container, by, selector, description), description)
 {
 }