-
Notifications
You must be signed in to change notification settings - Fork 9.3k
feature(ElementHandle) #2407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(ElementHandle) #2407
Conversation
Add `$eval`, `$$eval`,`mainFrame` to ElementHandle. Fixes puppeteer#2401
Remove trailing space.
lib/ElementHandle.js
Outdated
| * @return {!Promise<(!Object|undefined)>} | ||
| */ | ||
| async $eval(selector, pageFunction, ...args) { | ||
| return this.mainFrame().$eval(selector, pageFunction, ...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abalone0204, thanks for your first PR!
as far as I understand, the idea is to have a selector on the subtree of a selected element (from the issue: I'd like to get a reference to a DOM node and run one-liners against the subtree.)
here you have a new selector on mainFrame, which is not necessarily on element's subtree.
For example:
<div class="a">not-a-child-div</div>
<div id="my-id">
<div class="a">a-child-div</div>
</div>
Now, with your implementation, the following test will fail:
const handle = await page.$('#my-id');
expect(await handle.$eval('.a', node => node.innerText)).toBe('a-child-div');
it can actually be a good test case for you (:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yanivefraim Thanks!
I can dig on it now.
Reimplement the `$eval` function
Test `$eval`.
lib/ElementHandle.js
Outdated
| * @return {!Promise<(!Object|undefined)>} | ||
| */ | ||
| async $eval(selector, pageFunction, ...args) { | ||
| const elementHandle = await this.$(selector); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once you have this in place, you can re-use this inside Frame.$eval, similarly to how it's done for Frame.$.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, Just finished it.
Refactor `frame.$eval` with `elementHandle.$eval` according to reviewer.
Add doc for `elementHandle` and provide an example.
Move `$eval` to right place.
|
@abalone0204 the code is good. Do you plan to do |
|
@aslushnikov Thank you. Glad to hear that. |
|
@abalone0204 Someone marked checkboxes for "$$eval" for this PR; however, I don't see any code related to this. Some kind of error? |
|
@abalone0204 do you need help here? another option is to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge this as-is; the page.$$eval is yet to be implemented.
Description
Add
$evalto ElementHandle and also refactor theframe.$evalwithelementHandle.$eval.Fixes #2401.
Progress
$eval:npm run lint$$eval:npm run lint