简体   繁体   中英

How to Navigate to 2nd Url (angular7) after success login in 1st Url

Can some one help me out.... how to navigate to angular7 page from the non-angular page by changing the url.

please find my code snippet below:

const puppeteer = require('puppeteer');

async function getPic() {

    const browser = await puppeteer.launch({
        headless : false,
        args     : ['--window-size=1920,1080']
    });
    const page = await browser.newPage();

    //1st url is non angular page
    await page.goto('https://LT.html', {
        waitUntil : 'networkidle2',
        timeout   : 3000000
    });

    await page.waitForSelector('#login-form #userInput');
    await page.click('#login-form #userInput');

    await page.type('#login-form #userInput', 'rkatkam');

    await page.waitForSelector('#login-form #passwordInput');
    await page.click('#login-form #passwordInput');

    await page.type('#login-form #passwordInput', 'cisco123');

    await page.waitForSelector('#login-wrapper > #login #login-button');

    await Promise.all([
        page.waitForNavigation(),
        page.click('#login-wrapper > #login #login-button')
    ]);

    //now after getting the authentication success, i have to navigate to 2nd url (my actual application url
    // this is angular7 page. this page takes time to load by that time my script is timing out 
    //timeout 30000ms exceeded
    await page.goto('https://myactualapplication/', { //2nd url
        // networkIdleTimeout: 5000,
        waitUntil: 'networkidle2'  
    });

}

getPic();

Try to set page.setDefaultTimeout "globally", after the const page = await browser.newPage(); command. Like this:

const page = await browser.newPage();

// add this line:
await page.setDefaultTimeout(5*60*1000); // 5 minutes in miliseconds

// rest of the code...

If your page takes more than 5 minutes, increase the timeout.

Also in your code there is "networkIdleTimeout". This has no effect to puppeteer, since it's not recognized.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM