Internet Automation Popup Box (1 Viewer)

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
I'm automating a login page in IE. After I enter the user & pass and press enter a pop-up comes up. This is a disclaimer box where the user has to press 'ok' to make it go away.

Does anyone know how to get rid of the popup box? I tried using the sendkey without success. I don't think it's a good option anyway because I've read that it doesn't work in Vista.

Any ideas are welcome,

Joe
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
This is a disclaimer box where the user has to press 'ok' to make it go away.

Does anyone know how to get rid of the popup box?

I am not sure what you want.

Do you want to stop the pop-up totally from appearing OR is the pop-up essential to the login and you must enter OK.

edit: can you provide a URL or is this an intrAnet site.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Hi Darbid,

I could give you the url, but you would need a login & pass to see the popup.

Right after you enter the password a popup comes up saying that "this is for official government use, etc." then you have to press ok.

Also it will come up with an error pop-up box if it can't find a record. This happens every so often.

I don't think there is a way to disable them, since I think they are produced on the server side?

What I need is a way to tell if they come up in the first place and then a way to press "ok" for them. I'm also forced to use IE 6 and Office 2003. :mad:

vbaInet: I have previously looked at that thread, but it didn't have any info for my problem.

Thanks for the help,

Joe
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
Ok good. More questions.

Is this a dialog window or a new webpage popup?

Do you have to have this pop up and do you have to click the OK/Yes?

If we must have it then we need to work on this new window. If you do not need it then we will work on stoppping it from popping up.
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
by the way do you get the same pop up when the username and password are incorrect. Then I could test it.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Yes the same pop-up does come up. Ignore the message that says the government is comming to get you for entering a wrong password. They would only pay attention if you repeatedly entered wrong ones (like in an automated cracking program). This url is also publically available from a simple internet search.

Obviously I won't give you a username/password, but the box is the same type of one that I'm asking about.

https://hr.direct-access.us/servlets/iclientservlet/USCGP1HR/?cmd=login
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
Is the window you want to click YES in have a title of "Window Internet Explorer" and start with Unauthorized access bla bla bla
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
It is actually the same box that comes up. You would press OK to enter your username & password
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
Ok so the window I see is a dialog. I am going to guess that you must click OK (in other words we will not try and stop it; I am not sure if we can even). Further when it appears everything is frozen thus you are going to have to use a timer.

Put this code in a module.

I have tested this using a webbrowser control (ie IE on an access form.)

You have the problem that as soon as you click on "Sign in" the program is frozen thus I suggest you do it this way.

Call BeginTimer(500, Application.hWndAccessApp) 'this is milliseconds so you can make this longer if the site is slow.

then click on your signin button with your code.

The timer will then kick in, your form code will be frozen.

Then as soon as it clicks OK then your form code will continue.








Code:
Option Compare Database
Option Explicit
                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                              
Public AccHnd As Long
                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                              
'declares the imported API functions that are used in this example:
'http://en.wikipedia.org/wiki/API
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                              
'declares a constant that's used by PostMessage()... this specific message is
'ButtonMessage_CLICK (ie: message sent to click on the button)
Private Const BM_CLICK = &HF5
Private Const WM_SETTEXT = &HC
                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                              
Private Const MYTIMER_ID = 112
                                                                                                                                                                                                                                                              
Public Declare Function SetTimer Lib "user32" ( _
  ByVal hwnd As Long, _
  ByVal nIDEvent As Long, _
  ByVal uElapse As Long, _
  ByVal lpTimerFunc As Long) As Long
                                                                                                                                                                                                                                                              
Public Declare Function KillTimer Lib "user32" ( _
  ByVal hwnd As Long, _
  ByVal nIDEvent As Long) As Long
                                                                                                                                                                                                                                                              
Dim timerId As Long
                                                                                                                                                                                                                                                              
Public Sub BeginTimer(ByVal ms As Long, ByVal Access_Hnd As Long)
                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                              
    AccHnd = Access_Hnd
                                                                                                                                                                                                                                                              
  If timerId = 0 Then
    timerId = SetTimer(0, MYTIMER_ID, ms, AddressOf TimerProc)
  End If
End Sub
                                                                                                                                                                                                                                                              
Public Sub EndTimer()
  If KillTimer(0, timerId) <> 0 Then
    timerId = 0
  End If
End Sub
                                                                                                                                                                                                                                                              
