我是VBScript的新手,并试图衡量我创建的网站的性能。在我的网站中,当点击一个按钮时,该项目将被添加到购物车中。购物车中有6件商品。如果我的脚本单击要添加到购物车的第一个项目,我希望它等到继续下一个指令(不添加随机睡眠编号)。在我的程序中,它只将第1个和最后一个项目添加到我的购物车中:
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
答案 0 :(得分:1)
您可以这样做:
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