Forum Discussion

radu's avatar
radu
Occasional Contributor
6 years ago

Finding web table (sub-)components

Dear all,

I have some troubles finding tables (components) on the a web page, when using the Tree model and Javascript. Basically, I'm trying to get the (1) column headers and the (2) body of the table containing the data (these two things are a sort of sub-tables within the big (composite) table, see the first attached picture).

I've tried using the Find method, to get to the subcomponents searching after their class, their tagName, or some qa atributes, but I didn't have any success (please see the code below). I don't want to get stuck having the full path of the tables, although this works (i.e. I can find the table subcomponents if I provide their full path - but this makes code hardly readable and the path will not work for other pages). If I would search after ObjectType=Table, I don't know how to get the other sub-component (I think for every search the same subcomponent will be found by the Find method).

Any help/suggestions are welcomed on how to deal with class/tagName/tbody/thead.

Thank you!
R

 

function DetectTableComponents()
{
  var page = Sys.Browser("chrome").Page("*");
  page.Wait();
  Sys.HighlightObject(page);
  
// finding the big (composite) table. This is ok
  var parent = page.Find("data-qa", "qa-table", 20);
  var obj;

/*it works*/        obj = Sys.Browser("chrome").Page("*").Panel("root").Panel(0).Panel(0).Panel(1).Panel(0).Panel(1).Panel(1).Panel(0).Panel(0).Panel(1).Panel(0).Panel(0).Panel(0).Table(0);
/*DOESN'T WORK*///  obj = parent.Find("Class", "thead", 20);
/*DOESN'T WORK*///  obj = parent.Find("tagName", "thead", 20);
  Sys.HighlightObject(obj);
  Log.Message("1. These are the column headers", obj.FullName, pmNormal, "Default attributes", obj);


/*it works*/  obj = Sys.Browser("chrome").Page("*").Panel("root").Panel(0).Panel(0).Panel(1).Panel(0).Panel(1).Panel(1).Panel(0).Panel(0).Panel(1).Panel(0).Panel(0).Panel(1).Table(0);
/*DOESN'T WORK*///  obj = parent.Find("class", "tbody", 20);
/*DOESN'T WORK*///  obj = parent.Find("tagName", "tbody", 20);
/*DOESN'T WORK*///  obj = parent.Find("class", "table-enhanced__body", 20);
/*DOESN'T WORK*///  obj = parent.Find("data-qa", "qa-table-body", 20);
  Sys.HighlightObject(obj);
  Log.Message("2. This is the data part", obj.FullName, pmNormal, "Default attributes", obj);
}

6 Replies

  • cunderw's avatar
    cunderw
    Community Hero

    Can you provide screenshot of more details of what the properties look like (include all of them) in the Test Complete object browser?

     

    Also, is there any reason you're not using name mapping? This would provide a much faster way of finding your objects by using a closer to full path, while Aliases will allow you for much shorter paths in your code. 

    • radu's avatar
      radu
      Occasional Contributor

      Hi cunderw!

      I've decided not to use nameMapping because the url is not always the same (i.e. when the user chooses different input data, the url and the data displayed changes). Also there are controls which appear on all the pages, and if I would like to use them I would need to map the same controls on all pages.

      Can you give some hints why my above trials didn't work (the search after class, tagName)?

      Thank you!
      R

  • radu's avatar
    radu
    Occasional Contributor

     

    Hi! Sorry for the late response.

     

    In the end, I  managed to find the things using a two parameter search like this:

      PropArray = new Array("ObjectType", "innerHTML");
      ValuesArray = new Array("Table", "<tbody*");
      obj = parent.Find(PropArray, ValuesArray, 20);
    and
      PropArray = new Array("ObjectType", "innerHTML");
      ValuesArray = new Array("Table", "<thead*");
      obj = parent.Find(PropArray, ValuesArray, 20);

     

    It's a pity that testcomplete considers the tbody (table body) and the thead (table head) as simple panels.

     

    Thank you for your time and support!

    R