Watir 新版中,应用RAutomation库,对弹出框进行处理,如果操作系统是英文版系统,这会很方便,但是如果是中文系统,会遇到很多意想不到的问题,即使你去修改库Watir-classic的基本类,还是有一些情况无法处理。所有的Windows弹出窗口的问题,都可以应用AutoIt轻松解决。
Windows中常见的弹出框分为几类:
1. Alert
2. Confirm
3. Prompt
4. File select
下面的方法,解决了所有的这些常见问题:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 |
#encoding:utf-8 require ‘watir-classic‘ class PopupWindow def
initialize( ) @autoit
= WIN32OLE . new ( ‘AutoItX3.Control‘ ) end #popup_title: 弹出窗口的标题 def
push_alert_button(popup_title) @autoit .WinWaitActive(popup_title, "" ) @autoit .ControlClick(popup_title, "" , "Button1" ) @autoit .WinWaitClose(popup_title) end #popup_title: 弹出窗口的标题 #button_name: 弹出窗口上要点击的按钮名称 def
push_confirm_button(popup_title, button_name) @autoit .WinWaitActive(popup_title, "" ) @autoit .ControlClick(popup_title, "" , "[text:#{button_name}]" ) @autoit .WinWaitClose(popup_title) end #popup_title: 弹出窗口的标题 #input: 在弹出窗口的输入口中要输入的值 #button_name: 弹出窗口上要点击的按钮名称 def
push_prompt_button(popup_title, input, button_name) @autoit .WinWaitActive(popup_title, "" ) @autoit .ControlSetText(popup_title, "" , "Edit1" , input) @autoit .ControlClick(popup_title, "" , "[text:#{button_name}]" ) @autoit .WinWaitClose(popup_title) end #popup_title: 弹出窗口的标题 #file_path: 在弹出窗口的输入口中要输入的文件路径 #button_name: 弹出窗口上要点击的按钮名称 def
select_file(popup_title, file_path, button_name= "打开(&O)" ) @autoit .WinWaitActive(popup_title, "" ) @autoit .ControlSetText(popup_title, "" , "Edit1" , file_path) @autoit .ControlClick(popup_title, "" , "[text:#{button_name}]" ) @autoit .WinWaitClose(popup_title) end end |
Watir 中关于IE 弹出框的处理,布布扣,bubuko.com
原文:http://www.cnblogs.com/autotest/p/3671140.html