Forum Discussion

funmay's avatar
funmay
Contributor
6 years ago
Solved

Passing variable is declared as undefined/null while looping

Passing variable is declared as undefined/null while looping,this is seen 4 out of 10 times.If the number of rows is ten at any row number Testcomplete will throw error that one of the variable is undefined/null.

browser.FindChildByXpath(tablexPath+"//tr[undefined]/td[" + j + "]");

The variable [i] or [j] is declared as null/undefined 4 out of 10 times while looping through the elements.

See the example below:

var rows=browser.FindChildByXpath(xPathtable);
var cols =browser.FindChildByXpath(xPathColumn);


for (int i =1;i<rows.RowCount;i++) { 
 for (int j =1;j<col.ColumnCount;j++){
["Delay"](3000)
var textValue=browser.FindChildByXpath(tablexPath+"//tr[" + i + "]/td[" + j + "]");
textValue.contentText;  }}

 

  • Put a breakpoint in before the loops, add your variables to the watch list, and then run this code in debug mode and step through it a line at a time.  You should be able to see the conditions that cause it to see the null value.  

     

    If you do this several times and do not see the error state, then consider that you have a timing issue and may need to slow this bit of code down for all the values to be registered properly.

4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The thing about web tables is that each row doesn't necessarily have to have the same number of columns.  So, your loop is finding cells in the row but if the column number doesn't match, that will return NULL.

     

     

    • funmay's avatar
      funmay
      Contributor

      This is a webtable that have the same columns for all the rows.The null/undefined is seen 4 out of 10 runs.

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Put a breakpoint in before the loops, add your variables to the watch list, and then run this code in debug mode and step through it a line at a time.  You should be able to see the conditions that cause it to see the null value.  

         

        If you do this several times and do not see the error state, then consider that you have a timing issue and may need to slow this bit of code down for all the values to be registered properly.