javascript - Handle Pop-Up While Navigating with IE - Stack Overflow

I have an Excel VBA macro thatopens IE,navigates to the Medicare website,logs me in,pares the claims

I have an Excel VBA macro that

  1. opens IE,
  2. navigates to the Medicare website,
  3. logs me in,
  4. pares the claims listed on the website with those already in the workbook
  5. alerts me to any differences

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.

The source code behind the 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.

Any help in terms of figuring out how to programmatically click the pop-up's OK button would be much appreciated.

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 "/" 
    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 ".aspx" 

I have an Excel VBA macro that

  1. opens IE,
  2. navigates to the Medicare website,
  3. logs me in,
  4. pares the claims listed on the website with those already in the workbook
  5. alerts me to any differences

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.

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.

Any help in terms of figuring out how to programmatically click the pop-up's OK button would be much appreciated.

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" 
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jul 21, 2013 at 14:45 ronron 1,3783 gold badges18 silver badges30 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 1

Try Application.SendKeys "{ENTER}", True after your login code.

Also, try adding Do: DoEvents: Loop Until Not objIE.Busy and Do While objIE.readyState <> 4: DoEvents: Loop any time you need a page to load. In my experience, coupling the two together works pretty well, whereas using just one or the other can sometimes produce errors and using Application.Wait can slow down your code unecessarily.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745483502a4629664.html

相关推荐

  • javascript - Handle Pop-Up While Navigating with IE - Stack Overflow

    I have an Excel VBA macro thatopens IE,navigates to the Medicare website,logs me in,pares the claims

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信