VBscript Create an object from an IE element

MushroomKing

Registered User.
Local time
Today, 02:48
Joined
Jun 7, 2018
Messages
100
Hey guys!
I tried looking for an answer but to no avail. I hit a wall every time. Maybe someone can help?

I'm trying to "click" on an element with VBscript on a website.
This works. However, first i want to check if the element exists with a loop. This would work, if not for the "Invalid use of null" error i get with the code below.

Code:
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Navigate "url"
With IE.Document

Do
if not CreateObject(.getElementByID("formButton2343255")) is nothing then            
.getElementByID("formButton2343255").Click()
Exit Do
End if
WScript.Sleep 500 
Loop

SET objWshShell = Nothing
End With
End Function

Also, if i use

Code:
If Not .getElementByID("formButton2343255") Is Nothing Then

It tells me an "object is required!"

Could someone help me with this maybe?
 
Do you have to use CreateObject to use the .getElementByID method? Just curious...
 
Hi DBguy!

I wouldnt think so. But if i dont, i get object required.... :banghead:
 
Hi DBguy!

I wouldnt think so. But if i dont, i get object required.... :banghead:
Not sure how you tried it without but here's what I was thinking...
Code:
Set IE = WScript.CreateObject(...)
If IsNull(IE.Document.getElementByID("...") Then
    'nothing
Else
    'click it
End If
(untested)
 
theDBguy = theMASTERguy

Thanks man! That worked!
I was so caught up with vbs that i forgot regular simplicity.

Youre the best:):):):):):)
 
Hi. You're welcome. I forgot this is VBS. Not sure what is the equivalent of VBA.IsNull() in VBS.
 

Users who are viewing this thread

Back
Top Bottom