javascript - 使用 IE 导航时处理网站弹出窗口

标签 javascript html excel vba web

我有一个 Excel VBA 宏

  1. 打开 IE,
  2. 导航至 Medicare 网站,
  3. 让我登录,
  4. 将网站上列出的声明与工作簿中已有的声明进行比较
  5. 提醒我任何差异

在登录步骤中我遇到了问题,因此我在下面复制了这部分代码。一旦执行 .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/

相关文章:

javascript - 向可观察的响应添加附加参数

html - Firefox CSS 空白 :nowrap not being honoured

html - 一个新闻标题应该用什么标签?

vba - 将变量范围附加到数组vba

javascript - 将 Chartist.JS 放入 Jade 中

javascript - 带有 UI Bootstrap 指令的 ng-bind-html

java - 使用 Apache POI 写入 excel。文件未找到异常 :(The requested operation cannot be performed on a file with a user-mapped section open)

excel - 删除出现在两个字符之间的文本 - 多个实例 - Excel

javascript - 另一个内部的 Ajax 请求

javascript - JSFiddle 提供的额外 CSS