cancel
Showing results for 
Search instead for 
Did you mean: 

Keep getting Object required error message when using FindAllChildren method

SOLVED
Frequent Contributor

Keep getting Object required error message when using FindAllChildren method

Hi everyone,

I was trying to use FindAllChildren method to look for an object from the parent, but I keep getting "VBScript runtime error. Object required: 'FindAllChildren(...)'" when I run the script below. But if I use Find or FindChild method, it worked fine. Can anyone help me what was wrong?

 

Sub test

sys.Browser("*").Page("*").Find("contentText", "CorelDRAW Graphics Suite 2019 Education Edition", 10).Parent.FindAllChildren("ObjectLabel", "Choose a language:", 50).ClickItem("Spanish")

End Sub

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Keep getting Object required error message when using FindAllChildren method

Hi @whuang 

 

Why are you combining FindAllChildren with a click ?  FindAllChildren returns an array of items, not a single item, even if the array has a length of 1.  TC probably won't know what to click.  Since FindAllChildren excudes the current node, it is possible that by doing a FindAllChildren, you are excluding the one thing that TC can click, namely the parent.  If you use a FindChild rather than FindAllChildren with exact riterai, you should get a single list to to clickitem on

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

4 REPLIES 4
Community Hero

Re: Keep getting Object required error message when using FindAllChildren method

Hi @whuang 

 

Why are you combining FindAllChildren with a click ?  FindAllChildren returns an array of items, not a single item, even if the array has a length of 1.  TC probably won't know what to click.  Since FindAllChildren excudes the current node, it is possible that by doing a FindAllChildren, you are excluding the one thing that TC can click, namely the parent.  If you use a FindChild rather than FindAllChildren with exact riterai, you should get a single list to to clickitem on

 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,

View solution in original post

Community Hero

Re: Keep getting Object required error message when using FindAllChildren method

To add to @RUDOLF_BOTHMA 

You're combining a Find to find an object and then calling the parent of it before doing a findallchildren... what if the first Find doesn't find anything at all?  Or, what if the first find finds something that doesn't HAVE a Parent to call "FindAllChildren" on?

If you're going to use Find methods to find objects, you need to add additional code to verify that the Find worked all along the line.  Otherwise, you'll get all sorts of potential object not found issues.


Robert Martin
[Community Expert Group]
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
Frequent Contributor

Re: Keep getting Object required error message when using FindAllChildren method

 Thanks @tristaanogre @RUDOLF_BOTHMA I thought FindChild method would only search for one child and return the search result, and FindAllChildren would look through all Children but still return the first finding as the result. Now I understand. Below is the screenshot of the tree view. Link(0) is the object I was looking for by using the first Find, and the LanguageSelection is somewhere under another parallel object. Can you let me know whatelse I can add into the code to the Find worked all along the line?

1.JPG

Community Hero

Re: Keep getting Object required error message when using FindAllChildren method

Hi @whuang 

sys.Browser("*").Page("*").Find("contentText", "CorelDRAW Graphics Suite 2019 Education Edition", 10)

 

This is likely bringing back the last of the two panels, since you have two panels that appear to have the same name.  In my experience, TC returns them in order from deepest in the tree to highest.  I wouldn't count on this though.

 

I would suggest name mapping the top Panel("CorelDRAW Graphics Suite 2019 Education Edition")  Now it's easier to find the next panel with the same name uniquely and, well, name mappings are faster, neater and easier to manage your KWTs and scripts if layouts change

 

Although I'm not sure why you need to move from the link to the parallel node, I would probably look at the following pseudo code (assuming you have mapped the panel)  I leave the translation of the code from jscript to the viewer...

var topPanel = Aliases...CorelDrawPanel //just for clarity of code.  you could use the entire alias.  Allocating to a var just shortens it

var findproperties = ["ObjectType","ObjectIdentifier"] //Guessing at identifiers - you will have to check
var findvalues = ["Link","0"]
var linkItem = topPanel.FindChild(findproperties,findvalues...);
if(linkItem.Exists){
Log.Message("Link Found");
}
else{
Log.Message("Link Not found");
}
//If you have no particular need for the link, you could rather map the bottom panel the same way
var secondPanel = Aliasses..SecondPanel
//If you haven't mapped it, find the panel with a standard find:
var secondPanel = topPanel.FindChild(["contentText","ObjectType"],["coreldraw..."],["Panel"],....);
//either way, you have the bottom tier panel by that name

I'm guessing the Select("LanguageSelection_1"); has contentText "spanish" and Select("LanguaghSelection_2") has contentText "English" etc, so search for the correct one

var selectProps = ["contentText","ObjectIdentifier"];
var selectVals = ["Spanish"],["LanguaghSelection_*"] //Note the wildcard in the objectidentifier so you will search all languages
var spanishSelect = secondPanel.FindChild(selectProps,selectVals,...) if(spanishSelect.Exists){ Log.Message("Spanish is a language); } else{ Log.Message("Spanish isn't a language"); } //Now on to the click: //If you can click the select directly: spanishSelect.Click(); //The more likely scenario, the onClick is linked to the panel, in which case: spanishSelect.Parent.Click(); 

 


-------------------------------------------------
Standard syntax disclaimers apply
Regards,