Public Sub TimerProc( _
  ByVal hwnd As Long, _
  ByVal uMsg As Long, _
  ByVal idEvent As Long, _
  ByVal dwTime As Long)
                                                                                                                                                                                                                                                              
         Debug.Print "Timer"
                                                                                                                                                                                                                                                              
  
     Dim wnd1 As Long, wnd2 As Long, wnd3 As Long
    wnd1 = FindWindow("#32770", "Windows Internet Explorer")
                                                                                                                                                                                                                                                             
        Debug.Print "wnd1 " & wnd1
                                                                                                                                                                                                                                                             
    If (wnd1 <> 0) Then
        If (GetParent(wnd1) = AccHnd) Then
            wnd3 = FindWindowEx(wnd1, 0, "Button", "OK")
            Debug.Print "wnd3 " & wnd3
            
            If (wnd3 <> 0) Then
                Call PostMessage(wnd3, BM_CLICK, 0, 0)
            End If
        End If
    End If
                                                                                                                                                         
EndTimer
                                                                                                                                                                                                                                                           
End Sub
Some notes.

Code:
(GetParent(wnd1) = AccHnd)
This checks the parent window of your dialog. Currently I have given you code which uses the Application handle. If you are using IE alone then you will have to feed this code the IE handle. You will have this anyway.


Code:
wnd1 = FindWindow("#32770", "Windows Internet Explorer")
This finds your popup. If the title of the pop up changes then it will not find it. I see many languages there and the title might change if the computer language changes.

Code:
wnd3 = FindWindowEx(wnd1, 0, "Button", "OK")
Same as above. It is "OK" in english but might be something different in other languages.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Thanks darbid, I'm looking forward to trying it out.

Do you also know if there is a way to handle the popup errors that come up when it can't find a record. These need to be handled by my automation program so it doesn't freeze up.

thanks
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
Do you also know if there is a way to handle the popup errors that come up when it can't find a record. These need to be handled by my automation program so it doesn't freeze up.
thanks

Without actually looking at the website working - No idea.

Some suggestions.

1. Dont do a search that results in no records
2. does this "pop up" fire the Newwindow2 event of the webbrowser
3. Otherwise you are going to have to discover something that is unique when no records are found and check for this after a search. I suggest you look at the beforenavigate event and documentcomplete events and find something that happens there.
4. After a search is done just fire my code i gave you above. This code just stabs in the dark for a window and if it does not find it, it will not complain.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Hi Darbid,

I have tryed alot of variations on your program and what I'm finding is that when the IE popup box comes up VBA stops running along with the timer.

Once I click cancel or ok, I can see the timer start back up again.

Because of this it is not seeing the pop-up box because VBA is stopping just before it comes up.

Any other ideas?

Joe

Below is the yours and my program I have been monkeying with:

Code:
Option Compare Database
Option Explicit
 
Public AccHnd As Long
Public IEWindow As Long
 
'declares the imported API functions that are used in this example:
'http://en.wikipedia.org/wiki/API
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
 
'declares a constant that's used by PostMessage()... this specific message is
'ButtonMessage_CLICK (ie: message sent to click on the button)
Private Const BM_CLICK = &HF5
Private Const WM_SETTEXT = &HC
Private Const MYTIMER_ID = 112
 
Public Declare Function SetTimer Lib "user32" ( _
  ByVal hWnd As Long, _
  ByVal nIDEvent As Long, _
  ByVal uElapse As Long, _
  ByVal lpTimerFunc As Long) As Long
 
Public Declare Function KillTimer Lib "user32" ( _
  ByVal hWnd As Long, _
  ByVal nIDEvent As Long) As Long
 
  Dim timerId As Long
 
Public Sub BeginTimer(ByVal ms As Long, ByVal Access_Hnd As Long)
 
  AccHnd = Access_Hnd
 
  If timerId = 0 Then
    timerId = SetTimer(0, MYTIMER_ID, ms, AddressOf TimerProc)
  End If
 
End Sub
Public Sub EndTimer()
  If KillTimer(0, timerId) <> 0 Then
    timerId = 0
  End If
 
End Sub
Public Sub TimerProc( _
  ByVal hWnd As Long, _
  ByVal uMsg As Long, _
  ByVal idEvent As Long, _
  ByVal dwTime As Long)
 
    Debug.Print "Timer"
 
    Dim wnd1 As Long, wnd2 As Long, wnd3 As Long, wnd4 As Long, wnd5 As Long
    'wnd1 = FindWindow("#32770", "Windows Internet Explorer")
    wnd1 = IEWindow
 
    Dim windowTitle As String
    windowTitle = Space(100)
    Dim titleLength As Long
 
    titleLength = GetWindowText(wnd1, windowTitle, 100)
 
    Debug.Print "wnd1's address is " & wnd1 & ", and it's Title is = " & Left(windowTitle, titleLength)
 
    Dim counter As Integer
 
    If (wnd1 <> 0) Then
 
        Do
            counter = counter + 1
            wnd2 = FindWindowEx(wnd1, 0&, vbNullString, vbNullString)
            titleLength = GetWindowText(wnd2, windowTitle, 100)
            Debug.Print "child " & counter & " address = " & wnd2 & ", and it's Title is = " & Left(windowTitle, titleLength)
            wnd1 = wnd2
        Loop Until InStr(windowTitle, "microsoft internet explorer") <> 0 _
            Or counter > 50
 
    End If
 
 
