Wednesday, May 4, 2011

QTP-Working with Export data to Excel from dropdown using Excel object

Hi Readers,


I have try to write code for getting data from dropdown and split it and enter it in excel sheet using Excel Application object without using data table.In this example, Book2.xls should be already created in c: drive.Browser name and page name should be according to your test site. Weblist name proeprty should be according to your test page. Capture it using Object Spy on you page.

Hope this will helpful to you.


URL=www.google.com

Systemutil.Run "iexplore.exe",URL
browsernm="Google"
Pagenm="Google"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
'CurrObj.WebList("name:=Type").Click


Dim typeitem
typeitem=CurrObj.WebList("name:=Type").GetROProperty("items count") ' count number of items in dropdown
msgbox typeitem


Dim oexcel
Dim obook
Dim osheet
sSampleFolder="C:\"
sSampleFile="Book2.xls"
Set oexcel=CreateObject("Excel.Application")
Set obook=oexcel.Workbooks.Add
Set osheet=obook.Worksheets(1)
osheet.Range("A1").value="Type"
For i=1 to typeitem
a=CurrObj.WebList("name:=Type").GetItem(i)
osheet.Range("A2").value=a
Next
obook.SaveAs(sSampleFolder & sSampleFile )
Set osheet = Nothing
Set obook = Nothing
oexcel.Quit()
Set oexcel = Nothing

1 comment:

  1. Hi Trupti,

    Need some help on how to retain excel drop down even after running qtp scripts?
    As soon as I run qtp script, the drop-down which I'm using in excel is been removed, how to retain them?

    Regards,
    Anil

    ReplyDelete