IE 浏览器无法关闭并且文件下载弹出窗口需要焦点

发布于 2024-09-06 03:24:09 字数 1024 浏览 6 评论 0原文

我试图在链接激活后再次单击该链接 单击后会产生一个弹出窗口(文件下载)。 这里我有两个问题

1)我启动代码并保留它。代码的作用是 - 很久之后 process - 它等待链接处于活动状态。一旦链接处于活动状态 单击链接并打开下载弹出窗口(如果一切顺利) 好吧)然后它挂在那里(任务中显示黄色闪烁 栏,这意味着我必须单击资源管理器才能进行处理 无论接下来是什么)。每次我都必须点击 IE 出现下载弹出窗口。有没有办法处理这个问题或者我正在做什么 有些不对?

2)下一个问题是即使我点击IE,IE也不会 即使我写 ie.close 也关闭。 我的代码如下:

                       ## 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 由于某种奇怪的原因挂起..?

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 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 ..?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如果没有 2024-09-13 03:24:09

对于#2。您可能希望将代码“附加”到父窗口,然后尝试关闭它。看起来当下载对话框打开时,父窗口失去焦点。你可以尝试 -

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

然后尝试关闭浏览器。

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.

來不及說愛妳 2024-09-13 03:24:09

我不确定你的弹出问题,但我有代码来处理我自己发现的非常令人沮丧的弹出问题。因此,为了完整起见,我将其包括在内。这里您的 ie 浏览器对象相当于我的 @browser 实例对象

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

然后单击“确定”按钮只需运行

popup_clicker('OK')

您可能会注意到的一件事是您需要手动单击通过硬件单击触发弹出窗口的按钮。 AutoIT 可能会处理这个问题,或者如果您需要的话,我有一个手动 Watir 元素答题器。不先尝试一下。如果您需要的话,我还有代码来检查弹出内容(基本上将 'popup_text = w.getStaticText_hWnd(hwnd).to_s' 放入其中)。

至于2)确保“ie”对象仍然设置为浏览器。正如 Namrantha 所说,尝试重新连接。我不知道 ie.close 会失败。这应该可以工作,替换@browser,如你认为合适,XXX是窗口的标题或正则表达式等效项:

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

弹出点击器原始的信用必须转到我能找到的链中最远的后面,一个可爱的用户在Watir-General Google 群组 Wesley Chen:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文