Micro Focus QTP (UFT) Forums

Full Version: Web Table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Today i have faced one interview question.
Q:In a web Table some of the cell contains same cell data.how to find out number of similar data & how many cell contains this same data.
Example:Suppose 5 cell contains the data "X".How to find how many "X" are there & how many cell contains this.
x a b c
d e f x
z x x y
v b x m

Ans:
you can use descriptive program and get the childobjects (TR with innertext 'x') and then use the use your own logic to get the number of x in the row.
Simple logic:
Code:
NumberOfX= Len(childItem(i))-Len(Replace(childItem(i),"x",""))
hi, can you please explain your approach, I am not sure how you mean to go about it. say in the webtable, each cell is a webelement, we need to count no, of cells which have values as "X", ie innertext for the webelement is "x", in this case , I don't think ChildObject can be used as the webelement, thou contained in the webtable, is a child of the page and not the webtable. correct me if I'm wrong.
Check out this below snippet
Code:
'********************************************
''My Search Item
sSearchItem = "s" 'Change this based on your interest
'*********************************************

Set oGetAlp = Description.Create()
oGetAlp("html tag").value = "TR"
oGetAlp("innertext").Value =  ".*" & sSearchItem &".*"

Set oRows = Browser("QTP Forums - Search Results").Page("QTP Forums - Search Results").WebTable("Search Results").ChildObjects(oGetAlp)
Set oGetColAlp = Description.Create()
oGetColAlp("html tag").value = "TD"
oGetColAlp("innertext").Value = ".*" & sSearchItem &".*"
iRows = oRows.Count

For i = 0 to oRows.Count-1
    'msgbox oRows(i).GetROProperty("innertext")
    Set oTD = oRows(i).ChildObjectS(oGetColAlp)
    For j = 0 to oTD.Count-1
        sTDValue = oTD(j).GetROProperty("innertext")
        NumOccurances = NumOccurances+(len(sTDValue)-Len(Replace(sTDValue,sSearchItem,"")))
    Next
    iCols = iCols+ oTD.Count
Next

print "Total Number of Rows with " & sSearchItem &  ": "& iRows
print "Total Number of Columns  with  " & sSearchItem &  ": " & iCols
Print "Total Number of Occurances of  " & sSearchItem & ": " &  NumOccurances
Let me know if you have any queries on this
got it ..thanks Smile
no problem ... welcome buddy
Code:
oGetAlp("innertext").Value =  ".*" & sSearchItem &".*"


Query:-


What is ".*" used for?What it does?

Thanks in Advance