UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Clicking A Button In Internet Explorer    
 
   
dflak
post Apr 11 2018, 11:58 AM
Post#1


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


Alas the site is proprietary. This code takes me to the login screen and fills in my credentials. It does not click the Login button. If I click it manually, it logs in. You can see by what is commented out other things that don't work.
CODE
Public Sub Login()
On Error GoTo MyExit
' Invoke Explorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate Range("DashboardURL")

' Wait for the sheet to come up
Do Until ie.readyState = 4: DoEvents: Loop

' create reference to document
Set doc = ie.document

' create references to the form, inputs and button
Set ieFrm = doc.forms("logonForm")
Set ieUser = doc.getElementById("NQUser")
Set iePwd = doc.getElementById("NQPassword")
Set ieButton = doc.getElementById("idlogon")

' Enter the login credentials
ieUser.Value = Range("MyLogin")
iePwd.Value = Range("MyPassword")

' Enter the login credentials
ieUser.Value = Range("MyLogin")
iePwd.Value = Range("MyPassword")

Do Until ie.readyState = 4: DoEvents: Loop
' Log in
'ieFrm.submit
'ieButton.submit
ieButton.Click
WaitForIEReady
MyExit:

End Sub


P.S. This is what I think the button ID is:
<input id="idlogon" type="submit" class="button" style="width: 110px; margin-left:90px;" onmouseover="NQWSetHasClassName(document.getElementById('idlogon'), 'buttonOver', true)" onmouseout="NQWSetHasClassName(document.getElementById('idlogon'), 'buttonOver')" value="Sign In">

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
GroverParkGeorge
post Apr 11 2018, 12:06 PM
Post#2


UA Admin
Posts: 33,502
Joined: 20-June 02
From: Newcastle, WA


I think Daniel has something on this on his website.

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 12:26 PM
Post#3


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


Also see Daniel's response in this thread

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Apr 11 2018, 12:33 PM
Post#4


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


George: I don't see anything in that link about IE. It's all about MS-Access.

I'll take a look at the other link. I will have to "translate" it from MS-Access to Excel.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
GroverParkGeorge
post Apr 11 2018, 12:35 PM
Post#5


UA Admin
Posts: 33,502
Joined: 20-June 02
From: Newcastle, WA


I see. I thought Daniel had put that sample code up somewhere on his own site as well.

--------------------
My Real Name Is George. Grover Park Consulting is where I do business.
How to Ask a Good Question
Beginning SQL Server
Visit My Blog on Facebook
Go to the top of the page
 
dflak
post Apr 11 2018, 01:03 PM
Post#6


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


Here is the latest wrinkle. In the code below, the execution stops with the browser being launched. The only message box that displays is "Launch the Browser" - "Waiting for browser" also showed until I commented it out. Apparently the browser "hijacks" the focus and I don't know what happens to the execution of the Excel code it apparently exits and is not applied to the browser. I lose control on these lines.

CODE
With ie
    Do While .Busy Or .readyState <> 4: DoEvents: Loop
End With


Here is the complete code:
CODE
Option Explicit

Dim ie As Object            ' Instance of IE
Dim doc As Object           ' Specific IE Document

Public Sub Login()
Dim ieFrm As Object         ' Form
Dim ieUser As Object        ' User name for login
Dim iePwd As Object         ' Password for login
Dim ieButton As Object      ' Button to click in form

MsgBox "Launch the browser"

On Error GoTo MyExit
' Invoke Explorer
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate Range("DashboardURL")

' Wait for the sheet to come up
'MsgBox "Waiting for browser"
With ie
    Do While .Busy Or .readyState <> 4: DoEvents: Loop
End With
MsgBox "Browser ready"

' create reference to document
Set doc = ie.document

MsgBox "Define Login pieces"
' create references to the form, inputs and button
'Set ieFrm = doc.forms("logonForm")
Set ieFrm = doc.getelementbyID("logonform")
Set ieUser = doc.getelementbyID("NQUser")
Set iePwd = doc.getelementbyID("NQPassword")
Set ieButton = doc.getelementbyID("idlogon")

MsgBox "Filling in credentials"
' Enter the login credentials
ieUser.Value = Range("MyLogin")
iePwd.Value = Range("MyPassword")

' Enter the login credentials
ieUser.Value = Range("MyLogin")
iePwd.Value = Range("MyPassword")

' Log in
If Not ieButton Is Nothing Then
    ieButton.Click
    MsgBox "The button has been clicked"
Else
    MsgBox "Can't find the button"
End If
WaitForIEReady
MyExit:

End Sub

Public Sub WaitForIEReady()
Do While doc.readyState <> "complete"
    DoEvents
Loop
End Sub

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
dflak
post Apr 11 2018, 01:23 PM
Post#7


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


I turned off the ON ERROR and get an error message

Method Busy of object 'IWebBrowser2' failed.

or

Automation error
Unspecified error

or

Automation error
The Interface is unknown

Take your pick. I've seen all three depending on when I run the code.

The error occurs on this line Do While .Busy Or .readyState <> 4

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 01:27 PM
Post#8


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


Try removing the .Busy Or

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Apr 11 2018, 01:44 PM
Post#9


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


Thanks for the suggestion. It did not work frown.gif.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
dflak
post Apr 11 2018, 01:48 PM
Post#10


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


I got one step closer

