waitForXPath method

Future<ElementHandle?> waitForXPath(
  1. String xpath, {
  2. bool? visible,
  3. bool? hidden,
  4. Duration? timeout,
})

Wait for the xpath to appear in page. If at the moment of calling the method the xpath already exists, the method will return immediately. If the xpath doesn't appear after the timeout of waiting, the function will throw.

This method works across navigations:

import 'package:puppeteer/puppeteer.dart';

void main() async {
  var browser = await puppeteer.launch();
  var page = await browser.newPage();
  var watchImg = page.waitForXPath('//img');
  await page.goto('https://example.com');
  var image = await watchImg;
  print(await image!.propertyValue('src'));
  await browser.close();
}

Shortcut for page.mainFrame.waitForXPath.

Parameters:

  • A xpath of an element to wait for
  • visible: wait for element to be present in DOM and to be visible, i.e. to not have display: none or visibility: hidden CSS properties. Defaults to false.
  • hidden: wait for element to not be found in the DOM or to be hidden, i.e. have display: none or visibility: hidden CSS properties. Defaults to false.
  • timeout: maximum time to wait for. Pass Duration.zero to disable timeout. The default value can be changed by using the page.defaultTimeout property.

Returns a Future which resolves when element specified by xpath string is added to DOM. Resolves to null if waiting for hidden: true and selector is not found in DOM.

Implementation

Future<ElementHandle?> waitForXPath(String xpath,
    {bool? visible, bool? hidden, Duration? timeout}) {
  return mainFrame.waitForXPath(xpath,
      visible: visible, hidden: hidden, timeout: timeout);
}