Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Table
#1
Solved: 10 Years, 8 Months, 4 Weeks ago
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:
Reply
#2
Solved: 10 Years, 8 Months, 4 Weeks ago
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",""))
Thanks,
SUpputuri
Reply
#3
Solved: 10 Years, 8 Months, 4 Weeks ago
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.
Reply
#4
Solved: 10 Years, 8 Months, 4 Weeks ago
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
Thanks,
SUpputuri
Reply
#5
Solved: 10 Years, 8 Months, 4 Weeks ago
got it ..thanks Smile
Reply
#6
Solved: 10 Years, 8 Months, 4 Weeks ago
no problem ... welcome buddy
Thanks,
SUpputuri
Reply
#7
Solved: 10 Years, 8 Months, 4 Weeks ago
Code:
oGetAlp("innertext").Value =  ".*" & sSearchItem &".*"


Query:-


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

Thanks in Advance
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad Identify the Button in a Web table spsraj 4 7,793 09-29-2010, 08:24 PM
Last Post: aravindln

Forum Jump:


Users browsing this thread: 1 Guest(s)