Screenshot of a particular element with Ruby and Puppeteer

Install Ruby Puppeteer Implementation

gem install puppeteer-ruby

Take a screenshot of the element and save to file

require 'puppeteer-ruby'

Puppeteer.launch(headless: false) do |browser|
  page = browser.new_page
  element = page.query_selector('.ssrcss-hmf8ql-BoldText')
  bounding_box = element.bounding_box
  page.screenshot(path: "element.png", clip: {x: bounding_box.x, y: bounding_box.y, width: bounding_box.width, height: bounding_box.height})

Find out how to take a full-page screenshot with Ruby and Puppeteer.

We created Urlbox to make converting HTML to images easy

Learn more about our website screenshot API.