watir--屏幕截图

现在实现的功能是ruby的截图模块。主要是通过win32screenshot gem来完成的。

首先是安装:win32screenshot

gem install win32screenshot

其次就可以来进行测试了。

require 'win32/screenshot'

FileUtils.makedirs(vpath) #截图存放目录
# Take a screenshot of the window with the specified title 用来获取特殊标题的窗口图片,比如说打开某个文件夹。
Win32::Screenshot::Take.of(:window, :title => "Windows Internet Explorer").write(vpath)

# Take a screenshot of the foreground 用来获取当前窗口的图片
Win32::Screenshot::Take.of(:foreground).write("image.png")

# Take a screenshot of the specified window's top-left corner's area 获取特定区域的图片
Win32::Screenshot::Take.of(:window, :title => /internet/i, :area => [10, 10, 20, 20]).write("image.jpg")

# Take a screenshot of the window with the specified handle 
Win32::Screenshot::Take.of(:window, :hwnd => 123456).write("image.gif")

# Take a screenshot of the child window with the specified internal class name 可以获取子对象的图片
Win32::Screenshot::Take.of(:rautomation, RAutomation::Window.new(:hwnd => 123456).
                          child(:class => "Internet Explorer_Server")).write("image.png")

# Use the bitmap blob for something else
image = Win32::Screenshot::Take.of(:window, :hwnd => 123456)
image.height # => height of the image
image.width  # => width of the image
image.bitmap # => bitmap blob

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值