Bret Pettichord wrote:
> On 5/11/06, *David Schmidt* <[EMAIL PROTECTED] 
> <mailto:[EMAIL PROTECTED]>> wrote:
>
>     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).  
>
>
> Please look again. Here is the code in watir.rb. I'm not sure where 
> you got that tarball. CVS? Rubyforge? You need to find our current 
> code. Dev builds and source on OpenQA.org.
>
Well, I can't even *find* where I got it now even though I got it 
Tuesday, but it was Revision 1.282, version 1.4.  I just grabbed the 
1.5.0.980 gem but would still like a repository URL if there's a public 
one.  Do you have a CVS (or better yet, Subersion) URL that I can get 
the latest version from?  Then I can generate a patch against that (or 
possibly get commit rights) and have you check it out.  I think I have 
all the pieces and we just need to integrate them and flesh them out 
with all the how/what options.
>   class ModalPage < IE
>     def initialize(document, parent)
>       @ie = parent.ie <http://parent.ie>
>       # Bug should be transferred from parent
>       @document = document
>       set_fast_speed
>       @url_list = []
>       @error_checkers = []
>     end 
>     def document
>       return @document
>     end
>     def wait
>     end
>   end
>
> (If you look closely, you'll see my subtle implementation of 
> ModalPage#wait.)
>
Your masterful implementation of ModalPage#wait was exactly what was 
called for.  Select now works fine and doesn't block.
>
>     In addition, I saw that the only way to select a
>     modal dialog was by :title. 
>
>
> True
>
>     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).
>
>
> See how we did this above.
I added my implementation into the latest gem I found (1.5.0.980 from 
http://wiki.openqa.org/display/WTR/Development+Builds) and it's working 
for both :hwnd and :title:

irb(main):001:0> require 'watir'
=> false
irb(main):002:0> include Watir
=> Object
irb(main):003:0> ie = IE.attach(:title, /SAM/)
=> #<Watir::IE:0x2f9aa50 [...]>
irb(main):004:0> dialog = ie.modal_dialog
=> #<Watir::ModalDialog:0x2f95c08 [...]>
irb(main):005:0> dialog = ie.modal_dialog(:hwnd)
=> #<Watir::ModalDialog:0x2f924b8 [...]>
irb(main):006:0> dialog = ie.modal_dialog(:title, 'Determinant Select')
=> #<Watir::ModalDialog:0x2f8ddd8 [...]>
irb(main):007:0> dialog.button(:id, 'btnCancel').click
=> nil
irb(main):009:0> Watir::IE::VERSION
=> "1.5.0.980"
>  
>
>     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?  
>
>
> Yes, if you can do it. Frankly, i don't know how.
I found the methodology in WET.
>
> Also you can have more than one modal, namely a modal can itself 
> launch another modal. I know it sounds sick, but the app i'm testing 
> actually does this.
ACK!  I just confirmed this by taking my dialog object above and doing: 
dialog.document.parentWindow.showModalDialog('<URL>') and it brought up 
a child modal which blocks the first one.  That truly *is* sick.  We can 
get to it by title, but to get to it by "inheritance" I'll have to save 
the hwnd_modal value of our first modal dialog into the container so 
it's available to the following modal_dialog() call.  I've never found a 
way to get the HWND from an IE Document or Window object.  It can be 
done though and would look like this:

second_dialog = IE.attach(xxx, xxx).modal_dialog.modal_dialog

How does that look to you?
>  
>
>     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).
>
>
> Cool. This sounds better than what we have right now.
I think I like it better than having an attach_modal() method since it 
works just like the Frame or other container objects.  In case you 
didn't notice I didn't use one of the default factory methods so I was 
able to have model_dialog default to using the :hwnd how, but the user 
can still specify the :hwnd or :title/'<title>'.
>  
>
>     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!). 
>
>
> OK. I need to put this on my short list of things to fix!
>  
I posted a method to generate the model invocation string in 
http://www.mail-archive.com/wtr-general%40rubyforge.org/msg03627.html

Use that and make sure that click_no_wait using that string is available 
to all the applicable elements.  It handles frames fine.
>
>     [...]
>
>     # 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) 
>
>
> Awesome. Please donate your code for this.
I'll generate a diff from 1.5.0.980, will that work?
>  
>
>     [...]
>
>     # 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.
>
>
> The problem is (right or wrong) select calls wait. And your wait is 
> broken. (See mine)
Fixed and works great now.
>
>     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?
>
>
> 1. Figure out why you couldn't see my ModalPage class.
Old tarball.  Got it now, and I even left it in because I called mine 
ModalDialog.
> 2. Donate your code that finds a modal using the spawning window's HWND.
I'll gen the patch and e-mail it to you.  You can see it done in WET's 
WinUtil.rb file, or in my Watir::IE#ModalDialog in the patch I send you.
> 3. Who's John?
I meant Paul.  Brain stack overflow.
>
> Bret
David Schmidt
[EMAIL PROTECTED]

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

Reply via email to