VBA - Object required error after webpage sign in

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.


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
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi,
Were you able to solve the problem?
I run into the same problem. I notice that it happens only when I call getelementbyid after ApplicationWait. When I moved it before ApplicationWait, I don't get runtime error.


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.


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
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,694
Members
449,092
Latest member
snoom82

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