waitForUrl() method is used by the playwright to wait for the specified URL till it stops loading and completes fully.
Syntax:
await page.waitForURL(url);
Arguments Used:
Url: string|RegExp|function(URL)
A glob pattern or any regex pattern receiving URL is provided to match while waiting for the navigation.
Options:
timeout: Maximum time taken in milliseconds default is 30 seconds.
waitUntil "load"|"domcontentloaded"|"networkidle"|"commit"
domcontentloaded: Operation to be finished when the domcontentloaded event is fired.
load: Operation to be completed when the load is fired.
networkidle: Operation to be completed when networkidle is fired when there are no network connections.
commit: Operation to be completed when network response is received, and the doc starts loading.
Example:
await page.goto('https://www.programsbuzz.com/');
await page.locator('.fa-search').click()
await page.locator('#edit-keys').type('Playwright')
await page.locator('#edit-submit').click()
await page.waitForURL('https://www.programsbuzz.com/search/node?keys=Playwright')
- Here we used waitForURL to the URL where when clicked on the search bar 'go.'
- This will wait for the specified URL and then prepares the page for other operations.
- Log in to post comments