路漫漫其修远兮,吾将上下而求索
How do I deal with javascript popup’s?
上一篇 /
下一篇 2009-10-16 14:46:30
/ 个人分类:Ruby_Watir
A. Invoke the autoit function library with the .click_no_wait method…
You will need to install autoit. You can download it here, once installed you can call the function library using the win32OLE extension library.
Example html:
<html><head><scriptlanguage="javascript">function msgbox (textstring) {
alert (textstring) }</script></head><bodyid="test_00test_0107"onload=""><form><inputname="text1"type=text><inputname="submit"type=buttonvalue="show me"onclick="msgbox(form.text1.value)"></form></body></html>
Example watir:
require'watir'require'rubygems'require'win32ole'
autoit = WIN32OLE.new('AutoItX3.Control')@b.goto('http://justaddwatir.com/watir/test_html/tc_0101_0200/test_0107.html')@b.text_field(:name,"text1").set("Justaddwatir")@b.button(:name,"submit").click_no_waitautoit.WinWaitActive("[Class:#32770]")result =autoit.ControlClick("[Class:#32770]","","Button1")puts"successful click =1 unsuccessful =0, the result was "+result
In order for the autoit function to execute, you need to use the .click_no_wait method in watir before the autoit function. This is because once the pop up is presented, the focus comes off the IE window and the script. will pause. The .click_no_wait tells the script. to continue running regardless of what happens next.
You may use the autoit window identifier to get the properties of the pop up and the button attributes.
收藏
举报
TAG: