Micro Focus QTP (UFT) Forums
Read from excel. - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Read from excel. (/Thread-Read-from-excel)



Read from excel. - hpham - 06-25-2008

Hi everybody,
I want to automate function login, with two field username and password. If I use datatable, the script is successful. Then I want to read username and password from an excel file, then in the first loop, QTP recognizes these two fields, but in second loop, it doesn't recognize. I know why, cause the page is now not the login page, but I don't know how to correct it, pls help me. Here is my script:

Code:
Option Explicit
Dim filepath, sheet,rownum, row,columnnum, column,username, password, ExcelObj
filepath= "C:\test.xls"

Set ExcelObj = CreateObject("Excel.Application")
ExcelObj.DisplayAlerts = 0
ExcelObj.Workbooks.Open filePath, false, true '//opens the excel from desired path

Set sheet = ExcelObj.ActiveWorkbook.Worksheets(1)
rownum = sheet.UsedRange.Rows.count
columnnum = sheet.UsedRange.Columns.count

For row = 2  to rownum
    username = sheet.Cells(row,1)
    password = sheet.Cells(row, 2)
    Browser("STT Info -tiedotepalvelu").Page("STT Info -tiedotepalvelu").WebEdit("username").Set username
    Browser("STT Info -tiedotepalvelu").Page("Internal Site :: Press").WebEdit("password").SetSecure password
    Browser("STT Info -tiedotepalvelu").Page("STT Info -tiedotepalvelu").WebButton("Kirjaudu").Click

    Browser("STT Info -tiedotepalvelu").Page("Internal Site :: Press_2").Check CheckPoint(username)
    Browser("STT Info -tiedotepalvelu").Page("Internal Site :: Press_2").Sync

Next
Set sheet = Nothing
ExcelObj.Workbooks(1).Close
ExcelObj.Quit
Set ExcelObj = Nothing



RE: Read from excel. - Ankur - 06-26-2008

You have your answer in the question itself "cause the page is now not the login page" . While iterating always make sure that start and end conditions( in this case login page) are same.

Before Next add the line of code which takes you to your application.


RE: Read from excel. - hpham - 06-26-2008

Thanks a lot, Ankur.