thomasjaeger
asked on
Using VB to fill in and submit an HTML form
I am trying to create a login page for Hotmail but am getting "Run-time error 438 Object doesn't support this property or method". On the "IE.document.All.Item("XXX ").Value" line's.
I have included Microsoft Internet Controls" in the References(also tried in components). And have tried with and without the HTML object Library.
When I look at MSDN http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/InternetExplorer.asp
It says it is read only??? Yet I have found several mentions to doing it this way on this and other sites????
This should be an easy question for someone but I am sure lost.
What am I missing? Thanks
Tom Jaeger
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----
Option Explicit
Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument
Private Sub Form_Load()
Set IE = CreateObject("InternetExpl orer.Appli cation")
IE.Navigate "www.hotmail.com"
IE.Visible = True
End Sub
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
'Url could change so take care of it ;)
If InStr(1, URL, "login.passport.net/uilogi n.srf?id=2 ", vbTextCompare) Then
IE.document.All.Item("logi n").Value = "email" 'replace with your id
IE.document.All.Item("pass wd").Value = "pass" 'replace with your password
IE.document.All.Item("subm it1").Clic k
End If
End If
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
I have included Microsoft Internet Controls" in the References(also tried in components). And have tried with and without the HTML object Library.
When I look at MSDN http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reference/objects/InternetExplorer.asp
It says it is read only??? Yet I have found several mentions to doing it this way on this and other sites????
This should be an easy question for someone but I am sure lost.
What am I missing? Thanks
Tom Jaeger
--------------------------
Option Explicit
Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument
Private Sub Form_Load()
Set IE = CreateObject("InternetExpl
IE.Navigate "www.hotmail.com"
IE.Visible = True
End Sub
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
'Url could change so take care of it ;)
If InStr(1, URL, "login.passport.net/uilogi
IE.document.All.Item("logi
IE.document.All.Item("pass
IE.document.All.Item("subm
End If
End If
End Sub
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Instead of IE.document.All.Item("logi n").Value
you use IE.document.Form1.login.va lue
This applies to other objects to..
you use IE.document.Form1.login.va
This applies to other objects to..
ASKER
Thanks Aelatik,
I am going to accept your answer... but I am stumped as to why there were refrences to the
IE.document.All.Item("logi n").Value = "email"
all over the net when the correct way is
IE.document.Form1.login.Va lue = "email"
any thoughts? Normally I wouldn't care but I am learning so I like to know what I did wrong and why.
Thanks
Tom J
I am going to accept your answer... but I am stumped as to why there were refrences to the
IE.document.All.Item("logi
all over the net when the correct way is
IE.document.Form1.login.Va
any thoughts? Normally I wouldn't care but I am learning so I like to know what I did wrong and why.
Thanks
Tom J
I really can't explain it. Sometimes it does work with IE.document.All.Item("logi n").Value = "email"
It depends on the website i guess. Try it on Google for example. Your method should work fine there...
Option Explicit
Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument
Private Sub Form_Load()
Set IE = CreateObject("InternetExpl orer.Appli cation")
IE.navigate "www.google.com"
IE.Visible = True
End Sub
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
IE.document.All.Item("q"). Value = "searchtext"
End If
End Sub
It depends on the website i guess. Try it on Google for example. Your method should work fine there...
Option Explicit
Public WithEvents IE As InternetExplorer
Public WithEvents doc As HTMLDocument
Private Sub Form_Load()
Set IE = CreateObject("InternetExpl
IE.navigate "www.google.com"
IE.Visible = True
End Sub
Private Sub IE_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is IE) Then
IE.document.All.Item("q").
End If
End Sub
looking for same
>> but I am stumped as to why there were refrences to the (etc etc)
There are multiple input-elements on the hotmail sign-in page with the names of "login" and "passwd" so you can't get one of the objects without specifying the form. You could have used to Forms collection within the document-element and then accessed the input-elements from that. The other method just accesses the elements directly.
Btw, my first comment showed the correct method to use. aelatik just double-posted it using your own example.
There are multiple input-elements on the hotmail sign-in page with the names of "login" and "passwd" so you can't get one of the objects without specifying the form. You could have used to Forms collection within the document-element and then accessed the input-elements from that. The other method just accesses the elements directly.
Btw, my first comment showed the correct method to use. aelatik just double-posted it using your own example.
thomasjaeger,
The All array encompasses every element that has an id attribute, while the forms array is for 'in form' tags only, so if your form tag, such as <input type=...>, has an id then you can retrieve a reference to it via the all array.
The All array encompasses every element that has an id attribute, while the forms array is for 'in form' tags only, so if your form tag, such as <input type=...>, has an id then you can retrieve a reference to it via the all array.
Private Sub Form_Load()
Dim oIE As Object, sURL As String
sURL = "http://login.passport.net/uilogin.srf?id=2"
Set oIE = CreateObject("InternetExpl
oIE.Visible = True
Call oIE.Navigate("www.hotmail.com")
Do Until oIE.LocationURL = sURL And oIE.readystate = 4
DoEvents
Loop
oIE.document.Form1.login.V
oIE.document.Form1.passwd.
oIE.document.Form1.submit1
End Sub