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.

page.evalute() does not work as described

See original GitHub issue
  • Puppeteer version: 0.13.0
  • Platform / OS version: Sierra 10.12.6
  • URLs (if applicable):
  • Node.js version: v8.9.0

I am trying to create reference to a DOM element with page.evalute() like so:

    const myElement = (await page.evaluate( () => {
        let overflowDiv = document.querySelectorAll('.overflow')[0];
        let buttonDiv = overflowDiv.children[1];
        let listsButton = buttonDiv.children[0]; 
        return listsButton;   
    }))();

    await page.click(myElement);

However, I get a TypeError that myElement is not a function. According to the documentation it is supposed to resolve a promise. What am I dong wrong?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
aslushnikovcommented, Jan 10, 2018

@IgorDraskovic ah sorry, you should use page.evaluateHandle instead of page.evaluate.

    const myElement = await page.evaluateHandle(() => {
        let overflowDiv = document.querySelectorAll('.overflow')[0];
        let buttonDiv = overflowDiv.children[1];
        let listsButton = buttonDiv.children[0]; 
        return listsButton;   
    });
    await myElement.click();
0reactions
aslushnikovcommented, Mar 15, 2019

@mdrazahassan plz file a separate issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer page.evaluate not working as expected
I have a console log before I run page.evaluate() which logs what I expect, but the console log inside page.evaluate never runs. const...
Read more >
Page.evaluate() method - Puppeteer
Page.evaluate() method. Evaluates a function in the page's context and returns the result. If the function passed to page.evaluateHandle returns a Promise, ...
Read more >
puppeteer.Page.evaluate JavaScript and Node.js ... - Tabnine
Evaluates a function in the browser context. If the function, passed to the frame.evaluate, returns a Promise, then frame.evaluate would wait for the...
Read more >
Variable not defined with page.evaluate in Puppeteer - YouTube
Your browser can 't play this video. Learn more. Switch camera.
Read more >
Puppeteer documentation - DevDocs
NOTE Puppeteer can also be used to control the Chrome browser, but it works best with the version of Chromium it is bundled...
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