/// <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); }
private IEnumerable <IWebElement> FindMe() { WrappedDriver.WaitForAjax(_timeoutMs); _webElements = WebElementsCache.GetCachedElements(this.ToString()); if (IsStale()) { var stopwatch = Stopwatch.StartNew(); if (_container != null) { var root = _container.FindMe(); if (_frame != null) { Logger.Log($"Select frame {_frame}"); WrappedDriver.SwitchTo().Frame(_frame.FindMe()); } if (FindHidden) { Logger.Log($"Find {this}"); _webElements = root.FindElements(_by); } else { Logger.Log($"Find visible {this}"); _webElements = root.FindVisibleElements(_by); } } else { if (_frame != null) { Logger.Log($"Select frame {_frame}"); WrappedDriver.SwitchTo().Frame(_frame.FindMe()); } if (FindHidden) { Logger.Log($"Find {this}"); _webElements = WrappedDriver.FindElements(_by); } else { Logger.Log($"Find visible {this}"); _webElements = WrappedDriver.FindVisibleElements(_by); } } foreach (var ele in _webElements) { if (TestContext.CurrentContext.TestConfig.HighlightElements) { ele.Highlight(50, "red"); } } stopwatch.Stop(); Logger.Log($"Found {_webElements.Count()} Elements {_by} after {stopwatch.ElapsedMilliseconds} ms"); } _elements = new List <Element>(); int i = 1; foreach (var webele in _webElements) { var elem = new Element(webele, by, i); elem.WrappedElement = webele; _elements.Add(elem); WebElementCache.SaveElementToCache(webele, this.ToString(), i); i++; } WebElementsCache.SaveElementsToCache(_webElements.ToList(), this.ToString()); return(_webElements); }