Glad to help. Sun wrote: > Problem resolved. > First -- I don't actually know if this is, or is not, a modal dialog, since > the: > "if (modal = ie.modal_dialog(:hwnd, hwnd))" > statement cannot be parsed (because apparently, even in the 1081 code branch > the :hwnd parameter is not recognized for this method call.) > Since there can only be one modal dialog "in control" at any one time, you don't need *any* parameters to connect to a modal_dialog as long as there is only one IE with a modal dialog open at any time. However, because you *can* have two IE processes running at once I had coded in the ability to connect directly to the proper modal dialog window that YOUR IE process opened. However, that code was removed and I cannot replace it.
However, this window that you're seeing is NOT a modal dialog. IE has a number of different kinds of popup windows. One is the modal dialog which loads a normal HTML file and can even take inputs which are passed back to the calling window. Once you attach to a modal dialog you can treat them like any other IE window and perform normal Watir commands to read the HTML and/or fill any forms and click the dialog's buttons. The other type of popup is a "Javascript", or "Security" popup. They do not contain HTML and they cannot be manipulated with normal Watir commands. The WinClicker class in winclicker.rb has methods which allow you to perform some operations on a Javascript popup including reading static text and clicking on buttons by button label. Since *those* are the methods that worked for you below I know that your window was a Javascript and not a modal dialog. Both types of popup window will block if you use "click" on the button that creates them. This means that Watir's click() method will never return until the popup is closed. This is why you need to use the click_no_wait() method to click the button that opens the popup. Click_no_wait starts up another Watir process which clicks the button (and blocks). This leaves your main Watir task running so that it can attach or handle the popup. > However, I resolved the problem by brute force (non elegantly.) This is how I > did it. > While some might consider it "brute force" or "non-elegant", it is the method we must use to handle these popups. This is because the click that creates the popup will block, and because IE doesn't give Watir a way of easily controlling these popups. > === > require 'watir' > require 'test/unit' > class TC_article_example < Test::Unit::TestCase > def test_search > # open the IE browser > ie = Watir::IE.new > # steer to google > ie.goto('http://www.google.com/') > # load the search field > ie.text_field(:name, "q").set("pickaxe") > #Ensure popup won't block Watir > ie.button(:name, "btnG").click_no_wait > #Handle the popup > hwnd = ie.enabled_popup(5) > if (hwnd) #yes there is a popup > p hwnd > w = WinClicker.new > w.makeWindowActive(hwnd) > w.clickWindowsButton_hwnd(hwnd, "Yes") > end > # insert pause or it doesn't work... > sleep 3 > # Validate response > assert(ie.pageContainsText("Programming Ruby")) > end > end > === > The key things. > 1st, I used the click no wait feature: ie.button(:name, "btnG").click_no_wait > Required to be able to continue to execute commands in your original Watir script. > 2nd, I made use of the new "enabled_popup" functionality to get hwnd. > The enabled_popup() method uses the GW_ENABLED_POPUP option of the GetWindow() call in Windows USER32.DLL to locate any popup window associated with the current window. Watir can then use that window handle (HWND) to manipulate the popup. > 3rd, I used WinClicker to access and kill the security popup > Correct. Since it wasn't a modal_dialog this is the best way to clear the popup. There are even calls in WinClicker which will retrieve any static text displayed in the popup window before you click the OK button to clear it. I've used this to retrieve error messages being displayed. > 4th and finally, I had to insert that sleep statement or...it would fail with > this error on the assert call: "<nil> is not true." Why this should occur I > don't know and I find troubling...perhaps someone can explain why this works. > When the popup window is closed then control is returned to the original IE window. Since a popup window may be opened by a window you are *leaving* your assert started looking for the text before the page containing that text had finished (or perhaps even *started*) loading. Because of that you may not have even had a valid page when you performed the assert. Try putting in an @ie.wait after clicking the button and before the assert and see if that helps. David Schmidt _______________________________________________ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general