Skip to content
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

Recursive $/$$ #508

Closed
notgne2 opened this issue Aug 23, 2017 · 3 comments
Closed

Recursive $/$$ #508

notgne2 opened this issue Aug 23, 2017 · 3 comments
Assignees
Labels

Comments

@notgne2
Copy link

notgne2 commented Aug 23, 2017

Maybe add the ability to get child elements on ElementHandle instances, using $, and $$, syntax should work like:

let $header = await page.$("div.header")
let $homeLink = await $header.$("a.home")

await $homeLink.click()

Along with $$, this would make iterating pages with recursive structures so much more easier, no longer requiring it all to be kept inside of .evaluate callbacks.

Such as:

let $results = await page.$$(".result")

for (let $result of $results) {
    let $title = await $result.$(".title")

    let title await $title.evaluate(($) => $.innerText)
    console.log(`Title: ${title}`)

    let resUrl = await $title.evaluate(($) => $.href)
    console.log(`Result URL: ${resUrl}`)
    
    let $sourceLinks = await $result.$$(".sources")

    for (let $sourceLink of $sourceLinks) {
        let sourceUrl = await $sourceLink.evaluate(($) => $.href)
        console.log(`Source URL: ${sourceUrl}`)
    }
}

Don't think this would be too hard to implement, and work make automation a lot easier

@aslushnikov
Copy link
Contributor

This gonna be a part of object handles story: #382

@kidwm
Copy link

kidwm commented Oct 18, 2017

@aslushnikov So when can we use something like ElementHandle.$()?

@aslushnikov
Copy link
Contributor

@kidwm I'd be happy to review a pull request with tests and documentation. This should be easy to do similarly to the Frame.$ and Frame.$$. Check out the CONTRIBUTING.md for the tips on development and running tests.

aslushnikov pushed a commit that referenced this issue Oct 27, 2017
This patch adds `ElementHandle.$` and `ElementHandle.$$` methods to query nested
elements.

Fixes #508
ithinkihaveacat pushed a commit to ithinkihaveacat/puppeteer that referenced this issue 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
Projects
None yet
Development

No branches or pull requests

4 participants