elements property

List<WebElement> get elements

Returns all elements resolved.

Implementation

List<sync_wd.WebElement> get elements {
  sync_wd.WebElement base;
  if (_parentElement == null) {
    final root = _driver.findElements(sync_wd.By.tagName('html')).toList();
    if (root.isEmpty) {
      throw PageLoaderException('Could not find HTML tag at root');
    }
    if (root.length > 1) {
      throw PageLoaderException('Found multiple HTML tags');
    }
    base = root[0];
  } else {
    base = _parentElement!._single;
  }

  Iterable<sync_wd.WebElement> elements;
  if (_finder == null) {
    elements = [_cachedElement ?? base];
  } else if (_finder is ContextFinder) {
    elements = (_finder as ContextFinder)
        .findElements(_parentElement!)
        .map((p) => p.contextSync);
  } else if (_finder is WebElementFinder) {
    elements = [(_finder as WebElementFinder).element];
  } else if (_finder is CssFinder) {
    elements = base
        .findElements(
            sync_wd.By.cssSelector((_finder as CssFinder).cssSelector))
        .toList();
  } else {
    throw 'Unknown Finder type, ${_finder.runtimeType}';
  }

  // Filter/Checker API is based on PageLoaderElements; casting for this.
  final tempElements = elements
      .map((e) => WebDriverPageLoaderElement._castFromElement(e))
      .toList();
  final filteredElements =
      core.applyFiltersAndChecks(tempElements, _filters, _checkers);
  return filteredElements
      .map((e) => (e as WebDriverPageLoaderElement)._cachedElement!)
      .toList();
}