iterating through a grid
THIS IS A QUESTION I POSTED IN THE TEST COMPLETE FORUM AND THE ANSWER IS GIVEN AT THE BOTTOM. I'M UNABLE TO DUPLICATE THE PIECE OF CODE IN SILK TEST. WE ARE DOING A COMPARISON TO SEE IS BETTER. CAN ANYONE HELP US WITH THE SAME PIECE OF CODE IN 4TEST. THE CODE AT THE BOTTOM IS IN VBSCRIPT.
we are trying to functional test a grid in our web application. the first column of the grid displays a LINK, each of which are identified using the following:
set obj = window.frames.BBWebGrid1.document.all.c1549_2id
set obj = window.frames.BBWebGrid1.document.all.c1456_2id
etc. Thus, you can see that the only thing that is different between the ids of the links is the number in the middle i.e. 1549, 1456 etc.
The second column of the grid is a text box, which is identified by the following
set obj = window.frames.BBWebGrid1.document.all.c1549_6id
set obj = window.frames.BBWebGrid1.document.all.c1456_6id
Thus, for a particular row, the number cxxxx is common. but the number after the underscore (_) changes.
Thus to conclude, a simple grid in terms of its ids would be.
column 1(links) coulmn 2(text boxes)
row 1 c1549_2id c1549_6id
row 2 c1456_2id c1456_6id
This is the way the grid is organized in terms of its unique IDS.
What i need to do is the following: Just iterate through the grid and fill in the text boxes in column 2. I don't know how many can be there? there could 0, 1 or a 100. I know one thing for sure, the number 1456 or 1549 etc FOR A PARTICULAR ROW is definitely the same. Im making use of VBScript. Any idea how you would go about filling in the text boxes? any help would be appreciated. I also know that 2 and 6 are fixed for my columns and wont change.
I was thinking of somehow getting a handle to the items in the first column, then replacing the 2 in the handle with the 6 and then using the generated id to get access to the correspoinding text boxes.
This script searches for the edit controls by their names. It iterates through all children of the "document.all" object and checks the last three characters of the object name, if they are "6id", the script changes the "value" property of the object.
Set p = Sys.Process("IEXPLORE")
Set w = p.Window("IEFrame", "*", 1)
Set p = w.Page("*")
Set AllElements = p.frames.BBWebGrid1.document.all
ChildCount = AllElements.ChildCount
' Iterates trough all children of the "document.all" object
For I = 0 To ChildCount - 1
Set CurrentObject = AllElements.Child(I)
Last3Chars = Mid(CurrentObject.Name, Len (CurrentObject.Name) - 2)
If Last3Chars = "6id" Then
CurrentObject.value = I
THANKS FOR YOUR HELP.
Re: iterating through a grid
For 4Test language in SILK, Use the GetChildren then filter all the HtmlTextField by using ClassOf function. Now you can use the SetText function for HtmlTextField to pupolate the data.
[ 11-04-2005, 01:15 PM: Message edited by: ppat7046 ]
Re: iterating through a grid
I have never worked with Testcomplete, but have some experience with SilkTest.
I think what you need is to set the value in TextBoxes and not necessarily 'DUPLICATE' the peice of code (in terms of logic). If this is right, then, follow these steps:
1. Record the Grid control. Check what is being recorded. If like you say, all the objects have ids associated with it, you may get a recording similar to the following:
window xxxxxx SomeWindow
and so on.
As per you this textfield is
So what you should do in Silk is:
1. Loop through header row of the table
2. If I am not wrong, if all rows in table have $<####> constant, it would also be a part of the header.
3. Get this value in a variable with a statement like
string sColId = SomeWindow.ColumnHeader1.GetID ()
strip this string of any unwanted text (maybe like _xid, so, say
NewsColId = sColId less the stripped chars.
the sTextBoxId = NewsColId + "_6id"
So, to set a value in each textbox of this row would be as simple as:
// Note the scripting syntax, which is dynamic
Put all the above statments in a loop for each row, and you will not have to parse each and every child window.
Of course this method would work only if Silk recognized these ids...
Paste a recorded window declaration for this window, and maybe I can tell you the actual scripting statements.
Of course if Silk Does not recognize the id's, Prashants solution is what you are looking for.
Hope this helps.
// The Persistent Bugger