Micro Focus QTP (UFT) Forums
Webtable to datatable - 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: Webtable to datatable (/Thread-Webtable-to-datatable)



Webtable to datatable - sravsand - 09-02-2011

How to write the script for extracting the data from webtable to datatable?


Thanks inadvance
sandeep


RE: Webtable to datatable - suresz449 - 09-06-2011

Here I am taking an Example of W3 Schools Site, in this website we have webtable like vbscript functions.

Code:
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe"
Browser("Google").Navigate "www.w3schools.com"
Browser("Google").Page("W3Schools Online Web Tutorials").Link("Learn VBScript").Click
Browser("Google").Page("VBScript Tutorial").Link("VB Functions").Click

rCount = Browser("Google").Page("VBScript Functions").WebTable("Function").RowCount

For i = 2 to rCount

    cCount = Browser("Google").Page("VBScript Functions").WebTable("Function").ColumnCount(i)
        sData1 = Browser("Google").Page("VBScript Functions").WebTable("Function").GetCellData(i,1)
    sData2 = Browser("Google").Page("VBScript Functions").WebTable("Function").GetCellData(i,2)
        DataTable("Function",dtGlobalSheet) = sData1
    DataTable("Description",dtGlobalSheet) = sData2
    DataTable.SetCurrentRow(i)

Next

Here I am taking an example of W3schools web application

Code:
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe"
Browser("Google").Navigate "www.w3schools.com"
Browser("Google").Page("W3Schools Online Web Tutorials").Link("Learn VBScript").Click
Browser("Google").Page("VBScript Tutorial").Link("VB Functions").Click

rCount = Browser("Google").Page("VBScript Functions").WebTable("Function").RowCount

For i = 2 to rCount

    cCount = Browser("Google").Page("VBScript Functions").WebTable("Function").ColumnCount(i)
    sData1 = Browser("Google").Page("VBScript Functions").WebTable("Function").GetCellData(i,1)
    sData2 = Browser("Google").Page("VBScript Functions").WebTable("Function").GetCellData(i,2)
    DataTable("Function",dtGlobalSheet) = sData1
    DataTable("Description",dtGlobalSheet) = sData2
    DataTable.SetCurrentRow(i)

Next