Bret and all,

I was overjoyed to find the Watir::IE#attach_modal() method in the 
current development tree and quickly started experimenting in IRB to see 
how best to use it.  I quickly found that the last method call in 
attach_modal(), ModalDialog.new(), hasn't yet been implemented (at least 
in the tarball I got).  In addition, I saw that the only way to select a 
modal dialog was by :title.

I manually entered the Watir::IE#attach_modal() code into IRB and was 
able to get an htmldoc variable pointing to my modal dialog.  From that 
I could get the html using htmldoc.documentElement.outerHTML() 
(WHOOHOO!).  However, the modal dialog that I'm attaching to has a 
select_list and for our application (a scraper application, not a QA 
application) we need to be able to read the values from the 
select_list.  Now, of course I could just take the HTML I now have and 
use a regular expression to get the data we need, but it sure would be 
nicer to use the functions in Watir, wouldn't it?

OK, so I started to look at how to implement the WatirDialog class as 
called in the current Watir::IE#attach_modal method and I think I found 
out why this wasn't implemented yet.  Watir::IE#attach_modal is able to 
find a Document object, but I don't see any way to get an Internet 
Explorer Object to place into the @ie instance variable.  I also still 
have the problem that the current Watir::IE#attach_modal method only 
connects to the modal dialog by using the dialog's title.  This can give 
us problems if multiple dialogs have the same title, as could easily 
happen if you are running multiple concurrent IE instances (as we are).

I then though, since a given instance of IE can only have ONE modal 
dialog open, wouldn't it make more sense to find a modal dialog by using 
the current IE object?  I've been digging through the WET code for the 
past week, running many manual IRB sessions and learning FAR MORE about 
Microsoft IE and OLE than I ever cared to, but one thing WET showed was 
how to attach to a modal dialog using the parent IE window's window 
handle, which we have in Watir::IE#ie.  If we treat a modal dialog 
similar to a Watir::Frame container then perhaps we will get access to 
the modal dialog's Document elements in the same way.

By making liberal use of code from WET and Watir::IE#attach_modal I 
added a ModalDialog class near the end of Watir.rb, after Watir::Radio.  
My current version only allows connection to the modal dialog by using 
the parent Watir::IE's window handle, but it should be easy to modify it 
to also allow selection via the window title (or even other methods).

I'm now able to do the following in IRB (with my comments to the right):

irb(main):001:0> require 'watir'
=> true
irb(main):002:0> include Watir
=> Object

# attach to an IE window I've already navigated to
irb(main):003:0> my_ie = IE.attach(:title, /SAM/)
[...]

# site has frames inside of frames...
irb(main):004:0> frame = my_ie.frame('Main').frame('workarea')
[...]

# when clicked this button navigates to a new page, which brings up a
# modal dialog from onWindowLoad(). (ARGH!)
irb(main):005:0> button = frame.button(:id, 'btnCont')
[...]

# Here I click the button manually as the current click_no_wait() doesn't
# work from a frame (yet!).

[...]

# Now we see if we can get the modal dialog attached using my new code.
# (I won't show you my FIRST 10 tries which failed until I got the code
# working.)  :-)

# Note: While I've clicked a button deep into the frameset, I must
# attach the modal dialog using my Watir::IE object.  (This could be
# gotten around by writing some code to walk up the @container tree to
# get to the Watir::IE object in order to get it's HWND value.)
irb(main):006:0> dialog = my_ie.modal_dialog(:hwnd, 0)
[...]

# WHOOT!  I have a modal dialog object!  Can I now see elements inside
# the modal dialog?
irb(main):007:0> select = dialog.select_list(:name, 'cboDrop')
[...]

# YUP!  There's that nasty select I've been looking for.  I was even
# able to walk through the select_list values using
# select_list#getAllContents.

# Can I select one of those values?
irb(main):008:0> select.select(<value>)
[...]

# That select blocked after highlighting the field and selecting the
# proper value.  Perhaps there's a problem with flash in a modal
# dialog?  More work needs to be done, but now let's see if we can
# click a button.
irb(main):008:0> dialog.button(:id, 'btnOK').click
[...]

# At this point the dialog closed and I moved on to the following page!
# I'll have to figure out how to clean up the ModalDialog instance at
# this point, but I think we're on the right track!

This needs more work before it's ready to be released, but I think this 
shows that the concept is valid and may be a better model for linking to 
modal dialogs?

Bret and John, what are your thoughts?

David Schmidt
[EMAIL PROTECTED]

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to