elements property

List<Element> get elements

Implementation

List<Element> get elements {
  Element base;
  if (_parentElement == null) {
    base = document.body!;
  } else {
    base = _parentElement!._single;
  }

  Iterable<Element> elements;
  if (_finder == null) {
    elements = [_cachedElement ?? base];
  } else if (_finder is ContextFinder) {
    elements = (_finder as ContextFinder)
        .findElements(_parentElement!)
        .map((p) => p.context);
  } else if (_finder is CssFinder) {
    elements = base.querySelectorAll((_finder as CssFinder).cssSelector);
  } else {
    throw 'Unknown Finder type, ${_finder.runtimeType}';
  }

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