使用 watir-webdriver 保存图像 [英] Save image with watir-webdriver

查看:56
本文介绍了使用 watir-webdriver 保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何保存通过 watir-webdriver 加载的图像?所有手册和示例仅显示获取图像的 src,并使用 open-uri 保存它.但是我需要保存该图像,该图像是在我的页面加载时生成的.我怎样才能做到这一点?

How could i save image, which is loaded via watir-webdriver? All manuals and examples show only fetching src of image, and using open-uri saving it. But i need to save that image, which was generated when my page was loaded. How can i do this?

我可以同时使用 watir 和 watir-webdriver 吗?例如:

Could i use watir, and watir-webdriver at the same time? For example:

require 'watir-webdriver'
require 'watir'
@driver = Watir::Browser.new :firefox
@driver.goto (@base_url)
@img = @driver.image(id: 'CaptchaImage').save("2131.png")

我怎么能做这样的事情?或者如何从缓存中获取它?

How can i do something like this? Or else how to get it from cache?

有人可以帮我吗?

推荐答案

OpenURI 将帮助您..

OpenURI will help you ..

require "watir-webdriver"
require "open-uri"

b = Watir::Browser.new :chrome
b.goto "http://stackoverflow.com/"

File.open("target_file.jpg", 'wb') do |f|
 f.write open(b.img(:class, "sponsor-tag-img").src).read
end

希望你没有做坏事..:)

Hope you are not doing anything bad.. :)

如果有帮助,请告诉我.

Please let me know if it helped.

这篇关于使用 watir-webdriver 保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