D P.
D P.

Reputation: 1079

VBScript waiting till button is clicked

I am new to VBScript and trying to measure the performance of a website I have created. In my website, when a button is clicked, that item will be added to a shopping cart. There are 6 items to be added to the cart. If my script click the first item to be added to the cart, I want it to wait till proceeding to the next instruction (without putting a random sleep number). In my program, it only adds the 1st and the last item to my cart:

set webbrowser = createobject("internetexplorer.application")
webbrowser.visible = true

webbrowser.navigate("https://www.mywebsite") 
Do While webbrowser.busy 'waiting till the webpage is loaded
   wscript.sleep(1)
Loop 

buttonID = "item1"  
Demo(buttonID)'Program should wait till the first button is clicked before going to the statement below'
buttonID = "item2"  
Demo(buttonID)
buttonID = "item3"  
Demo(buttonID)
buttonID = "item4"  
Demo(buttonID)
buttonID = "item5"  
Demo(buttonID)
buttonID = "item6"  
Demo(buttonID)

Sub Demo(buttonID)    
    Do  
        set x = webbrowser.Document.getElementById(buttonID)
        If x is nothing then
           wscript.sleep 1
        else    
            webbrowser.Document.getElementById(buttonID).click
            Exit Do
        end if 
    Loop
End Sub

Upvotes: 3

Views: 402

Answers (1)

Gurmanjot Singh
Gurmanjot Singh

Reputation: 10360

You can do something like this:

set objie = createobject("internetexplorer.application")
objie.visible=true
objie.Navigate "https://www.swrm2017.org/TimeMeasurementOnlineShoppingSystem/BrowseCatalog/Catalog.php"
swait()

for i = 1 to 6
    id = "item"&i
    set button = objie.document.getElementById(id)
    button.click
    swait()
    set button = nothing
next
set ie = nothing

sub swait()
    while(objie.readystate<>4)
        wscript.sleep 10
    wend
    while objie.document.readystate<>"complete"
        wscript.sleep 10
    wend
end sub

Upvotes: 1

Related Questions