Paulo Dias
Paulo Dias

Reputation: 25

Puppeteer - Multiple page navigation

Most puppeteer examples are related with one page scraping.

How to navigate over multiple pages clicking on submit buttons on each page, simulating a user site navigation?

Upvotes: 3

Views: 1534

Answers (1)

Naycho334
Naycho334

Reputation: 167

According to the documentation,

browser.pages() returns: >> Promise which resolves to an array of all open pages. Non visible pages, such as "background_page", will not be listed here. You can find them using target.page().

const activePages = await browser.pages();

For example if there are 3 opened pages, You can handle them easily and use Page object's methods:

// take screenshots
await activePages[0].screenshot({path: 'screenshot.png' });
await activePages[1].screenshot({path: 'screenshot1.png' });
await activePages[2].screenshot({path: 'screenshot2.png' });

// close first page
await activePages[0].close();

Upvotes: 1

Related Questions