Ask a Question

Need C# syntax for ChildObjectName inside of a WaitChild event

SOLVED
bo_roop
Contributor

Need C# syntax for ChildObjectName inside of a WaitChild event

The online help shows me this:

 

if (Obj["WaitChild"](ChildObjectName, 0)["Exists"])

 

What I want to do is use ["Panel"](2) as my child object's name... but I can't figure out the syntax to set ChildObjectName = ["Panel"](2) in my script and get it to replay without errors.

 

 

I also can't reliable use a FindChild event as TestComplete does not replay 100% of the time. 😞

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Try changing from FindChild to FindChildEx with an additional parameter for timeout (see my example above)


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

12 REPLIES 12
tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Well, what errors are you getting, first of all, because that will help us know better what EXACTLY is going wrong.

 

But suffice it to say, you need to Name as EXACTLY the string as it shows in Object Browser. So, if the string shwos as ["Panel"](2) then you need to present that as a string.

 

So... I don't know C#Script well, but I'm assuming that the code should be something more like

 

ChildObjectName = "[\"Panel\"](2)"

Because the C# Script language base in TestComplete has it's root in JScript, you need the slash (\) characters before the double quotes to indicate that you are using the double quotes.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
bo_roop
Contributor

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Sorry,

 

Should have mentioned that that syntax doesn't work either. 😞

 

 

tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

So, what do you get in the way of errors, if any?

 

Have you tried the following?

ChildObjectName = "[\"Panel\"](2)"

if (Obj["WaitChild"](ChildObjectName, 10000)["Exists"])

According to the help documentation, (https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/waitch...), that second parameter, if it's set to 0, will return immediately... even if the object is not found.  By changing it to 10000, it actually sets a maximum time to wait for the object to appear.  It COULD be that the object may have a delay before it "Exists" and you need to actually wait for it.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
bo_roop
Contributor

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Good grief!

 

So as I was waiting 10000ms for the panel to be missing, it was found! Seems there's a 2nd panel(2) that exists when my first condition doesn't happen. So essentially, my code is always falling into the true section of the if statement which made me believe that the false was never being triggered.

 

Ugh.

 

Is it Friday yet? 🙂

tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

This is one reason why depending upon a single property (like Name) is insufficient for object identification... there are two objects that potentially are identified as ["Panel"](2)... what makes them unique?  is there a className that distinguishes them? innerText? contentText? etc...

 

This is why "FindChild" has arrays as the first two parameters... an array of property names and an array of property values so, again, you're not dependant upon a single property...

 

AND... again... this is why NameMapping works the way it does... it works on that same "Child" object principle... look for a child of the parent objects with this set of property/value pairs...


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
bo_roop
Contributor

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Yup... and I agree.

 

But going back to my original post: "I also can't reliable use a FindChild event as TestComplete does not replay 100% of the time. Smiley Sad"

 

The script will not reliably find the child control every time for me.

 

I have a page in my IE11 browser:

AnyPage = Sys["Browser"]("iexplore")["Page"](ProjectSuite["Variables"]["ServerURL"]+"/*");

 

and I need to find the textbox in our floating menu in the old UI:

AnyPage["Table"](1)["Cell"](0, 0)["Panel"](1)["Textbox"]("menuSearch")

 

or in the new UI:

["Panel"](2)["Nav"]("menu_root")["Panel"](0)["Textbox"]("menu_search_input")

So I'm trying to write a function that checks for the existence of one and then potentially the other... without relying on a variable that says which version of the UI we're running against. (which is how my current implementation gets around this issue)

 

I know there are plenty of properties that change between these two textboxes. (idStr being the most important). But running the FindChild function on the two textboxes will not reliably replay in TestComplete on each of my pages.

 

So I was trying to go down to the root of the menu's hierarchy (table vs. panel and see if I could get it to work that way)... and I'm not having much luck that way either.

 

I'm open to suggestions. 🙂

tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Can you share an example of your attempt to use FindChild that is not working?  I don't think the problem is necessarily in FindChild, but perhaps simply in finding the correct properties to work with.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
tristaanogre
Community Hero

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

Generally speaking.... start with a common parent object on both UI's... let's called it PanelX.  So, you could do your code like this (I'm using a JavaScript syntax but, technically, this should work fine even in your C#Script since it is, under the covers, just JScript with support for C# Syntax).

 

 

var myObject = PanelX.FindChildEx(['ObjectType','idStr'],['Textbox','menuSearch'], 5, true, 10000)
if (myObject.Exists) {
    Log.Message('Must be using the old UI');
}
else {
    myObject = PanelX.FindChildEx(['ObjectType','idStr'],['Textbox','menu_search_input'], 5, true, 10000);
    if (myObject.Exists){
        Log.Message('Must be using the new UI');
    }
    else {
        Log.Warning('Could not find the object in either UI pattern');
    }
}

 

Basically... search for it at a depth of 5 (this is assuming that PanelX is at most 5 ancestors above the desired child object) using the old UI idStr and continue pinging it for 10 seconds until either the object is found or the time out is reached.  If it is not found there, search using the new idStr and continue pinging for 10 seconds.  If it's not found there, log a warning, otherwise, myObject is now the desired object.

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
bo_roop
Contributor

Re: Need C# syntax for ChildObjectName inside of a WaitChild event

 

PropArray = new Array("ObjectType", "idStr", "ObjectIdentifier", "className");
ValuesArray = new Array("Textbox", "menuSearch", "menuSearch", "menuSearchReady");

// Find the cell where the link/button resides
var textbox = AnyPage["Find"](PropArray, ValuesArray, 1000);

This didn't reliably replay, so we decided to drop the ObjectIdentifier & className.

 

PropArray = new Array("ObjectType", "idStr");
ValuesArray = new Array("Textbox", "menu-search-input");

// Find the cell where the link/button resides
var textbox = AnyPage["Find"](PropArray, ValuesArray, 1000);

This didn't replay 100% of the time either... probably 95-98% of the time, but it was an improvement over the 85-90% we started with.

cancel
Showing results for 
Search instead for 
Did you mean: