Micro Focus QTP (UFT) Forums
Get values from dropdown the. Save it to 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: Get values from dropdown the. Save it to excel (/Thread-Get-values-from-dropdown-the-Save-it-to-excel)



Get values from dropdown the. Save it to excel - Sm8422 - 06-11-2012

My webpage has couples of dropdown. I want to get all the values from each dropdown and save them to excel with QTP. Is it possible?


RE: Get values from dropdown the. Save it to excel - ravi.gajul - 06-11-2012

Hi,
Yes it is possible.Sample code is shown below.The below code will add all the items in "departing from" list to the excel sheet "List.xls"
Code:
list=Browser("Browser").Page("Find a Flight: Mercury").WebList("fromPort").GetROProperty("all items")
arrItems=split(list,";")
Set oExcelApp=CreateObject("Excel.Application")
oExcelApp.visible=True
oExcelApp.Workbooks.open  "D:\List.xls"
oExcelApp.Workbooks(1).Activate
Set oExcelSheet=oExcelApp.ActiveWorkbook.WorkSheets(1)
oExcelSheet.activate
For i=lbound(arrItems) to ubound(arrItems)
    oExcelSheet.Cells(i+1,1)=arrItems(i)
Next
oExcelApp.WorkBooks(1).Save

oExcelApp.quit
Set oExcelApp=nothing
Set oExcelSheet=nothing
*Note :For the code to run properly
  1. Open http://newtours.demoaut.com/mercuryreservation.php
  2. Login with user id: mercury and pwd :mercury
  3. Add the object "Departing from" list item to the object respository.
  4. Make sure that the List.xls is created in 'D' Drive