watir-extensions-element-screenshot
watir-extensions-element-screenshot copied to clipboard
Capturing screenshot of element inside an iFrame
When capturing a screenshot of an element inside an iFrame, wd.location returns x and y locations relative to the iFrame. These iFrame locations should be used in the crop! function (in addition to the element locations).
Here's an IRB snippet, b is a Watir::Browser object (for Firefox) When I add the iFrame locations to the div element's locations, the image is correctly cropped.
irb(main):012:0> file = b.screenshot.save('page.png') irb(main):013:0> image = ChunkyPNG::Image.from_file('page.png') irb(main):014:0> b.iframe(:id => 'livebox_frame').div(:id => 'nested_div').wd.size => #<struct Selenium::WebDriver::Dimension width=165, height=35> irb(main):015:0> b.iframe(:id => 'livebox_frame').div(:id => 'nested_div').wd.location => #<struct Selenium::WebDriver::Point x=352, y=485> irb(main):016:0> b.iframe(:id => 'livebox_frame').wd.location => #<struct Selenium::WebDriver::Point x=391, y=106> irb(main):017:0> image.crop!(352+391, 485+106, 165, 35) irb(main):018:0> image.save('page_new.png')
Thus to fix this, we would somehow need to check if the element resides in an iFrame.
What happens if you pen the iframe URL and then try to screenshot the element?