waitForSelector method
Wait for the selector
to appear in page. If at the moment of calling
the method the selector
already exists, the method will return
immediately. If the selector 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.waitForSelector('img');
await page.goto('https://example.com');
var image = await watchImg;
print(await image!.propertyValue('src'));
await browser.close();
}
Shortcut for page.mainFrame.waitForSelector
.
Parameters:
- A
selector
of an element to wait for visible
: wait for element to be present in DOM and to be visible, i.e. to not havedisplay: none
orvisibility: hidden
CSS properties. Defaults tofalse
.hidden
: wait for element to not be found in the DOM or to be hidden, i.e. havedisplay: none
orvisibility: hidden
CSS properties. Defaults tofalse
.timeout
: maximum time to wait for. Pass Duration.zero to disable timeout. The default value can be changed by using thepage.defaultTimeout
property.
Returns a Future which resolves when element specified by selector string
is added to DOM. Resolves to null
if waiting for hidden: true
and selector
is not found in DOM.
Implementation
Future<ElementHandle?> waitForSelector(String selector,
{bool? visible, bool? hidden, Duration? timeout}) {
return mainFrame.waitForSelector(selector,
visible: visible, hidden: hidden, timeout: timeout);
}