I changed
CODE
With ie
    Do While .readyState <> 4: DoEvents: Loop
End With

to
CODE
With ie
    Do While .readyState = 4: DoEvents: Loop
End With

and got as far as
CODE
Set doc = ie.document

and got the "Interface is unknown" error.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 01:54 PM
Post#11


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


Your WaitForIEReady() looks wrong

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Apr 11 2018, 02:08 PM
Post#12


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


That may very well be, but I am crashing before that. Commenting out the line that calls it doesn't fix the issue. I am going to try one more thing:

In the olden days I would de-install IE and re-install it. Today I think the best you can do is turn it off and turn it back on. So if you have a bad DLL, though luck.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 02:26 PM
Post#13


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


I changed the function to:
CODE
Public Sub WaitForIEReady()
Do While ie.readyState <> 4
    DoEvents
Loop
End Sub


I got it working with the UA login page.

Let me try and work up a debugging version of your code for you to try

--------------------


Regards,

David Marten
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 02:39 PM
Post#14


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


The MsgBox's kept getting hidden behind everything.

Try it with this:
CODE
Public Sub Login()
10    On Error GoTo Err_Login

        Dim ieFrm As Object         ' Form
        Dim ieUser As Object        ' User name for login
        Dim iePwd As Object         ' Password for login
        Dim ieButton As Object      ' Button to click in form


20      Debug.Print "Launching browser"

      ' Invoke Explorer
30      Set ie = CreateObject("InternetExplorer.Application")
40      ie.Visible = True
50      ie.Navigate Range("DashboardURL")

      ' Wait for the sheet to come up
60      WaitForIEReady
70      Debug.Print "Browser ready"

      ' create reference to document
80      Set doc = ie.document

90      Debug.Print "Define Login pieces"
      ' create references to the form, inputs and button
100     Set ieFrm = doc.forms("logonForm")
110     Debug.Print "logonForm " & IIf(ieFrm Is Nothing, "not ", vbNullString) & "set"
120     If ieFrm Is Nothing Then GoTo Exit_Login
        
130     Set ieUser = doc.getelementbyID("NQUser")
140     Debug.Print "NQUser " & IIf(ieUser Is Nothing, "not ", vbNullString) & "set"
150     If ieUser Is Nothing Then GoTo Exit_Login
        
160     Set iePwd = doc.getelementbyID("NQPassword")
170     Debug.Print "NQPassword " & IIf(iePwd Is Nothing, "not ", vbNullString) & "set"
180     If iePwd Is Nothing Then GoTo Exit_Login
        
190     Set ieButton = doc.getelementbyID("idlogon")
200     Debug.Print "idlogon " & IIf(ieButton Is Nothing, "not ", vbNullString) & "set"
210     If ieButton Is Nothing Then GoTo Exit_Login

220     Debug.Print "Filling in credentials"
      ' Enter the login credentials
230     ieUser.Value = Range("MyLogin")
240     iePwd.Value = Range("MyPassword")

      ' Log in
250     If Not ieButton Is Nothing Then
260         ieButton.Click
270         Debug.Print "The button has been clicked"
280     Else
290         Debug.Print "Can't find the button"
300     End If
310     WaitForIEReady

Exit_Login:
320     If Not doc Is Nothing Then Set doc = Nothing
330     If Not ie Is Nothing Then Set ie = Nothing
340     Exit Sub
        
Err_Login:
350     Select Case Err.Number
        Case Else
360       MsgBox "Error No.: " & Err.Number & vbNewLine & vbNewLine & _
                 "Description: " & Err.Description & vbNewLine & vbNewLine & _
                 "Sub: Login" & vbNewLine & _
                 IIf(Erl, "Line No: " & Erl & vbNewLine, "") & _
                 "Module: Sheet1", , "Error: " & Err.Number
370     End Select
380     Resume Exit_Login

End Sub

Public Sub WaitForIEReady()
  Do While ie.readyState <> 4
      DoEvents
  Loop
End Sub


hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 02:41 PM
Post#15


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


>> Today I think the best you can do is turn it off and turn it back on. <<

I know! It just took me ages to remember that I had turned it off when I first installed windows 10!!!

pullhair.gif

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Apr 11 2018, 02:49 PM
Post#16


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


Toggling IE didn't help, but I got a suggestion to try
Set ie = New InternetExplorerMedium
instead of
Set ie = CreateObject("InternetExplorer.Application")

and that works.

So far, I've not come across this incantation in the documentation and discussions I found on line.

Now onto my next quest. Clicking on a tab (no, not that kind of tab but a tab on the sheet that comes up when I log in) smile.gif.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 
cheekybuddha
post Apr 11 2018, 03:32 PM
Post#17


UtterAccess VIP
Posts: 10,343
Joined: 6-December 03
From: Telegraph Hill


Nice thumbup.gif

I saw the reference to New InternetExplorerMedium as well, but it negates late binding.

At least I can turn Internet Explorer off again now! woohoo.gif

d

--------------------


Regards,

David Marten
Go to the top of the page
 
dflak
post Apr 11 2018, 03:45 PM
Post#18


Utter Access VIP
Posts: 6,202
Joined: 22-June 04
From: North Carolina


Id rather not be using IE. Chrome is my browser of choice.

--------------------
Dan

One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.
Please zip and attach samples. It makes life easier for those who have to figure out what you are trying to do. Thanks
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    23rd September 2018 - 03:21 AM