使用 IE 浏览时处理弹出窗口 [英] Handle Pop-Up While Navigating with IE
问题描述
我有一个 Excel VBA 宏
I have an Excel VBA macro that
- 打开 IE,
- 导航到 Medicare 网站,
- 让我登录,
- 将网站上列出的声明与工作簿中已有的声明进行比较
- 提醒我注意任何差异
我在登录步骤中遇到了问题,所以我复制了下面的那部分代码.一旦执行 .click
行,就会出现一个弹出窗口,要求用户单击 OK 按钮以继续.宏执行暂停,直到我手动单击弹出窗口中的 OK 按钮.
It is during the log-in step that I have a problem, so I've reproduced that portion of the code below. As soon as the .click
line is executed a pop-up window appears asking the user to click the OK button in order to proceed. Macro execution is suspended until I manually click the OK button on the pop-up.
http://www.mymedicare.gov 网页背后的源代码包含与弹出窗口,但我一直无法弄清楚如何使用它,以便我可以以编程方式单击弹出的 OK 按钮.
The source code behind the http://www.mymedicare.gov web page has information relative to the pop-up, but I haven't been able to figure out how to use it so that I can programmatically click the pop-up OK button.
在弄清楚如何以编程方式单击弹出窗口的 OK 按钮方面的任何帮助将不胜感激.
Any help in terms of figuring out how to programmatically click the pop-up's OK button would be much appreciated.
注意:对于此问题,可以使用任何用户 ID 和密码.如果您处理弹出窗口,您将进入一个页面,其中显示用户 ID/密码不正确.
note: For the purpose of this question, any user id and password can be used. If you handle the pop-up you'll be passed to a page that says something like incorrect user id / password.
这将表明您已成功处理弹出窗口.
That will indicate that you've been successful in handling the pop-up.
Sub Medicare_Claims()'
' Update the status bar
Application.StatusBar = "Running the Medicare Claims subroutine"
' Open the "MyMedicare web page
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "https://www.mymedicare.gov/"
End With
' Loop until the page is fully loaded
Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop
' Log-in
ie.Document.all.Item("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEUserName").Value = "abcde"
ie.Document.all.Item("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEPassword").Value = "12345"
ie.Document.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SignIn").Click
' Loop until the page is fully loaded
Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:15"))
' Navigate further to the Search Claims" web page
ie.Navigate "https://www.mymedicare.gov/searchclaims.aspx"
推荐答案
如果有人再次通过这种方式,这里是 Tim Williams 提供的解决方案:
In case anyone passes this way again, here is the solution provided by Tim Williams:
'Log-in
ie.Document.all.Item"ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEUserName").Value= "abcde"
ie.Document.all.Item("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEPassword").Value = "12345"
Dim f As String
f = "function(SignIn){document.getElementById'ctl00_ContentPlaceHolder1_ctl00_HomePage_Agree').value = 'True';}"
ie.Document.parentWindow.execScript "window.ConfirmationPopup = " & f, "jscript"
ie.Document.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SignIn").Click
这篇关于使用 IE 浏览时处理弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!