1.创建一个文件在D:\TestFile.xls
2.编写下面的代码
Dim xlApp 'Excel Application Automation Object Reference
Dim xlBook 'Reference to the workbook located in D:\
Dim xlSheet 'Reference to Sheet1
Dim iRow, sUserName, sPassword
Const iUserNameCol = 1
Const iPasswordCol = 2
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("D:\TestFile.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")
'SystemUtil.Run "iexplore.exe", "http://newtours.demoaut.com"
For iRow = 2 to xlSheet.UsedRange.Rows.Count
sUserName = xlSheet.Rows(iRow).Columns(iUserNameCol).Value
sPassword = xlSheet.Rows(iRow).Columns(iPasswordCol).Value
With Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours")
.WebEdit("name:=userName").Set sUserName
.WebEdit("name:=password").Set sPassword
.Image("name:=login").Click
End With
If Browser("title:=Find a Flight: Mercury Tours:").Exist(15) Then
Browser("title:=Find a Flight: Mercury Tours:").Link("text:=Home").Click
Reporter.ReportEvent micPass,"Iteration " &iRow-1,"UserName:"&sUserName& "is valid"
Else
Reporter.ReportEvent micFail,"Iteration " &iRow-1,"UserName:"&sUserName& "is invalid"
Browser("title:=Sign-on: Mercury Tours", "index:=0").Link("namet:=SIGN-ON").Click
End If
Next
xlBook.Close
xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing