Skip to content

Conversation

@sheerun
Copy link
Contributor

@sheerun sheerun commented Oct 24, 2017

Fixes #508

Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sheerun, Thanks for the PR!

This is three PRs in one:

  • ElementHandle.$/ElementHandle.$$
  • ElementHandle.content()
  • JSHandle.evaluate() (i'm not comfortable with this method name, given its current semantics)

I'd like this PR to be scoped to the ElementHandle.$/ElementHandle.$$ since it seems to be the most important. If you have time, I'd be happy to review other PR's.

* @param {!Array<*>} args
* @return {!Promise<*>}
*/
async evaluate(pageFunction, ...args) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the evaluate and evaluateHandle methods as they are in this PR: they are named similarly to page.evaluate but have a different semantics, passing in the element as a first argument. They also should belong to JSHandle rather then ElementHandle.

* @return {!Promise<String>}
*/
async content() {
return this.evaluate(e => e.outerHTML, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice, I'd love to see this in a separate PR with a test.

* @param {string} selector
* @return {!Promise<?ElementHandle>}
*/
async $(selector) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a test for this and for $$?

@sheerun
Copy link
Contributor Author

sheerun commented Oct 24, 2017

Please guide me where and how to write tests for this feature

@aslushnikov
Copy link
Contributor

Please guide me where and how to write tests for this feature

@sheerun sure:

@sheerun
Copy link
Contributor Author

sheerun commented Oct 24, 2017

In what file tests for this feature should be?

@aslushnikov
Copy link
Contributor

@sheerun all tests live in a test/test.js file. You can add a testsuite next to the Page.$ / Page.$$ test suites.

@sheerun
Copy link
Contributor Author

sheerun commented Oct 25, 2017

@aslushnikov I've done what you asked for

Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Can you please run npm run doc to regenerate the table-of-contents and please the linter?

test/test.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just put describe('ElementHandle.$', ..) and describe('ElementHandle.$$', ..) test suites somewhere next to other ElementHandle test suites. This will save you work for setting up a browser, and also will make tests faster since you'll avoid re-launching the browser.

@sheerun sheerun force-pushed the element branch 2 times, most recently from a138d30 to 5aadb15 Compare October 25, 2017 21:52
@sheerun
Copy link
Contributor Author

sheerun commented Oct 25, 2017

ok the tests are passing

@sheerun
Copy link
Contributor Author

sheerun commented Oct 26, 2017

the errors on travis are irrelevant

Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@aslushnikov aslushnikov merged commit 5ffbd0d into puppeteer:master Oct 27, 2017
ithinkihaveacat pushed a commit to ithinkihaveacat/puppeteer that referenced this pull request Oct 31, 2017
…eer#1151)

This patch adds `ElementHandle.$` and `ElementHandle.$$` methods to query nested
elements.

Fixes puppeteer#508
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants