watir自动化捕获上传图片元素:

require 'watir'
include Watir
require 'test/unit'
class TC_recorded < Test::Unit::TestCase
def test_recorded
puts "First Line"
ie=Watir::IE.new
puts "Open IE"
ie.goto("http://localshot:8082")
ie.file_field(:name,'file').set("C:\\wy.jpg")

执行脚本,报错!原因是什么呢?

看这面这段代码:input_elements.rb

class FileField < InputElement
#:stopdoc:
INPUT_TYPES = ["file"]
POPUP_TITLES = ['Choose file', 'Choose File to Upload']
#:startdoc: # set the file location in the Choose file dialog in a new process
# will raise a WatirException if AutoIt is not correctly installed
def set(path_to_file)
assert_exists
require 'watir/windowhelper'
WindowHelper.check_autoit_installed
begin
Thread.new do
sleep 1 # it takes some time for popup to appear system %{ruby -e '
require "win32ole" @autoit = WIN32OLE.new("AutoItX3.Control")
time = Time.now while (Time.now - time) < 15 # the loop will wait up to 15 seconds for popup to appear
#{POPUP_TITLES.inspect}.each do |popup_title|
next unless @autoit.WinWait(popup_title, "", 1) == 1 @autoit.ControlSetText(popup_title, "", "Edit1", #{path_to_file.inspect})
@autoit.ControlSend(popup_title, "", "Button2", "{ENTER}")
exit
end # each
end # while
'}
end.join(1)
rescue
raise Watir::Exception::WatirException, "Problem accessing Choose file dialog"
end
click
end
end
  POPUP_TITLES = ['Choose file', 'Choose File to Upload'] 
  Choose file ! 本地化的问题.

  怎么修改呢?

  POPUP_TITLES = ['选择要加载的文件', 'Choose File to Upload']

这个titles的数组第一个元素是根据操作系统及浏览器的文件上传弹窗而修改的

ruby + watir 自动化上传图片文件解决方案的更多相关文章

  1. ueditor1.3.6jsp版在struts2应用中上传图片报"未找到上传文件"解决方案

    摘要: ueditor1.3.6jsp版在struts2应用中上传图片报"未找到上传文件"解决方案 在struts2应用中使用ueditor富文本编辑器上传图片或者附件时,即使配置 ...

  2. ruby+watir安装指南

    安装ruby+watir一共需要下面几个步骤 1. 安装ruby: 2. 升级Rubygems:Rubygems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统. 它提供一个 ...

  3. ajax上传图片文件

    这里用的是一个隐藏的iframe,这样可以让form表单提交到这个iframe里面,用户就看不到页面的刷新了 前段时间在解决ajax上传文件时折腾了好一阵.直接用$.post上传文本信息肯定是没有问题 ...

  4. Atitit.android播放smb 网络邻居视频文件解决方案

    Atitit.android播放smb 网络邻居视频文件解决方案 Android4.4 1.1. Android4视频播放器不能直接地支持smb协议..子好先转换成个http流 1.2. ES文件浏览 ...

  5. php上传图片文件常用的几个方法

    1. 前台 <form class="add-form" method="post" action="/person/save" en ...

  6. 3 分钟轻松搭建 Ruby 项目自动化持续集成

    任何事情超过 90 秒就应该自动化,这是程序员的终极打开方式.Automating shapes smarter future. 这是一篇关于 Ruby 项目持续集成的快速指导教程,教大家如何使用 f ...

  7. [Ajax] 使用Ajax异步上传图片文件(非Form表单提交)

    通过表单Form提交来上传文件的方式这里就不说了: 下面介绍,通过js中使用ajax异步上传图片文件: 新建一个html页面和一个一般处理程序即可: 涉及思路: //发送2次Ajax请求完成js异步上 ...

  8. Ubuntu文件写入内容时出现错误 E121:无法打开并写入文件解决方案

    在安装某些软件过程中会让你新建个txt或者在输入vim /etc/profile命令时,输入完毕后保存文件时就会报错 E121:无法打开并写入文件解决方案,一般的解决状况就是输入如下命令: :w !s ...

  9. 利用Spring MVC 上传图片文件

    本文转自:http://amcucn.iteye.com/blog/264457.感谢作者 近日在工作当中,需要用到上传图片的功能,然而自己平时学习的时候只会使用struts的上传功能,但因为项目并没 ...

随机推荐

  1. [Asp.net 5] DependencyInjection项目代码分析4-微软的实现(2)

    在 DependencyInjection项目代码分析4-微软的实现(1)中介绍了“ServiceTable”.“ServiceEntry”.“IGenericService”.“IService”. ...

  2. 为IEnumerable扩展一个ForEach方法

    IEnumerable没有一个ForEach方法,我们可以使用C#写一个扩展方法: Source Code: using System; using System.Collections.Generi ...

  3. 提高生产性工具(五) - 数据的过滤器和图形化(适用于 MVC5 + MongoDB)

    在下面流水账似的文章之前,先将一些感悟说一下. 1.如果一个系统对于某个功能在至少三个地方使用的话,必须将其抽象提炼出来,而且时间点最好是大规模测试之前. 2.提炼出来的功能,如果品质做得好,整个系统 ...

  4. 【Java每日一题】20161013

    package Oct2016; public class Ques1013{ public static void main(String[] args){ new Obj(); } } class ...

  5. windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境

    windows下用eclipse+goclipse插件+gdb搭建go语言开发调试环境   http://rongmayisheng.com/post/windows%E4%B8%8B%E7%94%A ...

  6. 袋鼠过河---DP

    题目:一只袋鼠要从河这边跳到河对岸,河很宽,但是河中间打了很多桩子,每隔一米就有一个,每个桩子上都有一个弹簧,袋鼠跳到弹簧上就可以跳的更远,每个弹簧力量不同,用一个数字代表它的力量,如果弹簧力量为5, ...

  7. Scalaz(4)- typeclass:标准类型-Equal,Order,Show,Enum

    Scalaz是由一堆的typeclass组成.每一个typeclass具备自己特殊的功能.用户可以通过随意多态(ad-hoc polymorphism)把这些功能施用在自己定义的类型上.scala这个 ...

  8. Java_Class 16方格拼图游戏

    public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Game ...

  9. java 小程序-- 汉诺塔

    1.code public static void main(String[] args) { ; moveDish(, 'A', 'B', 'C'); } public static void mo ...

  10. Java--Semaphore控制并发线程数量

    package com; import java.util.concurrent.Semaphore; /** * Created by yangyu on 16/11/28. */ /** * Se ...