'    If (wnd1 <> 0) Then
'        If (GetParent(wnd1) = AccHnd) Then
'            wnd3 = FindWindowEx(wnd1, 0, "Button", "OK")
'            Debug.Print "wnd3 " & wnd3
'
'            If (wnd3 <> 0) Then
'                Call PostMessage(wnd3, BM_CLICK, 0, 0)
'            End If
'        End If
'    End If
 
    EndTimer
 
End Sub
Public Sub DA_Login()
    Dim IE As InternetExplorer
    Set IE = CreateObject("InternetExplorer.Application")
 
    IE.Visible = True
    IE.Navigate "[URL]https://hr.direct-access.us/servlets/iclientservlet/USCGP1HR/?cmd=login[/URL]"
    'enter the user ID
    Do: Loop Until Not IE.Busy
    Do While InStr(IE.Document.documentElement.innerText, "User ID") = 0
    Loop
    IE.Document.all("userid").Value = 1234567    
    'enter the password
    Do: Loop Until Not IE.Busy
    Do While InStr(IE.Document.documentElement.innerText, "Password") = 0
    Loop
    IE.Document.all("pwd").Value = "mySecretPassword"
 
    IEWindow = IE.hWnd
    Call BeginTimer(1500, Application.hWndAccessApp)
    'press the submit button
    IE.Document.all("Submit").Click
 
Exit_DA_Login:
    Exit Sub
 
End Sub
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
you must put my code with timer in a module. The form code will be frozen as soon as it clicks on something that brings up the dialog window.
 
Last edited:

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
I'm not using a form. I'm just running it from the intermediate window.
I'll try putting the code in a different module though.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Ok. I tried launching it from a form and putting your timing routine in a separate module. I also tried running my routine from a standalong module with yours in a seperate module.

The same thing happens, no text prints in the immediate window until I press cancel or ok on the pop-up box from IE. It looks like the timing routine is freezing along with VBA.
 

darbid

Registered User.
Local time
Today, 14:29
Joined
Jun 26, 2008
Messages
1,428
ok here is what I tested

open the mdb.
open the form

enter fake info into the login
click on the botton on the right
within 2 seconds click on the login button on the site.



The dialog will pop up and my timer will cut in and click the ok.

Can you get that working?
 

Attachments

  • Copy of db4.mdb
    928 KB · Views: 141

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
I tried it like you said, but the confirmation box never goes away.

Your form brings up the url and I enter a fake username and then a password. I click on the "Command1" button and then click on "Sign In" on the actual page.

I tried several times with waiting different amounts of time from pressing "Command1" to pressing "sign in".

Is it working on your system? How many seconds does it take for the timer program to kick in?

thanks for your help,

Joe
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
I noticed that my confirmation box says "microsoft internet explorer"

After changing your code to

Code:
wnd1 = FindWindow("#32770", "Microsoft Internet Explorer")

from

Code:
wnd1 = FindWindow("#32770", "Windows Internet Explorer")

It works!

I'm going to see if I can get it to work now without having to press the "Command1" button.
 

gypsyjoe11

Registered User.
Local time
Today, 08:29
Joined
Feb 19, 2010
Messages
46
Darbid,

I modified your database and got it to enter the username and password, call the timer and then press submit when you click on the "Command1" button after the form loads.

I tried to avoid this by calling another routine in the form load event that then did the above stuff. In this case it loads the url, but then looks for the page elements before it is finished loading. I tried a wait loop, but it does the wait loop before calling the url navigate for some reason.

I also tried using the above with createobject, but the timer then doesn't work. (this is with IE outside of a form)

I was also wondering if the timer could be used to periodically check and see if an error msg box came up in the case where it can't find a record. This is different than the login screen.

At least it works inside a form after a button is pressed. That is a workable solution. I would like to either get it outside the form or so it does it automatically though.

Joe
 

Attachments

  • Internet Automation.mdb
    940 KB · Views: 157

Users who are viewing this thread

Top Bottom