Example #1
0
        public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context)
        {
            if (this.bys.Length == 0)
            {
                return(new List <IWebElement>().AsReadOnly());
            }
            IEnumerable <IWebElement> enumerable = null;

            By[] array = this.bys;
            for (int i = 0; i < array.Length; i++)
            {
                By by = array[i];
                ReadOnlyCollection <IWebElement> readOnlyCollection = by.FindElements(context);
                if (readOnlyCollection.Count == 0)
                {
                    return(new List <IWebElement>().AsReadOnly());
                }
                if (enumerable == null)
                {
                    enumerable = readOnlyCollection;
                }
                else
                {
                    enumerable = enumerable.Intersect(by.FindElements(context));
                }
            }
            return(enumerable.ToList <IWebElement>().AsReadOnly());
        }
Example #2
0
        public override IWebElement FindElement(ISearchContext context)
        {
            ReadOnlyCollection <IWebElement> elements = by.FindElements(context);

            if (index < 0 || index >= elements.Count)
            {
                throw new NoSuchElementException(
                          string.Format("Element with by '{0}' and index '{1}' not found (actual count='{2}')", by, index,
                                        elements.Count));
            }
            return(elements[index]);
        }
Example #3
0
        public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context)
        {
            if (this.bys.Length == 0)
            {
                return(new List <IWebElement>().AsReadOnly());
            }
            List <IWebElement> list = null;

            By[] array = this.bys;
            for (int i = 0; i < array.Length; i++)
            {
                By by = array[i];
                List <IWebElement> list2 = new List <IWebElement>();
                if (list == null)
                {
                    list2.AddRange(by.FindElements(context));
                }
                else
                {
                    foreach (IWebElement current in list)
                    {
                        list2.AddRange(current.FindElements(by));
                    }
                }
                list = list2;
            }
            return(list.AsReadOnly());
        }
        public static ReadOnlyCollection <IWebElement> BestMatchedElements(By by, string framePath = null, By byOfRoot = null)
        {
            if (!string.IsNullOrEmpty(framePath))
            {
                CurrentSwitchTo(framePath);
            }

            ReadOnlyCollection <IWebElement> result = null;
            IWebElement root = Driver.FindElement(byOfRoot ?? UIContainer.DefaultByOfRoot);

            result = by.FindElements(root);
            if (result.Count() != 0)
            {
                return(result);
            }

            IEnumerable <IWebElement> frames = By.CssSelector("frame, iframe").FindElements(Driver);

            foreach (var frame in frames)
            {
                string frameNameOrId = null;
                if (frame.TryGetAttribute("name", out frameNameOrId) || frame.TryGetAttribute("id", out frameNameOrId))
                {
                    result = BestMatchedElements(by, frameNameOrId, byOfRoot);
                    if (result.Count() != 0)
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
Example #5
0
 public ReadOnlyCollection <IWebElement> FindElements(By by)
 {
     if (by == null)
     {
         throw new ArgumentNullException("by", "by cannot be null");
     }
     return(by.FindElements(this));
 }
Example #6
0
        /// <summary>
        ///     Finds the elements on the page by using the <see cref="By" /> object and returns a ReadOnlyCollection of the
        ///     Elements on the page
        /// </summary>
        /// <param name="by">By mechanism to find the element</param>
        /// <returns>ReadOnlyCollection of IWebElement</returns>
        /// <example>
        ///     <code>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// ReadOnlyCollection<![CDATA[<IWebElement>]]> classList = driver.FindElements(By.ClassName("class"));
        /// </code>
        /// </example>
        public async Task <ReadOnlyCollection <IWebElement> > FindElements(By by,
                                                                           CancellationToken cancellationToken = new CancellationToken())
        {
            if (by == null)
            {
                throw new ArgumentNullException(nameof(by), "by cannot be null");
            }

            return(await by.FindElements(this, cancellationToken));
        }
Example #7
0
 private object CheckElementAvailability()
 {
     try
     {
         var elements = _elementSelector.FindElements(_remoteWebDriver);
         return(elements.SingleOrDefault(e => e.Displayed) != null);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context)
 {
     try
     {
         string id         = control.Locator.FindElement(control.SearchContext).GetAttribute("id");
         string newId      = changeIdStrategy.ChangeId(id);
         By     newLocator = Id(newId);
         return(newLocator.FindElements(context));
     }
     catch (Exception)
     {
         return(new ReadOnlyCollection <IWebElement>(new IWebElement[0]));
     }
 }
Example #9
0
        public ArrayInstance FindElements(SearchContextInstance searchContext)
        {
            if (searchContext == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A Search Context must be specified.");
            }

            var result      = m_by.FindElements(searchContext.SearchContext);
            var resultArray = this.Engine.Array.Construct();

            foreach (var r in result)
            {
                ArrayInstance.Push(resultArray, new WebElementInstance(this.Engine.Object.InstancePrototype, r));
            }

            return(resultArray);
        }
Example #10
0
 /// <summary>
 /// Finds the elements on the page by using the <see cref="By"/> object and returns a ReadOnlyCollection of the Elements on the page
 /// </summary>
 /// <param name="by">By mechanism to find the element</param>
 /// <returns>ReadOnlyCollection of IWebElement</returns>
 public ReadOnlyCollection<IWebElement> FindElements(By by)
 {
     return by.FindElements(this);
 }
 /// <summary>
 /// Finds the elements on the page by using the <see cref="By"/> object and returns a ReadOnlyCollection of the Elements on the page.
 /// </summary>
 /// <param name="by">By mechanism for finding the object.</param>
 /// <returns>ReadOnlyCollection of IWebElement.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> classList = driver.FindElements(By.ClassName("class"));
 /// </code>
 /// </example>
 public ReadOnlyCollection<IWebElement> FindElements(By by)
 {
     return by.FindElements(new Finder(driver, elementHandle));
 }
Example #12
0
        public override IWebElement FindElement(ISearchContext context)
        {
            ReadOnlyCollection <IWebElement> elements = by.FindElements(context);

            return(elements.Where(condition).Single());
        }
 /// <summary>
 /// Finds the elements on the page by using the <see cref="By"/> object and returns a ReadOnlyCollection of the Elements on the page.
 /// </summary>
 /// <param name="by">By mechanism for finding the element.</param>
 /// <returns>ReadOnlyCollection of IWebElement.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> classList = driver.FindElements(By.ClassName("class"));
 /// </code>
 /// </example>
 public ReadOnlyCollection<IWebElement> FindElements(By by)
 {
     return by.FindElements(new Finder(this, new SafeInternetExplorerWebElementHandle()));
 }
        public ReadOnlyCollection <IWebElement> FindElements(By by)
        {
            ISearchContext ctx = CreateSearchContext(_my);

            return(by.FindElements(ctx));
        }
Example #15
0
 public ReadOnlyCollection <IWebElement> FindElements(By @by)
 {
     return(@by.FindElements(containerLocator.FindElement(parentSearchContext)));
 }
Example #16
0
 /// <summary>
 /// Finds the elements on the page by using the <see cref="By"/> object and returns a ReadOnlyCollection of the Elements on the page.
 /// </summary>
 /// <param name="by">By mechanism for finding the object.</param>
 /// <returns>ReadOnlyCollection of IWebElement.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> classList = driver.FindElements(By.ClassName("class"));
 /// </code>
 /// </example>
 public ReadOnlyCollection <IWebElement> FindElements(By by)
 {
     return(by.FindElements(new Finder(driver, elementHandle)));
 }
Example #17
0
 public ReadOnlyCollection <IWebElement> FindElements(By mechanism)
 {
     return(mechanism.FindElements(new ElementFinderContext(currentNode, webBrowser)));
 }
 public override ReadOnlyCollection <IWebElement> FindElements(ISearchContext context)
 {
     return(By.FindElements(context));
 }
Example #19
0
 public ReadOnlyCollection <IWebElement> FindElements(By by)
 {
     return(by.FindElements(this));
 }
Example #20
0
        /// <summary>
        /// Finds all <see cref="IWebElement">IWebElements</see> within the current context 
        /// using the given mechanism.
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <returns>A <see cref="ReadOnlyCollection{T}"/> of all <see cref="IWebElement">WebElements</see>
        /// matching the current criteria, or an empty list if nothing matches.</returns>
        public ReadOnlyCollection<IWebElement> FindElements(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException("by", "by cannot be null");
            }

            return by.FindElements(this);
        }
 /// <summary>
 /// Finds the elements on the page by using the <see cref="By"/> object and returns a ReadOnlyCollection of the Elements on the page.
 /// </summary>
 /// <param name="by">By mechanism for finding the element.</param>
 /// <returns>ReadOnlyCollection of IWebElement.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// ReadOnlyCollection<![CDATA[<IWebElement>]]> classList = driver.FindElements(By.ClassName("class"));
 /// </code>
 /// </example>
 public ReadOnlyCollection <IWebElement> FindElements(By by)
 {
     return(by.FindElements(new Finder(this, new SafeInternetExplorerWebElementHandle())));
 }