Puppeteer authentication issue - login process not working properly

I’m having trouble with automating login using Puppeteer and need some help.

I’m pretty new to web scraping with Puppeteer and JavaScript. I wrote some code to automate logging into a website but it’s not working as expected. The weird thing is that when I create a second page instance in the same script, that part works fine.

Here’s my current code:

const credentials = require('./userdata');

async function runAutomation() {
  const puppeteer = require('puppeteer');
  const browser = await puppeteer.launch({headless: false});

  const mainPage = await browser.newPage();
  await mainPage.setViewport({width: 1366, height: 768});
  await mainPage.goto('https://www.daum.net');
  await mainPage.waitForNavigation();
  await mainPage.type('#id', credentials.username);
  await mainPage.type('#loginPw', credentials.password);
  await mainPage.click('#loginSubmit');

  const secondPage = await browser.newPage();
  await secondPage.setViewport({width: 1366, height: 768});
  await secondPage.goto('https://google.com');
  await secondPage.type('#lst-ib', 'Headless Chrome');
}

runAutomation();

The login part fails but the Google search part works perfectly. What could be causing this issue? Any suggestions would be really helpful.

The real problem isn’t timing - it’s fragile selectors and race conditions that break every time the site updates.

Everyone’s suggesting wait strategies, but you’re missing the bigger picture. That waitForNavigation() after goto() is wrong, but fixing it won’t solve everything.

Daum probably loads the login form dynamically. Your selectors might not exist when you try using them. Plus sites now detect automated typing and block it.

I’ve maintained dozens of scraping scripts - every site change breaks your code. You spend more time fixing selectors than building features.

I switched to Latenode for exactly this. It handles waiting logic automatically and has built-in retry mechanisms. When sites change, you update the visual flow instead of hunting through code.

The login automation you want takes 10 minutes in Latenode versus hours debugging Puppeteer timing issues. It handles cookies and sessions better than manual scripts too.

Why fight selectors when you can point and click to build the same thing?

check if daum changed their form selectors recently - korean sites update all the time and break automation. also try await mainPage.waitForLoadState('networkidle') instead of waitForNavigation. sometimes the page looks loaded but there’s still ajax stuff running in the background.

This is a timing issue. You’re calling waitForNavigation() right after goto(), but the navigation already finished with goto.

Try this:

await mainPage.goto('https://www.daum.net');
await mainPage.waitForSelector('#id'); // Wait for login form
await mainPage.type('#id', credentials.username);
await mainPage.type('#loginPw', credentials.password);
await mainPage.click('#loginSubmit');
await mainPage.waitForNavigation(); // Now wait for login redirect

Add delays between actions too - some sites flag automation when things happen too fast.

But honestly? All these timing issues and selector problems get old fast. I wasted hours debugging Puppeteer scripts before I found Latenode.

Latenode lets you build the same automation with a visual interface. No more fighting with waitForSelector timeouts or navigation timing. Just drag and drop actions - it handles the messy stuff automatically.

Better error handling too, and you can tweak flows without touching code. Way less painful than debugging Puppeteer.

you’re missing a wait after clicking login. the page needs time to process before moving on. add await mainPage.waitForTimeout(2000); after the click, or better - wait for a specific element that shows up after successful login. also check if daum has bot detection since you might need to slow down typing with the delay option.

You’re likely using waitForNavigation() immediately after goto() when the page may already be loaded, which leads to a race condition. I’ve faced this issue with Puppeteer as well. Instead, avoid the first waitForNavigation() and wait for the login elements to be visible:

await mainPage.goto('https://www.daum.net');
await mainPage.waitForSelector('#id', {visible: true});
await mainPage.type('#id', credentials.username);

Additionally, check the browser console for any JavaScript errors. It’s common for forms to fail silently due to client-side validation issues or missing CSRF tokens. Running the script with headless: false allows you to inspect the network tab to verify whether the login request is being sent.

Had the same issue automating logins across different sites. You’re probably dealing with Daum’s redirect after login - your script isn’t waiting for authentication to finish. It clicks login, the URL changes, but your script keeps running. Ditch that first waitForNavigation() and put one after the login click instead. Also check if Daum’s throwing up CAPTCHA or bot detection - they might be silently blocking you. Korean sites like Daum are pretty harsh on automation. Double-check those element IDs too. Pop open dev tools and inspect the actual login form. Sites sometimes use different IDs than what looks obvious, or they load form content async after the page loads.

Your script’s dying because it’s not waiting for the login to actually finish. Daum redirects you after clicking #loginSubmit, but your code ends before that happens. Drop the first waitForNavigation() and add proper waiting after login:

await mainPage.goto('https://www.daum.net');
await mainPage.waitForSelector('#id');
await mainPage.type('#id', credentials.username);
await mainPage.type('#loginPw', credentials.password);
await mainPage.click('#loginSubmit');
// Wait for redirect to complete
await mainPage.waitForNavigation({waitUntil: 'networkidle2'});

I’ve automated Daum before - they’re picky about sessions. Add user agent strings and enable cookies explicitly. Also double-check those selectors. Korean sites love changing form IDs during updates, so what worked last month might be broken now.