Search code examples
jqueryrubycapybarapoltergeistwebpage-screenshot

Ruby cabypara, execute script to hide elements not working


So i am trying to take screenshots of web pages with cabypara/poltergeist, but there are certain elements that i want to hide, but executing the JQuery script to hide elements seems to be not working, i even tried hiding all elements and still the screenshot would show everything. Here's the code

Capybara.register_driver(:poltergeist) { |app| Capybara::Poltergeist::Driver.new(app, js_errors: false) }
Capybara.default_driver = :poltergeist
internet = Capybara.current_session
internet.visit 'https://www.google.com/'
internet.execute_script %Q{$("*").hide();}
internet.save_screenshot 'image.png'

What's the problem here ?


Solution

  • A quick guess would be that the google homepage doesn't load JQuery, so you can't use JQuery methods in your script. You will need to rely on the basic DOM methods.