/// <summary> /// FindMe() selects the iframe, and waits for the element to appear. 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() { var wait = new WebDriverWait(WrappedDriver, TimeSpan.FromMilliseconds(_timeoutMs)); wait.Message = $"{this} was not found"; //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 = wait.Until(drv => root.FindVisibleElement(_by)); } else { //find any element, even if its hidden _webelement = wait.Until(drv => 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 = wait.Until(drv => drv.FindVisibleElement(_by)); } //find any element including hidden ones else { _webelement = wait.Until(drv => drv.FindElement(_by)); } } } //highlight the element so the user can see what element was found _webelement.Highlight(); return(_webelement); }
public IEnumerable <IWebElement> FindMe() { var wait = new WebDriverWait(WrappedDriver, TimeSpan.FromMilliseconds(_timeoutMs)); wait.Message = $"{this} was not found"; WrappedDriver.WaitForAjax(_timeoutMs); if (IsStale()) { if (_container != null) { var root = _container.FindMe(); if (_frame != null) { WrappedDriver.SwitchTo().Frame(_frame.FindMe()); } if (FindHidden) { _webElements = wait.Until(drv => root.FindElements(_by)); } else { _webElements = wait.Until(drv => root.FindVisibleElements(_by)); } } else { if (_frame != null) { WrappedDriver.SwitchTo().Frame(_frame.FindMe()); } if (FindHidden) { _webElements = wait.Until(_driver => _driver.FindElements(_by)); } else { _webElements = wait.Until(_driver => _driver.FindVisibleElements(_by)); } } } _elements = new List <Element>(); foreach (var webele in _webElements) { webele.Highlight(); var elem = new Element(by); elem.WrappedElement = webele; _elements.Add(elem); } return(_webElements); }
/// <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); }