I know you can capture a single html node vial the command prompt, but is it possible to do this programmatically from the console similar to Puppeteer? I'd like to loop all elements on a page and capture them for occasional one-off projects where I don't want to set up a full auth process in puppeteer.
I'm referring to this functionality:
But executed from the console like during a foreach or something like that.
See the puppeteer reference here.
Something to the effect of this:
$x("//*[contains(@class, 'special-class-name')]").forEach((el)=> el.screenshot())
Click on the 3 lines on top right corner on the browser window >> Web Developer >> Web Console. Alternatively, you can also press Ctrl+Shift+K (Windows) or Cmd+Opt+K (Mac) from keyboard. You need to first enable the developer menu to access web inspector on Safari. Choose Safari > Preferences, and click Advanced.
Capture node screenshot - Captures a screenshot of the inspected element in isolation. Capture screenshot - Captures a screenshot of the viewport only. Capture full size screenshot - Captures the entire page, even what is outside of the visible viewport.
I just made a script that take a screenshot every submit button in Google main page. Just take a look and take some inspiration from it.
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch({
headless:false,
defaultViewport:null,
devtools: true,
args: ['--window-size=1920,1170','--window-position=0,0']
})
const page = (await browser.pages())[0]
const open = await page.goto ( 'https://www.google.com' )
const submit = await page.$$('input[type="submit"]')
const length = submit.length
let num = 0
const shot = submit.forEach( async elemHandle => {
num++
await elemHandle.screenshot({
path : `${Date.now()}_${num}.png`
})
})
})()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With