Input text in Internet Explorer (Username/password)

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
Hi,

This was working on another website, but I can't get it to work now. Trying to input username/password on this site and click submit.

<code>

Sub PLineBot()
Dim IE As Object
Dim url As String


Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
url = "https://propertyline.ca/"
IE.navigate url

'wait for page to load
Do
DoEvents
Loop Until IE.readyState = 4


IE.document.getElementById("account").Value = "username"
IE.document.getElementById("password").Value = "password"

IE.document.forms(0).submit.Click

End Sub

</code>

Any ideas?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I found this code on mrexcel , which works on the website listed, but won't work on the propertyline.ca website?

<code>

Sub GoToWebSiteAndPlayAroundNew()
Dim appIE As Object ' InternetExplorer
Dim doc As Object 'HTMLDocument
Dim URL As String
Dim objIMG As Object ' HTMLImg
Dim objAnchor As Object ' HTMLAnchorElement

Set appIE = CreateObject("InternetExplorer.Application")

URL = "https://efolio.morgankeegan.com/escripts/defaultLogon.asp?errCode=2"

With appIE
.navigate URL
.Visible = True

Do While .Busy: DoEvents: Loop
Do While .readyState <> 4: DoEvents: Loop

Set doc = .document

doc.getElementById("fUserName").Value = "UserName"

doc.getElementById("fPassword").Value = "Password"

Set objIMG = doc.images("SubmitRus")

Set objAnchor = objIMG.parentElement

objAnchor.Click

Do While .Busy: DoEvents: Loop
Do While .readyState <> 4: DoEvents: Loop

End With

Set appIE = Nothing

End Sub

</code>
 
Upvote 0
I have tried this same code on 3 different webpages and it works every time. I am not sure what is special about propertyline.ca? I have tried all of the getelement protocols and it won't input a username or even recognize the field? Any input would be awesome, thanks.
 
Upvote 0
Upvote 0
Thank you for the reply. The code gets stuck on "Set HTMLdoc = frame.document"? Not sure what this is doing. It gives me "Access is Denied" error. Any ideas?
 
Upvote 0
The "Access is denied" error is due to the login frame being hosted on a different domain to the main page, and browsers prevent scripts from accessing cross-frame documents - see https://msdn.microsoft.com/en-us/library/ms533028(v=vs.85).aspx for more info.

To access the username and password input boxes on this site therefore requires a separate IE.navigate to the src attribute of the login frame's document, as done by the following code.

This code uses early binding of IE and HTMLDocument objects and therefore you need to set (in Tools -> References in the VBA editor) references to Microsoft Internet Controls and Microsoft HTML Object Library.
Code:
Public Sub IE_Login()

    'References required:
    'Microsoft Internet Controls
    'Microsoft HTML Object Library

    Dim IE As InternetExplorer
    Dim URL As String
    Dim HTMLdoc As HTMLDocument, iframe As HTMLIFrame
    
    URL = "https://propertyline.ca/"
    
    Set IE = New InternetExplorer
    With IE
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
        
        'Navigate to src attribute of login iframe
        'Needed because login iframe document is hosted by a different domain to the main URL and browsers prevent cross-frame scripting
        'when content documents are from different domains - see https://msdn.microsoft.com/en-us/library/ms533028%28v=vs.85%29.aspx
        
        Set iframe = HTMLdoc.getElementById("login-frame")
        .Visible = True    'could hide IE login window
        .navigate iframe.src
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
    
    'Populate login fields and click Submit button
    
    HTMLdoc.getElementById("account").Value = "username"
    HTMLdoc.getElementById("password").Value = "password"
    HTMLdoc.getElementById("submit").Click
    
    With IE
        'Wait for login
        
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        
        'Navigate again to original URL - should be logged in now, assuming correct username and password supplied above
        
        .Visible = True
        .navigate URL
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        Set HTMLdoc = .document
    End With
    
    'Verify correct logged in webpage by displaying its text
    
    MsgBox HTMLdoc.body.innerText
    
End Sub
I don't have an account on the site, so I'm unable to fully test this code.
 
Upvote 0
Thank you again for responding, I really appreciate it. I had tried this before and it gets to the source page: https://www.reports.propertyline.ca/Login. Once the login is attempted IE gives an error: object doesn't support this property or method. If I browse to that page in Chrome it works no problem. Any idea why it wouldn't work in IE?

You can test this error just by going to the website and hitting submit with no username or password, it produces the same error.
 
Last edited:
Upvote 0
Update: I upgraded to IE 10 because IE 8 was the issue. It gives me an error on this: Set HTMLdoc = .document

Object Library feature not supported.

I have the two references that are required, not sure why this would cause an error?
 
Upvote 0
Ok, I have it working to a point. Now internal to the system I am trying to 'click' a new button which html looks like:

<code>

a href="#" class="btn btn-xs-md btn-1-blue" data-bind="click: arnSearch">Search

</code>

How do you 'click' that?
 
Last edited:
Upvote 0
Yes, the site can't be automated with IE8.

Can you post your complete code and I will have a look.
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top