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.

.waitForFunction() should return a value

See original GitHub issue

It seems that as for now, .waitForFunction() just checks for the truthiness of the returned value in the frame context, which is then discarded. It is impossible to implement any functionality that waits for the function’s Promise actually returning a value and using that value in the Node context.

One possible scenario would be using .waitForFunction to wait for a specific <option> tag with a specific label and returning instead its value.

I could simulate it with .evaluate() but I would lose the polling/timeout configuration options.

Version: 1.0.0-rc Platform: Linux NodeJS:: v9.x

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

2reactions
marco-pragliolacommented, Jan 3, 2018

@yujiosaka Actually, .waitForXPath was the thing I was missing at the beginning. Then, trying some hacks and workarounds, I came up with this question. But yes, it could solve some scenarios.

It is very common to do tests or scraping based on the presence of some inner HTML and not a tag, class or id by itself.

1reaction
marco-pragliolacommented, Jan 2, 2018

@yujiosaka but your label attribute makes no sense, it should be value, with label I am referring to the innerHTML of the option. Which is impossible to check via selectors.

Practical example: a page is loaded with a select tag. The dropdown is filled via AJAX with some option tags like:

<option value="45">Foo</option>
<option value="66">Bar</option>

I have to intercept the option whose innerHTML is Foo and retrieve its value (45). I’d expect to do something like:

const retrievedValue = await page.waitForFunction((arg1, arg2, ...) => {
     // fancy stuff here
     return value;
}, options, arg1, arg2, ...);

This would be super because I can pass arguments and specify polling type and timeout. But I have to do some serious hacks to retrieve that value.

This is only a particular case, anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass a function inside page.waitForFunction() with puppeteer
waitForFunction() accepts a callback and right now you're passing in a ... This results in the return value of the callback (a boolean ......
Read more >
Puppeteer waitForFunction - tools4testing
waitForFunction method waits till the supplied function evaluates to true. waitForFunction method returns the promise with the JSHandle of the truthy value.
Read more >
puppeteer.Page.waitForFunction JavaScript and Node.js code ...
Allows waiting for various conditions. Most used puppeteer functions. launch. The method launches a browser instance with given arguments. The browser will be ......
Read more >
Page.waitForFunction() method - Puppeteer
waitForFunction() can be used to observe viewport size change: import puppeteer from 'puppeteer'; (async () => { const browser = await puppeteer.launch();
Read more >
Puppeteer documentation - DevDocs
If no element matches the selector, the return value resolves to null . ... waitForFunction(). if selectorOrFunctionOrTimeout is a number , then the...
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