cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing SwingObjects using FindAllChildren

TestQA1
Occasional Contributor

Accessing SwingObjects using FindAllChildren

Hi,

 

I have a input field with sys.Process("some property").SwingObject("some property").SwingObject("some property").SwingObject("input field name","",0) in the Test Project.

I need to access the last SwingObject in the above path.

 

I first want to find all the children of the sys.Process including all the child/grand child swing objects and then use index to perform operations on those objects.

 

p = Sys.Process("xyz");

let pp = p.FindAllChildren(" "," ",7); //tried adding javafullclassname property but didn't work

if (pp.length > 0){

for (i = 0; i < pp.length; i++){

Log.Message(pp[i].FullName);

pp[i].click();

pp[i].keys(u);

}

10 REPLIES 10
AlexKaras
Community Hero

Re: Accessing SwingObjects using FindAllChildren

Hi,

 

.FindAllChildren(" "," ",7)

The above line of code says: "Find all children up to the depth of 7 that have property with the name <one space> and the value of this property equals to <one space>".

I bet no such object exists in your application.

If you like to get all children up to level 7, then provide a property that exists for any object and indicate that it may have any value. E.g.: .FindAllChildren("name","*",7)

If you like to get just input fields, the code might be like this: .FindAllChildren("input field name","*",7)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
sonya_m
Community Manager

Re: Accessing SwingObjects using FindAllChildren

Thanks Alex!

 

 

Hi @TestQA1 , I see that you replied straight to the email notification, this way your reply won't be posted to the community.

Let me quote it for this time, please reply inside the community in the future, thank you!

 

Here's your reply:

 

>>

Hi, 

 
I'm sorry I should have entered property name and value in FindAllChildren, just left it blank for the post, in actual I put the property and the value in real code. What I'm trying to do is to get all children on the user credentials dialog and then extract username and password based on index. Javafullclassname property is available for username and password field and for the dialog that contains those field has AWT properties.
<<
 
 

Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
AlexKaras
Community Hero

Re: Accessing SwingObjects using FindAllChildren

@sonya_m :

Sonya, thank you for reposting the reply.

 

@TestQA1 :

What I'm trying to do is to get all children

And ?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
TestQA1
Occasional Contributor

Re: Accessing SwingObjects using FindAllChildren

Hi Alex,

 

The swing desktop app has a login page with a login dialog on it. I have been trying to first get all the child/grand child objects on the dialog and then want to perform operation on those grand child objects using index.

 

Javafullclassname property is there for username and password fields. But, I am not able to fetch these two objects.

 

Thank you.

AlexKaras
Community Hero

Re: Accessing SwingObjects using FindAllChildren

Hi,

 

I am not able to fetch these two objects.

Any more details? Your code? Error message? What line of code throws the error? Screenshot of Object Browser with one or both objects that you'd like to find? Anything else that can help others to understand what you have tried and what exactly does not work for you?

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
TestQA1
Occasional Contributor

Re: Accessing SwingObjects using FindAllChildren

Object Explorer Hierarchy:

Sys.Process("abc").SwingObject1(some property,value).SwingObject2(some property,value)

Now SwingObject2 has two childs, SwingObject2.1(some property,value) and SwingObject2.2(some property,value)

I want to fetch all childs of SwingObject2.1 (lets say it has 5 direct childs and I want to get SwingObject2.1.2) above through iteration or something.

 

l = Sys.Process("abc");
ll = l.SwingObject2("some ClassName", "value",index , WndIndex);
lm = ll.FindAllChildren("JavaFullClassName","value of the class of the SwingObject2.1.2 ",10);

if(lm.length>0){
Log.Message("length exist");
Log.Message(lm.FullName);
}
}

else {
Log.Message("else")
}

 

Is this the right way to iterate through swing objects? And I don't know how to find indexes in Object Tree, I'm sorry I am new to Test Complete.

 

Thanks

TestQA1
Occasional Contributor

Re: Accessing SwingObjects using FindAllChildren

I want to add that it's not throwing error, but instead of showing FullName it showing empty list.

AlexKaras
Community Hero

Re: Accessing SwingObjects using FindAllChildren

Hi,

 

 instead of showing FullName it showing empty list.

.FindAllChildren() returns an array of found objects.

In your code (lm.FullName) you are trying to get the value of the .FullName property of the array. As the array does not have FullName property an empty value is returned.

Documentation for .FindAllChildren() method provides an example with the iteration through the resulting array. Check it and I hope that it will help.

 

As an example, modification of your code (JavaScript):

if(lm.length>0){
  Log.Message("length exist");

  for (let i = 0; i < lm.length; i++) // iterate through the array
    Log.Message(lm[i].FullName);
}

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
sonya_m
Community Manager

Re: Accessing SwingObjects using FindAllChildren

Thank you AlexKaras!

 

@TestQA1 Does this help?


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements