在 watir-webdriver 中保存图像 [英] Save image in watir-webdriver

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

问题描述

我需要将图像从 recaptcha 保存到 localhost 磁盘,我正在使用 watir-webdriver 获取图像 dom 元素,但它不支持保存方法,就像 watir 一样.那么如何将图像保存到我的磁盘?html:

<div id="recaptcha_image" style="width: 300px; height: 57px;"><img style="display:block;"ALT = Проверкапослову验证码" HEIGHT = 57" 宽度= 300" SRC = https://www.google.com/recaptcha/api/image?c=03AHJ_VusSUxF0IYURRcVTVTjJJnUk92j-hXYsuwqvu0m5tvKFzAnwvrHlz-j_Gfqg-sUrHLj3D2DrUYNNg4uvr2BNgZqlK5vpJUJVYkkWo36I4RRmRGkYZru5kBYhzPCCn49KlH6wW_iLw6vIzv7vnhpu6ndqxb-9SkIRrVYyBwN39kg18Lov7Hc" >

和红宝石代码:

cap = @browsers[i].div(:id => 'recaptcha_image').image

如何将图像文件保存到磁盘?

解决方案

require 'watir-webdriver'需要'open-uri'image_src = @browsers[i].div(:id =>'recaptcha_image').image.srcFile.open("/path/", 'wb') do |f|f.write open(image_src).read结尾

I need to save image from recaptcha to localhost disk, i'm getting image dom element using watir-webdriver, but it doesn't support save method, as watir do. So how can i save image to my disk? Html:

<div id="recaptcha_image" style="width: 300px; height: 57px;">
  <img style="display:block;" alt="Проверка по слову reCAPTCHA" height="57" width="300" src="https://www.google.com/recaptcha/api/image?c=03AHJ_VusSUxF0IYURRcVTVTjJJnUk92j-hXYsuwqvu0m5tvKFzAnwvrHlz-j_Gfqg-sUrHLj3D2DrUYNNg4uvr2BNgZqlK5vpJUJVYkkWo36I4RRmRGkYZru5kBYhzPCCn49KlH6wW_iLw6vIzv7vnhpu6ndqxb-9SkIRrVYyBwN39kg18Lov7Hc">
</div>

and ruby-code:

cap = @browsers[i].div(:id => 'recaptcha_image').image

How to save image file to disk?

解决方案

require 'watir-webdriver'    
require 'open-uri'

image_src = @browsers[i].div(:id => 'recaptcha_image').image.src

File.open("/path/", 'wb') do |f|
  f.write open(image_src).read
end

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

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