Beispiel #1
0
        /// <summary>
        /// FindMe() selects the iframe, and searches for the element.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(_timeoutMs);

            //If the element was already found, and has not gone stale, return the previously found IWebElement
            if (IsStale())
            {
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (_container != null)
                {
                    //find the root element using the container's findMe
                    var root = _container.FindMe();
                    //select an iframe if necessary
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        _webelement = root.FindVisibleElement(_by);
                    }
                    else
                    {
                        //find any element, even if its hidden
                        _webelement = root.FindElement(_by);
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        _webelement = WrappedDriver.FindVisibleElement(_by);
                    }
                    //find any element including hidden ones
                    else
                    {
                        _webelement = WrappedDriver.FindElement(_by);
                    }
                }
            }
            //highlight the element so the user can see what element was found
            //_webelement.Highlight();
            return(_webelement);
        }
Beispiel #2
0
        /// <summary>
        /// FindMe() selects the iframe, and searches for the element.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(TimeoutMs);

            //look for a non-null reference in the cache
            if (WebElement == null)
            {
                WebElement = WebElementCache.GetCachedElement(this.ToString(), Index);
            }

            //If the element was already found, and has not gone stale, return the previously found IWebElement

            if (IsStale())
            {
                var stopwatch = Stopwatch.StartNew();
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (Container != null)
                {
                    //find the root element using the container's findMe
                    var root = Container.FindMe();
                    //select an iframe if necessary
                    if (Frame != null)
                    {
                        Logger.Log($"Select frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }

                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = root.FindVisibleElement(By);
                    }
                    else
                    {
                        Logger.Log($"Finding {this}");

                        //find any element, even if its hidden
                        WebElement = root.FindElement(By);
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (Frame != null)
                    {
                        Logger.Log($"Selecting frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = WrappedDriver.FindVisibleElement(By);
                    }
                    //find any element including hidden ones
                    else
                    {
                        Logger.Log($"Finding {this}");

                        WebElement = WrappedDriver.FindElement(By);
                    }
                }
                stopwatch.Stop();
                Logger.Log($"{this} found after {stopwatch.ElapsedMilliseconds} ms");
                //save the found element to the cache
                WebElementCache.SaveElementToCache(WebElement, this.ToString(), Index);
            }

            return(WebElement);
        }