' 启动IE浏览器
SystemUtil.Run "iexplore.exe"
' save the Report Filter mode
OldFilter = Reporter.Filter
Reporter.Filter = 2 ' Enables Errors Only
' 链接描述
Set Desc = Description.Create()
Desc("html tag").Value = "A"
Desc("href").Value = "http://blog.csdn.net/Testing_is_believing/category/.*"
Set BrowserObj = Browser("creationtime:=0")
' 导航到指定页面
BrowserObj.Navigate "http://blog.csdn.net/Testing_is_believing/category/357781.aspx"
Set PageObj = BrowserObj.Page("index:=0")
msgbox "开始"
call EnumerateApp(PageObj, Desc, "Click", "ReportPage", "BrowserBack")
Reporter.Filter = OldFilter ' returns the original filter
' 遍历整个程序,执行指定的操作,例如点击每个链接
Function EnumerateApp(ParentObj, Desc, OperationMethod, PostOperationMethod, RestoreMethod)
dim ObjCol, CurrentObj, idx
idx = 0
' retrieve a collection of all the objects of the given descrition 按指定的描述取得所有子对象
Set bjCol = ParentObj.ChildObjects(Desc)
Do While (idx < ObjCol.Count)
' get the current object
set CurrentObj = ObjCol.item(idx)
' perform. the desired operation on the object 执行指定的操作,例如Click
eval("CurrentObj." & OperationMethod)
' perform. the post operations (after the object operation) 执行完指定的操作后需要做的动作,例如写入测试
日志 eval(PostOperationMethod & "(ParentObj, CurrentObj)")
' Return the application to the original state 让程序回到初始状态,例如让浏览器导航回退到主页面
eval(RestoreMethod & "(ParentObj, CurrentObj)")
idx = idx + 1
' reretrieve the collection of objects
' (as the application might have changed)
Set bjCol = ParentObj.ChildObjects(Desc)
Loop
End Function
' 写测试日志
Function ReportPage(ParentObj, CurrentObj)
dim FuncFilter, PageTitle
PageTitle = ParentObj.GetROProperty("title")
FuncFilter = Reporter.Filter
Reporter.Filter = 0
Reporter.ReportEvent 0, "Page Information", "page title " & PageTitle
Reporter.Filter = FuncFilter
End Function
' 让浏览器按回退键
Function BrowserBack(ParentObj, CurrentObj)
On Error Resume Next
BrowserObj.Back
End Function