popup when page loads

172 views
Skip to first unread message

Michael Badger

unread,
Mar 12, 2008, 11:31:22 AM3/12/08
to watir-...@googlegroups.com
Hello,

I need to click OK on a javascript warning message as soon as a web
page loads, but I'm having problems accessing the popup. Here's my
code:

$browser.goto(url)
# popup appears here. script hangs
hwnd = $browser.enabled_popup(30)
if (hwnd)
popup = WinClicker.new
popup.makeWindowActive(hwnd)
popup.clickWindowsButton("Windows Internet Explorer", "OK", 30)
end

When I manually step through my test in irb, the command prompt never
returns after I issue browser.goto. This leads me to believe I need to
start looking for the popup before $browser.goto(url), but I don't
know how. The same popup handling code works for me in other parts of
the application when I download a file or confirm a delete. In those
cases,however, I click a button with click_no_wait to trigger the
popup.

I appreciate any advice.

Mike

mxparker

unread,
Mar 13, 2008, 9:19:23 PM3/13/08
to Watir General
This seems to be a persistent problem. I've looked for the last couple
of days I haven't found the quick/easy answer. But, a lot of forum
discussions end up suggesting the use of the AutoItX COM component.

From AutoIt's Home Page (http://www.autoitscript.com/autoit3/) =>
"AutoIt v3 is a freeware BASIC-like scripting language designed for
automating the Windows GUI... It uses a combination of simulated
keystrokes, mouse movement and window/control manipulation in order to
automate tasks in a way not possible or reliable with other languages.
Also supplied is a combined COM and DLL version of AutoIt called
AutoItX that allows you to add the unique features of AutoIt to your
own favourite scripting or programming languages"

See below for a small example of accessing AutoIt's methods. You'll
need to install AutoIt and review the help files to determine which
methods you'll need to use to get to your dialog box and click the
close button.

If anybody knows the short answer, I'd love to hear it.

-- start --
require 'win32ole'
a=WIN32OLE.new("AutoItX3.Control")
a.mousemove 100,100
a.mousemove 300,300
a.mouseclick "right"
-- end --

(One thing to look out for - with File Save As dialogs or
Authentication Pop-ups - is situations where the page NEVER finishes
loading. In this case I've seen people run two scripts, or use a
timeout block. see below. Nothing too clean or easy.)

Using timeout block to get around File Save As...

=== Time Out Example ==

#Run Report
ie=IE.attach(:title,/Investment Detail/)
f1=ie.frame(:index,1)
f1.select_list(:name,/AccountNumber/).select(/19-8440/)
f1.select_list(:name,/ViewPage/).select(/Investment Detail/)
f1.button(:value,/GO/).click

begin
Timeout::timeout(30) do |timeout_length|
# do something that will take longer than timeout...

#Export Report
f2 = ie.frame(:index,2)
t=f2.table(:index,2)
t[2][2].link(:index,2).click

end

rescue Timeout::Error # go to here because the above timeed out

a = WIN32OLE.new("AutoItX3.Control")

# File Download
a.WinWaitActive("File Download", "Do you want to open or save", 20)
a.ControlClick("File Download", "Do you want to open or save",
"&Save")

a.Sleep(3000)

# #Save As Dialog
a.WinWaitActive("Save As")
a.ControlSetText("Save As","",1148,"#{file_path}")
a.Send("!s")

end # end rescue

=== End Time Out Example ==

On Mar 13, 5:53 pm, Oasis <oasissolutions....@gmail.com> wrote:

Michael Badger

unread,
Mar 13, 2008, 11:21:29 PM3/13/08
to watir-...@googlegroups.com
Thanks. It turns out that AutoIt is the answer in this case. The popup
section of the Watir FAQ has code that works. For the benefit of
others who come along, let me provide some of my own analysis to the
problem. The code I originally posted works fine when I click a
button/link with the click_no_wait method.

My problem is that when I load the page, the popup displays. The
script halts and waits for the popup to clear, which produces a "hung"
script. I needed the goto_no_wait method, but that's missing from the
current version of Watir - I think (attempt at humor, laugh). The
answer is to use AutoIt in a new thread to watch for popups. The code
is in the FAQ and works as-is. I just missed it the first dozen times.

Regards,
Mike

marekj

unread,
Mar 14, 2008, 12:52:10 AM3/14/08
to watir-...@googlegroups.com
Mike,
we are haviing some issues here on this popup front.

we resorted to Threads


    threads = []
    threads << Thread.new { $ie.radio(:name, 'myradio', 'myvalue').set}
    threads << Thread.new { system("rubyw c:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\watir-1.5.3\\watir\\clickJSDialog.rb OK 5") }
Reply all
Reply to author
Forward
0 new messages