【问题标题】:Watir - Error when I try to take screenshot of divWatir - 当我尝试截取 div 时出错
【发布时间】:2018-01-14 11:12:47
【问题描述】:

我使用 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>'

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

【问题讨论】:

  • 截图正常,但是我在你的代码中发现一个问题是指定的页面中不存在给定的id resultStats,我使用了这个id sb_ifc0 这是一个id一个部门的

标签: ruby watir


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2013-11-13
    • 2017-11-04
    • 2011-04-25
    • 2020-07-31
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    相关资源
    最近更新 更多