Geoff Beals
New Member
- Joined
- Mar 22, 2015
- Messages
- 1
I am having problems with this code which extracts solar data from a public website that requires a registration and login. The situation is as follows:
1. The code navigates to the website successfully, enters the usercode and password, and logs in. Logging in results in a total change in the page content to a new data input page, but the URL remains unchanged.
2. The code then fails with Runtime error 424 “Object required” when it reaches the last line in the posted code below which is also the first data entry field on the new data input page.
3. I've considered the possibility that wait time is the cause, but extending this to 30 secs makes no difference
In debug mode, when I step through the code one line at a time, it works just fine and carries on to complete the data entry correctly which makes me wonder why it won’t work automatically. At the point of stoppage, and while in debug mode, I have tested the ObjIE.Document.URL which remains unchanged and correct, but the ObjIE.Document.Body.innertext returns the text from the sign in page rather than the new data requesting page which suggests to me that somehow the change to new page content is not being registered properly when I run the code automatically.
Please, can someone point out what I’m missing here and how I might fix this? I would greatly appreciate any help that might point me in the right direction.
I have also asked this question over at Stack Overflow
1. The code navigates to the website successfully, enters the usercode and password, and logs in. Logging in results in a total change in the page content to a new data input page, but the URL remains unchanged.
2. The code then fails with Runtime error 424 “Object required” when it reaches the last line in the posted code below which is also the first data entry field on the new data input page.
3. I've considered the possibility that wait time is the cause, but extending this to 30 secs makes no difference
In debug mode, when I step through the code one line at a time, it works just fine and carries on to complete the data entry correctly which makes me wonder why it won’t work automatically. At the point of stoppage, and while in debug mode, I have tested the ObjIE.Document.URL which remains unchanged and correct, but the ObjIE.Document.Body.innertext returns the text from the sign in page rather than the new data requesting page which suggests to me that somehow the change to new page content is not being registered properly when I run the code automatically.
Please, can someone point out what I’m missing here and how I might fix this? I would greatly appreciate any help that might point me in the right direction.
Code:
Sub Test()
Dim ObjIE As Object
Dim myUserName As String
Dim myPassword As String
Dim SiteAddress As Variant
Dim WaitTime As String
Dim PanelTilt As Single
Dim PanelBearing As Single
myUserName = "xxxxxxxx"
myPassword = "zzzzzzzz"
SiteAddress = “When I run this code SiteAddress is a real street address”
WaitTime = "00:00:05"
the_start:
'Navigate to the SignIn page
Set ObjIE = CreateObject("InternetExplorer.Application")
ObjIE.Top = 0
ObjIE.Visible = True
ObjIE.Navigate ("http://solarview.niwa.co.nz/")
'Wait until page loads, and restart if there is an error
Do
DoEvents
If Err.Number <> 0 Then
ObjIE.Quit
Set ObjIE = Nothing
GoTo the_start:
End If
Loop Until ObjIE.ReadyState = 4
ObjIE.Document.getElementsByName("username")(0).Value = myUserName
ObjIE.Document.getElementsByName("password")(0).Value = myPassword
ObjIE.Document.forms(0).submit
'Navigate to the Main Solarview page
Do
DoEvents
Loop Until ObjIE.ReadyState = 4
Application.Wait Now + TimeValue(WaitTime)
'Enter Site address and search for co-ordinates using:
' 1. User Address:
' <input id="addressID" size="60" class="text" type="text" name="address">
' 2. Submit Button:
' <input type="button" id="SubmitForm" value="Find address" class="form-button">
ObjIE.Document.getElementById("addressID").Value = SiteAddress
End Sub
I have also asked this question over at Stack Overflow