Newboy11
Newboy11

Reputation: 3134

storing page to variable in puppeteer doesn't work

I'm trying to store the page result to a variable so I can use it to access other page but encountered an error "TypeError: Cannot read property 'waitForSelector' of undefined"

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.goto('https://www.instagram.com/accounts/login/');
  await page.waitForSelector('input[name="username"]');
  await page.type('input[name="username"]', 'username');
  await page.type('input[name="password"]', 'password');
  const mainPage = await page.click('button[type="submit"]');
  await mainPage.pdf({path: 'page.pdf', format: 'A4'});
  mainPage.goto(https://www.instagram.com/direct/inbox/);
  mainPage.waitForSelector('button[name="Send Message"]');
  //some additional code
})();

Upvotes: 0

Views: 215

Answers (1)

hardkoded
hardkoded

Reputation: 21695

page.click won't return a page. You can use waitForNavigation there.

await Promise.all([
    page.waitForNavigation(),
    page.click('button[type="submit"]')]);

Upvotes: 1

Related Questions