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
 

sunny65

New Member
Joined
Jul 6, 2016
Messages
1
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
 

Forum statistics

Threads
1,082,333
Messages
5,364,675
Members
400,810
Latest member
elbashka

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top