VBscript Create an object from an IE element (1 Viewer)

MushroomKing

Registered User.
Local time
Yesterday, 16:33
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?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:33
Joined
Oct 29, 2018
Messages
21,454
Do you have to use CreateObject to use the .getElementByID method? Just curious...
 

MushroomKing

Registered User.
Local time
Yesterday, 16:33
Joined
Jun 7, 2018
Messages
100
Hi DBguy!

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

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:33
Joined
Oct 29, 2018
Messages
21,454
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)
 

MushroomKing

Registered User.
Local time
Yesterday, 16:33
Joined
Jun 7, 2018
Messages
100
theDBguy = theMASTERguy

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

Youre the best:):):):):):)
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 16:33
Joined
Oct 29, 2018
Messages
21,454
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

Top Bottom