使用 VBA 自动化关闭 JavaScript 警报 [英] Close JavaScript Alert Using VBA Automation

查看:23
本文介绍了使用 VBA 自动化关闭 JavaScript 警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来关闭在网页加载时加载的 Javascript 弹出窗口/消息框(即不是新的 IE 窗口,而是脚本化的 alert()).

I am searching for a way to close a Javascript pop-up/message box (i.e. not a NEW IE window, but a scripted alert()) that loads when a webpage is loaded.

我目前有将数据加载到搜索表单中、运行搜索、从结果中检索所需信息、退出搜索,然后继续处理列表中的下一项的代码.在某些情况下,搜索结果中缺少一条关键信息.发生这种情况时,页面上的 JavaScript 会在页面加载时弹出消息,让用户知道信息丢失.通过自动化,代码在继续之前暂停(等待)框被清除,并且用户必须在这发生之前点击确定按钮.

I currently have code that loads data into a search form, runs the search, retrieves the needed information from the results, exits the search, then continues with the next item in a list. In some cases, there is a piece of critical information missing from the search results. When this happens, the JavaScript on the page pops up the message when the page loads, letting the user know that info is missing. With the automation the code halts(waits) for the box to clear before continuing, and the user must click on the OK button before this will happen.

(我无法直接更改页面的源脚本,因为这超出了我在这里工作的职责范围.另外,保留此功能以供一般使用更为重要;它真的只会受益我正在创建的这个小用途函数.)

(I have no way to change the source script of the page directly, as that is outside of my scope of responsibility here at work. Plus, it is more important to retain this functionality for general use; it would really only benefit this small-usage function I'm creating.)

虽然我无法更改源脚本,但我找到了一个示例 如何通过更改加载的脚本来防止显示弹出窗口/警报.但是,它与一个已经加载的页面有关并且对我来说并不真正起作用(据我所知).

While I can't change the source script, I have found an example of how to prevent a pop-up/alert from displaying by changing the loaded script. However, it relates to an already-loaded page and doesn't really work for me (as far as I can tell).

IE.Document.getElementById("clearRelItems").removeAttribute "onClick"
IE.Document.getElementById("clearRelItems").setAttribute "onClick", "return true;"

是否可以在页面完全加载之前使用此方法进行更改?也就是说,这可以用来以某种方式绕过/规避页面加载时的函数调用吗?

Is it possible to use this method to make a change before the page has fully loaded? i.e. can this be used to somehow bypass/circumvent the function call at page load?

我知道 sendkeys,但如果可能的话,我宁愿避免使用此选项(如果不存在其他替代方法,我可能最终会使用此选项).此功能旨在由用户启动,然后在后台运行,因为它需要一些时间才能完成.

I know about sendkeys, but I would prefer to avoid this option if at all possible (I may end up using this option if no other alternative exists). This function is intended to be initiated by the user, then left running in the background as it will take some time to complete.

我已经按照@Kyle 的建议研究了获取 XML,但我认为我的能力不足以使这种方法起作用.

I have looked into grabbing the XML as suggested by @Kyle, but I don't believe I am proficient enough to make this method work.

我还能如何绕过警报?有没有办法实际激活警报上的确定按钮?可以通过其他方式绕过页面的警报/加载吗?

How else might I get around the alert? Is there a way to actually activate the OK button on the alert? Can the alert/loading of the page be bypassed any other way?

推荐答案

一种解决方法可能是识别您的脚本何时卡住,然后只需发送击键enter"即可关闭弹出窗口.

One work-around could be to recognize when your script is stuck and then just send the keystroke "enter" to close the pop-up.

这篇关于使用 VBA 自动化关闭 JavaScript 警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