我使用watir在RadRails IDE.After中测试,单击按钮删除出现窗口"Message from webpage“,确认我是否真的想删除记录。我怎样才能模拟点击OK?下面是我尝试过的方法: 1) ie=Watir::IE.new ie.execute_script("window.alert = function() {}") - have no effect
2) ie1.button(:name, "delete_action").click ie4.execute_script("window.confirm = function() {return true}")
获取错误- Task.rb:140:in '<main>: undefined local variable or method 'ie4' for main:Object (NameError)
3) ie1.button(:name, "delete_action").click ie1.execute_script("window.confirm = function() {return true}")
没有效果
4) ` `def按钮(startClicker,waitTime = 3)
w = WinClicker.new
longName = ie.dir.gsub("/" , "\\" )
shortName = w.getShortFileName(longName)
c = "start rubyw #{shortName }\\watir\\clickJSDialog.rb #{button }
#{ waitTime} "
puts "Starting #{c}"
w.winsystem(c)
w=nil
end`并放入
`ie1.button(:name, "delete_action").click
startClicker("OK" , 3)
ie.button("Submit").click`在来自网页的消息出现后。获取错误:
E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/modal_dialog.rb:3:in 'initialize': Watir no longer supports WinClicker. Please use click_no_wait and the javascript_dialog method. (NotImplementedError) from Task.rb:12:in 'new' from Task.rb:12:in 'startClicker' from Task.rb:162:in '<main>'
5)测试开始时的代码
` `def check_for_popups
autoit = WIN32OLE.new('AutoItX3.Control')
loop do
ret = autoit.WinWait('Message from webpage', '', 1)
if (ret==1) then autoit.Send('{enter}') end
sleep(3)
end end`
Code after message from webpage appears
`ie1.button(:name, "delete_action").click
$popup = Thread.new { check_for_popups }
at_exit { Thread.kill($popup) } `没有反应。
6) ` `require 'watir-classic\contrib\enabled_popup‘
定义按钮(startClicker,waitTime= 9,user_input=nil )
hwnd = $ie.enabled_popup(waitTime)
if (hwnd)
w = WinClicker.new
if ( user_input )
w.setTextValueForFileNameField( hwnd, "#{user_input}" )
end
sleep 3
w.clickWindowsButton_hwnd( hwnd, "#{button}" )
w=nil
end结束`
来自网页的消息出现后出现代码
`ie1.button(:.click_no_wait,“delete_action”)按钮
startClicker( "OK ",7)`
Get message - Task.rb:14:instartClicker':未定义的方法enabled_popup' for nil:NilClass (NoMethodError) from Task.rb:157:in'`
7)require 'watir/contrib/enabled_popup'
来自网页的消息出现后的代码-
` `hwnd = browser.enabled_popup(5)
if (hwnd)
popup = WinClicker.new
华为(popup.makeWindowActive)
Popup.clickWindowsButton(“来自网页的消息”,"OK","30")
结束`
获取错误- ':1.9的DL API中的E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/win32.rb:19:in块与1.8不兼容,请参阅来自E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contrib/enabled_popup.rb:11:in E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/wait.rb:18:in的enabled_popup‘from E:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/contrib/enabled_popup.rb:11:in enabled_popup enabled_popup’中的来自Task.rb:145:in <main>'的enabled_popup (NotImplementedError)
8)``require 'watir-classic\contrib\enabled_popup‘
def popupChecker(文本)
Timeout::timeout(2)do
begin
if $ie.enabled_popup
hwnd = ie.enabled_popup(5)
w = WinClicker.new
w.makeWindowActive(hwnd)
w.clickWindowsButton_hWnd(hwnd,text)
end
rescue Timeout::Error
puts 'No popup existed'
end
end结束`
来自网页的消息出现后的代码-
`ie1.button(:.click_no_wait,“delete_action”)按钮
popupChecker('OK')
ie1.wait`
Get message:Task.rb:13:inblock in popupChecker':undefined method enabled_popup' for nil:NilClass (NoMethodError) from E:/Ruby193/lib/ruby/1.9.1/timeout.rb:68:intimeout‘from Task.rb:11:in popupChecker' from Task.rb:158:in'`
9)``def check_for_popups(title=“来自网页的消息”,button="OK")
popup=Thread.new {
autoit=WIN32OLE.new('AutoItX3.Control')
ret=autoit.WinWait(title,"",60)
if (ret==1)
puts "There is popup."
autoit.WinActivate(title)
button.downcase!
if button.eql?("ok") || button.eql?("yes") || button.eql?("continue")
autoit.Send("{Enter}")
else
autoit.Send("{tab}")
autoit.Send("{Enter}")
end
elsif (ret==0)
puts "No popup, please check your code."
end
}
at_exit { Thread.kill(popup) }结束`
来自网页的消息出现后的代码-
check_for_popups("Message from webpage", "OK")
无反应
发布于 2012-07-05 17:18:19
试试这个:
browser.alert.ok更多信息:http://watir.github.io/docs/javascript-dialogs/
https://stackoverflow.com/questions/11340910
复制相似问题