question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chrome dev console result and puppeteer result is different

See original GitHub issue

when i was scrapping innerHTML using puppeteer, first test using chrome dev console

document.querySelector("div#c_food_tab1 div#mCSB_4_container").innerHTML;

is return good result so copy & paste this code to my src and run code

result is Error

(node:4895) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property ‘innerHTML’ of null

so i decided to fix my code that HTML element select all course of target

const profRestaurant = await page.evaluate( () => document.querySelector("div#c_food_tab1 div#mCSB_5 div#mCSB_5_container") .innerHTML );

then code is working

i wondering about why their(chrome dev console, puppeteer) return different result

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
vsemozhetbytcommented, Feb 12, 2019

The layout and DOM structure of the page depends on the viewport size. When you test on the common browser, the viewport is wide and the page has "div#c_food_tab1 div#mCSB_4_container" selector. Puppeteer sets an initial viewport size to 800px x 600px, so with puppeteer script the viewport is narrow and the page has "div#c_food_tab1 div#mCSB_5 div#mCSB_5_container" instead of "div#c_food_tab1 div#mCSB_4_container". If you add this line in your first script, it will work properly (you can set any other wide size):

  await page.setViewport({ width: 1280, height: 720 });
  await page.goto("https://portal.dankook.ac.kr/web/portal");
1reaction
Manngoldcommented, Feb 12, 2019

@vsemozhetbyt Oh, viewport! wonderful thanks to your help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer vs Chrome console log different behaviour
First I check with Chrome inspect and console how to find the right value and it was everything ok. Then I paste the...
Read more >
Debugging Puppeteer - Chrome Developers
# Use debugger in node.js ... This will let you debug test code. For example, you can step over await page.click() in the...
Read more >
Using Chrome Devtools Protocol with Puppeteer
Puppeteer is a high level abstraction over the Chrome Devtools Protocol that gives you a user-friendly API to drive Chromium (or Blink) based...
Read more >
Devtools Service - WebdriverIO
A WebdriverIO service that allows you to run Chrome DevTools commands in your tests ... The following commands with their results are available: ......
Read more >
Playing with Puppeteer - Level Up Coding
I used the developer homepage and set the locale to en-US to ensure I will only get English results. Using the chrome developer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found