-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
Implement page.$$ method #463
Conversation
docs/api.md
Outdated
- `selector` <[string]> Selector to query page for | ||
- returns: <[Promise]<[Array]<[ElementHandle]>>> Promise which resolves to ElementHandles pointing to the page elements. | ||
|
||
The method queries page for all elements matching selector. If there are no such elements within the page, the method will resolve to `[]`. |
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.
Let's have the description here as above.
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.
Done
test/test.js
Outdated
it('should query existing elements', SX(async function() { | ||
await page.setContent('<div>A</div><br/><div>B</div>'); | ||
let elements = await page.$$('div'); | ||
expect(elements.length).toBe(2); |
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.
Let's dump the content, so we at least know that it is creating ElementHandles.
expect(await Promise.all(elements.map(e => e.evaluate(g => g.textContent)))).toEqual(['A','B'])
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.
Done.
@@ -27,6 +27,7 @@ | |||
+ [event: 'requestfinished'](#event-requestfinished) | |||
+ [event: 'response'](#event-response) | |||
+ [page.$(selector)](#pageselector) | |||
+ [page.$$(selector)](#pageselector) |
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.
Should be #pageselector-1
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.
Unfortunately, this is a bug in the toc-generator.
@@ -85,6 +86,7 @@ | |||
+ [dialog.type](#dialogtype) | |||
* [class: Frame](#class-frame) | |||
+ [frame.$(selector)](#frameselector) | |||
+ [frame.$$(selector)](#frameselector) |
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.
Should be #frameselector-1
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.
Ditto here
docs/api.md
Outdated
|
||
The method runs `document.querySelectorAll` within the page. If no elements match the selector, the return value resolve to `[]`. | ||
|
||
Shortcut for [page.mainFrame().$$(selector)](#frameselector). |
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.
Should be #frameselector-1
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.
Done
docs/api.md
Outdated
@@ -978,6 +988,11 @@ puppeteer.launch().then(async browser => { | |||
|
|||
The method queries page for the selector. If there's no such element within the page, the method will resolve to `null`. | |||
|
|||
#### frame.$$(selector) | |||
- `selector` <[string]> Selector to query page for | |||
- returns: <[Promise]<[Array]<[ElementHandle]>>> Promise which resolves to ElementHandles pointing to the page elements. |
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 wonder, maybe all the page
instances should be replaced by frame
in frame
API descriptions when appropriate?
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.
Done.
This patch implements page.$$ which runs document.querySelectorAll in page and returns results as an array of ElementHandle instances. Fixes puppeteer#384.
d3d1e48
to
54daeb3
Compare
const promises = elements.map(element => element.evaluate(e => e.textContent)); | ||
expect(await Promise.all(promises)).toEqual(['A', 'B']); | ||
})); | ||
it('should return ampty array if nothing is found', SX(async function() { |
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.
ampty
typo 😂 ?
This patch implements page.$$ that runs document.querySelectorAll
in page and returns results as an array of ElementHandle instances.
Fixes #384.