private IEnumerable <TElement> GetAndWaitWebDriverElements() { if (_shouldCacheFoundElements && _cachedElements == null) { _cachedElements = GetAndWaitNativeElements().ToList(); } if (_shouldCacheFoundElements && _cachedElements != null) { foreach (var element in _cachedElements) { yield return(element); } } else { foreach (var element in GetAndWaitNativeElements()) { yield return(element); } } IEnumerable <TElement> GetAndWaitNativeElements() { foreach (var foundElement in _foundElements) { yield return(foundElement); } if (_parentElement != null) { var elementRepository = new ElementRepository(); foreach (var nativeElement in _by?.FindAllElements(_parentElement)) { var element = elementRepository.CreateElementThatIsFound <TElement>(_by, (WindowsElement)nativeElement); yield return(element); } } else { var elementRepository = new ElementRepository(); foreach (var nativeElement in _by?.FindAllElements(WrappedDriver)) { var element = elementRepository.CreateElementThatIsFound <TElement>(_by, nativeElement); yield return(element); } } } }
// TODO: This is a technical debt, for the case with _by that is not null and we want to verify the non-existance of elements public dynamic WaitWebDriverElements() { Utilities.Wait.ForConditionUntilTimeout( () => { var elements = _parentElement == null ? _by.FindAllElements(WrappedDriver) : _by.FindAllElements(_parentElement); return(elements.Any()); }, totalRunTimeoutMilliseconds: ConfigurationService.GetSection <DesktopSettings>().ElementToExistTimeout, sleepTimeMilliseconds: ConfigurationService.GetSection <DesktopSettings>().SleepInterval); var elements = _parentElement == null?_by.FindAllElements(WrappedDriver) : _by.FindAllElements(_parentElement); return(elements); }