when_contains method

Future<Online> when_contains(
  1. String selector,
  2. String text,
  3. MapFunc<ElementHandle, dynamic> action
)

Implementation

Future<Online> when_contains(
  String selector,
  String text,
  MapFunc<ElementHandle, dynamic> action,
) async {
  Show.waiting_for(selector, "to contain $text");
  var page = await this.page;
  await page.waitForSelector(selector);
  var element = await page.$eval(selector, '''(element, text) => {
    return Array.from(element.querySelectorAll('div,span,p,li,ul,ol,a,h1,h2,h3,h4,h5,h6')).find((e) => e.innerText.includes(text));
  }''', args: [text]);
  if (element != null) {
    await action(element);
  }
  return this;
}