private static IEnumerable<IWebElement> FindAll(ISearchContext iFind, ByEx byEx, int retries, int milliseconds) { var elements = byEx.FilterElements(iFind.FindElements(byEx.By)); while ((retries > 0) && elements.Count() == 0) { Thread.Sleep(milliseconds); elements = byEx.FilterElements(iFind.FindElements(byEx.By)); retries--; } return elements; }
public static IWebElement FindElement(this ISearchContext iFind, ByEx byEx) { IWebElement e = null; int tryCount = 0; while ((tryCount < MAX_RETRIES) && e == null) { e = byEx.FilterElements(iFind.FindElements(byEx.By)).FirstOrDefault(); tryCount++; if (e == null) { Thread.Sleep(1000); } } if (e == null) // fail normally with built-in FindElement { if (byEx.GetType() == typeof(ByEx)) { e = iFind.FindElement(byEx.By); } else { // default FindElement(By) won't find it throw new NoSuchElementException(); } } return e; }