Forum Discussion

cjfoeller0404's avatar
cjfoeller0404
Occasional Contributor
24 days ago
Solved

Find and Use a Sibling Object Starting from an AliasChild Object

I am attempting to find an object that is located directly next to an initial object. The way I am attempting to do this is by trying to get the .Parent of the initial object, then attempting to do a WaitPanel Function call on the parent object to locate the desired child. Though in attempting this, it is unable to find the Panel object.

Both the Desired Object and Parent Container do not have an static ID or class that can assist directly with object discovery, and the text inside this "Panel(0)" object changes on every instance. 

For Example:
let anchorobj = [PathToProcess.Page].WaitAliasChild("MappedName", 1000); //This is our Panel(1) object, this is found successfully and hence can be used without issue
let parent = anchorobj.Parent; //I want this to be the Panel(2) object the anchorobj is nested in, though this does not seem to be true
let desiredobject = parent.WaitPanel(0, 1000); //This is creating a Utils.CreateStubObject() as far as I can tell where desiredobject.Exists == false; I want this to get the Panel(0) object marked as Desired Object


Is there a better/more correct way to do this method of attempting to get this object?

  • Alright, figured it a solution. Though I doubt this is the optimal method

    So to get the actual Parent Object, it needs to use ".parentNode" (or ".parentElement"), though as this is browser based javascript element, it does not create the "TestComplete Object", hence using this will cause parent.Exist == false. So once I have gone up enough levels to reach the parent I want (in the example it's only the one level), I can then take the class of the object (that changes every run with Electron's Code Obfuscation), do a WaitElement searching for an element with that Class Name, and then I can do the WaitPanel to find the desired object.

    For Example:

    let anchorobj = [PathToProcess.Page].WaitAliasChild("MappedName", 1000);
    let parentclass = anchorobj.parentElement.className;
    let parent = [PathToProcess.Page].WaitElement("contains(@class, '" + parentclass+ "']", 1000);
    let desiredobject = parent.WaitPanel(0, 1000);

     

    I'll leave this open for a couple days in case anyone knows a more optimal solution

2 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    If the hierarchy tree structure looks exactly what you have provided, then your coding is almost correct.

    If you have a name mapping for object Panel(0).Panel(2).Panel(1), then you can get the parent object using the Parent property, which will retrieve Panel(0).Panel(2). You can either directly access Panel(0).Panel(2).Panel(0) or use the WaitNNN methods to wait for the object to exist.

    let anchorobj = [PathToProcess.Page].WaitAliasChild("MappedName", 1000); // Panel(0).Panel(2).Panel(1)
    let parent = anchorobj.Parent; // Get parent Panel(0).Panel(2)
    
    let desiredobject = parent.Panel(0) // Get directly
    // OR
    let desiredobject = parent.WaitChild("Panel(0)", 1000); // Wait for object to exist. You can also use WaitAliasChild or WaitNamedChild
    
    if (desiredobject.Exists)
      Log.Message(desiredobject.Name);
    else
      Log.Message("Not found");

    Use the appropriate WaitNNN method, and adjust the time out period. 

    FYI, these are child objects of parent object Panel(0).Panel(2):
    Panel(0).Panel(2).Image("PG_png")
    Panel(0).Panel(2).Panel(0)
    Panel(0).Panel(2).Panel(1)

     

  • cjfoeller0404's avatar
    cjfoeller0404
    Occasional Contributor

    Alright, figured it a solution. Though I doubt this is the optimal method

    So to get the actual Parent Object, it needs to use ".parentNode" (or ".parentElement"), though as this is browser based javascript element, it does not create the "TestComplete Object", hence using this will cause parent.Exist == false. So once I have gone up enough levels to reach the parent I want (in the example it's only the one level), I can then take the class of the object (that changes every run with Electron's Code Obfuscation), do a WaitElement searching for an element with that Class Name, and then I can do the WaitPanel to find the desired object.

    For Example:

    let anchorobj = [PathToProcess.Page].WaitAliasChild("MappedName", 1000);
    let parentclass = anchorobj.parentElement.className;
    let parent = [PathToProcess.Page].WaitElement("contains(@class, '" + parentclass+ "']", 1000);
    let desiredobject = parent.WaitPanel(0, 1000);

     

    I'll leave this open for a couple days in case anyone knows a more optimal solution