Waits for a page load to complete
import {
openBrowser, openTab, findElement, clickElement, waitForNavigation
} from 'puppet-strings'
async function run() {
const browser = await openBrowser('google-chrome')
const tab = await openTab(browser, 'https://npmjs.com')
const lodashLink = await findElement(tab, 'a', 'lodash')
clickElement(lodashLink)
await waitForNavigation(tab)
}
run()
tab
(Tab)
promise
(Promise)
For actions that cause a separate page to be loaded, like
- Clicking on a link
- Submitting a native form
- Being redirected by application code
it is currently necessary to waitForNavigation
before performing further
actions.
waitForNavigation
waits until the page is fully loaded and has not made a
network request for 500ms
. Note that WebSocket connections are ignored.
openTab
will always wait for the page to finish loading. So,
when opening a new tab, it's unnecessary to also waitForNavigation
.