开发者

IE browser doesn't close and file download popup needs focus

I am trying to to click on a link after it is active which again produces a popup ( file download) after clicking. Here i have 2 problems

1) I start the code and leave it .what the code does is -after long process -it waits for the link to be active .Once the link is active it clicks on the link and开发者_Python百科 a download popups opens (if everything goes well) and then it hangs there ( showing yellow flashing in the task bar which mean i have to click on the explorer for it to process whatever is next ).every time i have to click on the IE whenever the download popup appears .Is there a way to handle this or am i doing some wrong ?

2) The next problem is even if i click on the IE .the IE doesn't get close even though i write ie.close . my code is below :

                       ## if the link is active
                    ie.link(:text,a).click_no_wait
                     prompt_message = "Do you want to open or save this file?"
                     window_title = "File Download"
                     save_dialog =WIN32OLE.new("AutoItX3.Control")
                       save_dialog.WinGetText(window_title)

                       save_dialog_obtained =save_dialog.WinWaitActive(window_title)
                        save_dialog.WinKill(window_title)
                      # end
                      #'
                       #some more code -normal puts statements
                      #

                    ie.close

ie is hanging up for some strange reason ..?


For #2. You would want to 'attach' your code to the parent window and then try to close it. Looks like when the download dialog opens, the parent window is losing focus. You could try -

ie = Watir::IE.attach(:url, ) (OR) ie = Watir::IE.attach(:title, )

and then try to close the browser.


I'm not sure of your popup issue, but I have code to deal with what I found to be a very frustrating popup problem of my own. So I include it for completeness. Here your ie browser object is equivalent to my @browser instance object

require 'watir\winClicker'
require 'watir\contrib\enabled_popup'

def popup_clicker(text)
    begin
      Timeout::timeout 2 , PopupTimeout do
        if @browser.enabled_popup
          hwnd = @browser.enabled_popup(5)
          w = WinClicker.new
          w.makeWindowActive(hwnd)
          w.clickWindowsButton_hwnd(hwnd,text)
        end
      end
    rescue PopupTimeout
        # Do this line if you can't find a popup
    end
    @browser.wait
  end

Then to click the OK button just run

popup_clicker('OK')

One thing you might notice is that you need to manually click the button that fires the popup with a hardware click. AutoIT might handle that, or I have a manual Watir element clicker if you want it. Try it without first. I also have code to check the popup contents if you want that (basically throw 'popup_text = w.getStaticText_hWnd(hwnd).to_s' into it).

As for 2) make sure the 'ie' object is still set to the browser. Try reattaching, as Namrantha noted. I've not known ie.close to fail. This should work, replacing @browser as you see fit, and XXX being the title of the window or a regex equivalent:

@browser = Watir::IE.attach(:title, XXXX)
@browser.close

Credit for the popup clicker original has to go to the furthest back in the chain I can find, a lovely user on the Watir-General google group called Wesley Chen:

http://groups.google.com/group/watir-general/browse_thread/thread/41c45aae9f87da9b

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