我有一个 Excel VBA 宏
- 打开 IE,
- 导航至 Medicare 网站,
- 让我登录,
- 将网站上列出的声明与工作簿中已有的声明进行比较
- 提醒我任何差异
在登录步骤中我遇到了问题,因此我在下面复制了这部分代码。一旦执行 .click
行,就会出现一个弹出窗口,要求用户单击 OK 按钮才能继续。宏执行会暂停,直到我手动单击弹出窗口中的确定按钮。
http://www.mymedicare.gov背后的源代码网页包含与弹出窗口相关的信息,但我无法弄清楚如何使用它,以便我可以通过编程方式单击弹出窗口 确定 按钮。
几年前,我发布了this question蒂姆·威廉姆斯提供了出色的solution基于与弹出窗口后面的 javascript 交互。此后,Medicare 更改了网页背后的代码,蒂姆的解决方案不再处理弹出窗口。我已经尝试了 Tim 主题的很多变体,但还没有找到解决方案。
如果您能提供有关如何以编程方式单击弹出窗口的确定按钮的任何帮助,我们将不胜感激。
note: For the purpose of this question, any user id and password can be used (I've out abcde and 12345 in the code below). 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"
最佳答案
这对我有用
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
Dim doc As Object
Set doc = ie.Document
doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEUserName").Value = "abcde"
doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEPassword").Value = "12345"
doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_Agree").Value = "True"
doc.parentWindow.execScript "window.ConfirmationPopup = function(){null;}", "jscript"
doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SignIn").Click
End Sub
关于javascript - 使用 IE 导航时处理网站弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38002871/