0
votes

Guys

I just wrote a vbs code snippet to automatically post in a forum. That's just for convenience. I encountered a wired problem: I have several accounts. When I login as some accounts and use the script to automatically post, everything is OK. However, when I login as the other accounts and run the script, I got the error:

Error : Object required "getElementById(...)"

Code : 800a01a8

Source : Microsoft VBScript runtime error

I'm sure the object exists because I get it in the source of the webpage. I feel the error occurred randomly and I cannot get the regularity. The script is ran in a Windows 8 OS and the browser is IE9. I'm a new learner of vbs and I don't know how to debug it. So I hope someone can help me. You can give me some clue.

Here is my code snippet:

Option Explicit
Dim IEApp
Dim iURL1
Dim iURL2
Dim iURL3
Dim iURL4
Dim iURL5

Set IEApp = CreateObject("InternetExplorer.Application")
iURL1="http://bbs.dealmoon.com/thread-299027-1-1.html"
iURL2="http://bbs.dealmoon.com/thread-299195-1-1.html"
iURL3="http://bbs.dealmoon.com/thread-299018-1-1.html"
iURL4="http://bbs.dealmoon.com/thread-299015-1-1.html"
iURL5="http://bbs.dealmoon.com/thread-299014-1-1.html"

Open iURL1
Open iURL2
Open iURL3
Open iURL4
Open iURL5

WScript.Echo("Done!")

Sub Wait(IE)
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
  Do
    WScript.Sleep 500
  Loop While IE.ReadyState < 4 And IE.Busy 
End Sub

Sub Post(IE)
Dim count
For count=0 To 9
  With IE.Document
    .getElementById("fastpostmessage").innerHTML = "good"
    .getElementById("fastpostsubmit").click
    Wait IE
    WScript.Sleep GetRandom(7,15)
  End With
Next
End Sub

Sub Open(PageURL)
  IEApp.Visible = False
  IEApp.Navigate PageURL
  Wait IEApp
  Post IEApp
End Sub

Function GetRandom(floor,ceil)

  Randomize
  GetRandom=Int((ceil - floor + 1) * Rnd + floor)*1000
  
End Function
2

2 Answers

0
votes

You should call your POST routine after all the HTML content is loaded, for example in DOMContentLoaded or window.onload (for IE<9).

-1
votes

You dimmed IEApp, created the object, but you are not using it when trying to get the element ID. Your With block should look like this:

With IEApp.Document
    .getElementById("fastpostmessage").innerHTML = "good"
    .getElementById("fastpostsubmit").click
    Wait IEApp
    WScript.Sleep GetRandom(7,15)
End With

There are a few other places you only have IE instead of IEApp. Clear those up and your code should run fine.