11

Is there a way to do this using capybara+phantomjs.

Or perhaps something more complex like cropping a full page screenshot to the specific dom element?

NREZ
  • 942
  • 9
  • 13
user1898961
  • 115
  • 6
  • 2
    [Poltergeist](https://github.com/jonleighton/poltergeist) the Capybara driver for PhantomJS nearly has what you're asking but not quite. If you're willing to fill the gap yourself you can try and hack the [render binding](https://github.com/jonleighton/poltergeist/blob/98d4a4a8936e8d6b3417f2c057bafaba40874eee/lib/capybara/poltergeist/client/compiled/browser.js#L285) to pass the coordinates of the element you're interested in to the setClipRect() setter which dictates the area to be captured. – Arnaud Meuret Feb 13 '13 at 13:27
  • Using Poltergeist + some JS you could try the following. First using JS select the DOM element you desire and store it in a variable. You can then empty the body tag of the document using JS and then fill it with your DOM element. Then take a screenshot using the poltergeist driver. If you have CSS rules that have to stay you could first hide all other elements using JS and then take the screenshot. – Bert Goethals Apr 25 '13 at 18:01
  • A pull request has been submitted for this feature, and will be closed shortly. – James Lim Aug 15 '13 at 20:55

1 Answers1

1

A pull request has been submitted for this feature.

It will be closed shortly, and you will be able to use

driver.render selector: '#some_id`

in the next release.

James Lim
  • 12,915
  • 4
  • 40
  • 65