Watir Popup 采用新线程进行处理
require 'watir'
require 'win32ole'
def check_for_popups(title="Microsoft Internet Explorer", 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!
ifbutton.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) }
end
$ie.link(:text,//).click_no_wait
check_for_popups("MicrosoftInternet Explorer","OK")
这个方法针对 Popup是 OK/cancel之类的弹出框比较有效。
点亮测试人生!QQ:408129370
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号:
百度阅读电子书地址:http://yuedu.baidu.com/ebook/f6dbb2a2f01dc281e53af0f3
讨论QQ群:536192476
个人公众号: