【问题标题】:Handle Website Pop-Up While Navigating with IE使用 IE 导航时处理网站弹出窗口
【发布时间】:2020-07-05 08:40:21
【问题描述】:

我有一个 Excel VBA 宏,

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

在登录步骤中我遇到了问题,所以我在下面复制了我的那部分代码。只要.click 行被执行,就会出现一个弹出窗口,要求用户单击OK 按钮以继续。宏执行被暂停,直到我手动单击弹出窗口上的 OK 按钮。

http://www.mymedicare.gov 网页背后的源代码有与弹窗相关的信息,但我一直无法弄清楚如何使用它,以便以编程方式单击弹窗 OK 按钮。

几年前,我发布了this question,蒂姆·威廉姆斯(Tim Williams)提供了一个出色的solution,基于与弹出窗口后面的javascript交互。此后,Medicare 更改了网页背后的代码,Tim 的解决方案不再处理弹出窗口。我在 Tim 的主题上尝试了很多变体,但没有找到解决方案。

任何有关如何以编程方式单击弹出窗口的 OK 按钮的帮助将不胜感激。

注意:对于这个问题,可以使用任何用户 id 和密码(我在下面的代码中去掉了 abcde 和 12345)。如果您处理弹出窗口,您将被传递到一个显示错误用户 ID/密码之类的页面。这将表明您已成功处理弹出窗口。

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" 

【问题讨论】:

    标签: javascript html excel vba web


    【解决方案1】:

    这对我有用

    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
    

    【讨论】:

      猜你喜欢
      • 2013-07-20
      • 2015-08-03
      • 2018-06-07
      • 2017-05-05
      • 1970-01-01
      • 2013-02-03
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多