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

标签 javascript excel automation alert vba

我有一个 Excel VBA 宏

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

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

http://www.mymedicare.gov背后的源代码网页包含与弹出窗口相关的信息,但我无法弄清楚如何使用它,以便我可以通过编程方式单击弹出窗口 确定 按钮。

如果您能提供有关如何以编程方式单击弹出窗口的确定按钮的任何帮助,我们将不胜感激。

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" 

最佳答案

尝试Application.SendKeys "{ENTER}", True在您的登录代码之后。

另外,尝试添加 Do: DoEvents: Loop Until Not objIE.BusyDo While objIE.readyState <> 4: DoEvents: Loop任何时候您需要加载页面。根据我的经验,将两者结合在一起效果很好,而仅使用其中之一有时会产生错误,而使用 Application.Wait会不必要地减慢您的代码速度。

关于javascript - 使用 IE 导航时处理弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17773523/

相关文章:

javascript jquery IE 中的每个问题

Excel VBA 宏 : User Defined Type Not Defined

vba - 用vba清理excel表

automation - 是否可以使用 MyBatis Generator 一次为所有表生成工件?

selenium - 如何在selenium-ide中自动点击iframe?

javascript - 如何在 Node JS 中使用 Express 读取带句点的参数?

javascript - 如何通过YouTube API获取 "Top tracks for (artist)"URL?

java - 如何通过控制层次结构(来自 C#)自动操作 Java GUI 程序?

javascript - 超链接到 GitHub 项目 HTML 作为带有参数的预览

c# - 在 C# 中轻松读取 Excel?