I’m just starting with JavaScript and Puppeteer. I attempted the following login script, but it didn’t work properly. However, when I created newPage
, the login was successful. What steps can I take to resolve this issue?
const USER_CREDENTIALS = require('./user_credentials');
async function run() {
const puppeteer = require('puppeteer');
const browserInstance = await puppeteer.launch({headless: false});
const loginPage = await browserInstance.newPage();
await loginPage.setViewport({width: 1200, height: 720});
await loginPage.goto('https://www.example.com');
await loginPage.waitForNavigation();
await loginPage.type('#username', USER_CREDENTIALS.username);
await loginPage.type('#password', USER_CREDENTIALS.password);
await loginPage.click('#submit');
const secondaryPage = await browserInstance.newPage();
await secondaryPage.setViewport({width: 1200, height: 720});
await secondaryPage.goto('https://example.org');
await secondaryPage.type('#search', 'Puppeteer Automation');
}
run();