Hey folks,
Please find below code for working with Web table to get row count, column count and fetch records from the web table.
URL=http://www.google.com/
Systemutil.Run "iexplore.exe",URL
browsernm=".*Google.*"
Pagenm=".*Google.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
wait(5)
CurrObj.WebEdit("name:=q","html tag:=input").Set "Web table in qtp"
CurrObj.WebButton("name:=Google Search").Click
'to find the row count from web table
wtblrowcnt=CurrObj.WebTable("name:=nav_logo14").rowcount
msgbox wtblrowcnt
'To find the column count from web table
wtblcolcnt=CurrObj.WebTable("name:=nav_logo14").columncount(1) 'column count argument is row number
msgbox wtblcolcnt
'To fetch the data from particular cell
celldata= CurrObj.WebTable("name:=nav_logo14").getcelldata(1,1)
msgbox celldata
'Get the row number for defined text
RowNumber = Browser("").Page("").WebTable("").GetRowWithCellText("Trupti")
'CellText works as same as GetCellData method
Browser("").Page("").WebTable("index:=0").CellText(1,1)
'CellTextbyContext returns the text within a cell delimited by a character. We can retrieve the text before '(or) after the delimiter using this method.
' Consider a cell having the text “Jethva;Trupti”. Here “;’ is the delimiter
Browser("").Page("").WebTable("index:=0").CellTextByContext(1,1,"",";")
'TextCellExist method checks whether a text exists in a cell or not. It returns true, if the input text exists 'in the cell, else it returns false. Rather than using GetCellData method and then comparing the result with 'the input text, we can achieve it using this simple method.
Browser("").Page("").WebTable("index:=0").TextCellExist(1,1,"Trupti")
Thanks,
Trupti
Please find below code for working with Web table to get row count, column count and fetch records from the web table.
URL=http://www.google.com/
browsernm=".*Google.*"
Pagenm=".*Google.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
wait(5)
CurrObj.WebEdit("name:=q","html tag:=input").Set "Web table in qtp"
CurrObj.WebButton("name:=Google Search").Click
wtblrowcnt=CurrObj.WebTable("name:=nav_logo14").rowcount
msgbox wtblrowcnt
'To find the column count from web table
wtblcolcnt=CurrObj.WebTable("name:=nav_logo14").columncount(1) 'column count argument is row number
msgbox wtblcolcnt
'To fetch the data from particular cell
celldata= CurrObj.WebTable("name:=nav_logo14").getcelldata(1,1)
msgbox celldata
'Get the row number for defined text
RowNumber = Browser("").Page("").WebTable("").GetRowWithCellText("Trupti")
'CellText works as same as GetCellData method
Browser("").Page("").WebTable("index:=0").CellText(1,1)
'CellTextbyContext returns the text within a cell delimited by a character. We can retrieve the text before '(or) after the delimiter using this method.
' Consider a cell having the text “Jethva;Trupti”. Here “;’ is the delimiter
Browser("").Page("").WebTable("index:=0").CellTextByContext(1,1,"",";")
'TextCellExist method checks whether a text exists in a cell or not. It returns true, if the input text exists 'in the cell, else it returns false. Rather than using GetCellData method and then comparing the result with 'the input text, we can achieve it using this simple method.
Browser("").Page("").WebTable("index:=0").TextCellExist(1,1,"Trupti")
Thanks,
Trupti
This has helped me, especially on the last snippit of code. :-)
ReplyDelete