public WebDriver Prefix(SelectorPrefix prefix) { var p = new ValidatedPrefix(); var l = Prefixes.Concat(prefix); var possibles = l.CrossMultiply(); RetryExecutor.RetryFor(() => { var iframes = SeleniumDriver.FindElements(By.XPath("//iframe")); var valid = possibles.AsParallel().AsOrdered().Where(xpath => SeleniumDriver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } else if (iframes.Any()) { foreach (var iframe in iframes) { try { SeleniumDriver.SwitchTo().Frame(iframe); valid = possibles.AsParallel().AsOrdered().Where(xpath => SeleniumDriver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } } catch { } } SeleniumDriver.SwitchTo().DefaultContent(); } if (!p.IsInitialized) { throw new Exception($"Was unable to find any that matched prefix, tried:{possibles.LogFormat()}"); } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs)); var wdm = new WebDriver( SeleniumDriver, RootUrl, SeleniumGridConfiguration, RetryExecutor, SelectorFactory, ElementFactory, XpathProvider, MovieLogger, WebElementSourceLog, new List <SelectorPrefix> { p } ); Children.Add(wdm); return(wdm); }
public WebDriver Prefix(SelectorPrefix prefix) { var p = new ValidatedPrefix(); var l = Prefixes.Concat(prefix); var possibles = l.CrossMultiply(); RetryExecutor.RetryFor(() => { var valid = possibles.AsParallel().AsOrdered().Where(xpath => Driver.FindElements(By.XPath(xpath)).Any()).ToList(); if (valid.Any()) { p.Init("filtered", valid); } else { throw new Exception($"Was unable to find any that matched prefix, tried:{possibles.LogFormat()}"); } }, TimeSpan.FromMilliseconds(SeleniumGridConfiguration.RetryMs)); var wdm = new WebDriver( Driver, RootUrl, SeleniumGridConfiguration, RetryExecutor, SelectorFactory, ElementFactory, XpathProvider, MovieLogger, new List <SelectorPrefix> { p } ); Children.Add(wdm); return(wdm); }