繁体   English   中英

Watir-当我尝试拍摄div的屏幕截图时出错

[英]Watir - Error when I try to take screenshot of div

我使用Watir和Watir-element-screenshot获取元素的屏幕截图。 浏览器:Chrome和Firefox(最新版本)我的代码:

require 'watir'
require 'watir/extensions/element/screenshot'
browser = Watir::Browser.new :firefox
browser.goto 'google.com.ua'    
browser.text_field(id: "lst-ib").set "ruby\n"    
browser.window.maximize
browser.element(id: "resultStats").screenshot("2.png")   
browser.close

并采取以下错误:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/color.rb:968:in `scanline_bytesize': undefined method `>>' for 2439.0:Float (NoMethodError)
Did you mean?  >
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:207:in `encode_png_image_pass_to_stream'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:174:in `encode_png_image_without_interlacing'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:161:in `encode_png_pixelstream'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:85:in `to_datastream'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/image.rb:62:in `to_datastream'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:35:in `write'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `block in save'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `open'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/chunky_png-1.3.8/lib/chunky_png/canvas/png_encoding.rb:43:in `save'
    from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-extensions-element-screenshot-0.0.3/lib/watir/extensions/element/screenshot.rb:12:in `screenshot'
    from 2.rb:11:in `<main>'

此消息的原因是什么,我该如何修复?

您可以使用此代码进行屏幕截图并保存在特定位置。

 browser.screenshot.save("path to save image/2.png") 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM