cancel
Showing results for 
Search instead for 
Did you mean: 

How can I stay on the popup window and perform actions?

SOLVED
Highlighted
Frequent Contributor

How can I stay on the popup window and perform actions?

Hello,

 

I have a test that will trigger a popup window, and I need to enter some data on the popup, I used the SetFocus to try to stay on the popup, but when TC run the codes after the setfocus, it switches the window to previous one (main window). Can someone please tell me how can I stay on the popup and perform actions? Thank you!

 

Here are my codes:

sys.Browser("chrome").BrowserWindow(1).SetFocus()
Call EnterText("User","Frank")

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: How can I stay on the popup window and perform actions?

OK, first of all...  why no NameMapping?  Honestly, that's going to be the BEST way to identify objects and make sure they are distinct.  You are using a wildcard for the page which will find ANY page, literally the FIRST page it finds will be returned.  If your popup is a second page in the Browser, then there's no guarentee that your code will find it.  AT LEAST you need to be specific in the page.  

So, your popup comes up... I still don't know EXACTLY what that popup is, but your code below will find the first textbox with the label indicated in whatever page is returned.   By the description of your behavior, probably the first page it returns is NOT the page containing your popup, so that's why it activates the page instead of the popup.

 

So:

 

1) Consider mapping all your components rather than relying on find methods solely... use Find when mapping doesn't make sense

2) Be more specific with all aspects of your object identification, even the page URL

 


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

View solution in original post

7 REPLIES 7
Community Hero

Re: How can I stay on the popup window and perform actions?

What's in "EnterText"?  That's a non-native function to TestComplete, obviously custom.  WE can't help debug that without knowing the code.

Just off your description of the behavior, though.  TestComplete automatically sets focus to the object that you interact with.  So, it sounds like, after you set focus to the BrowserWindow, the next step (somewhere inside EnterText) is interacting with some other object.  

On another note, "BrowserWindow" is the Desktop Application portion of your internet browser, it's not the web page that you're working with.  If the pop-up is a component on the web page, then you need to make sure that you call the "SetFocus" on that component, not on the BrowserWindow object.


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: How can I stay on the popup window and perform actions?

Hi @tristaanogre , yes EnterText is a custom reusable action, what it does is look for the textfield on a page that matches with text field name I give to it, and then enter data into the field. Below are the codes for the action.

 

Public Sub EnterText(TextFieldName,TextConent)


PropArray = Array("ObjectType","ObjectLabel","ChildCount")
ValueArray = Array("Textbox",TextFieldName,"0")
Set TextField = Sys.Browser("*").Page("*").Find(PropArray,ValueArray,30)
If TextField.Exists Then
TextField.SetText (TextConent)
Call Log.Message("'"&TextConent&"' is successfully entered in "&TextFieldName&" field.")
Else
Call Log.Error(TextFieldName&" is NOT found on the page!",,,,Sys.Browser("*").Page("*").PagePicture)
End If
End Sub

Community Hero

Re: How can I stay on the popup window and perform actions?

OK, first of all...  why no NameMapping?  Honestly, that's going to be the BEST way to identify objects and make sure they are distinct.  You are using a wildcard for the page which will find ANY page, literally the FIRST page it finds will be returned.  If your popup is a second page in the Browser, then there's no guarentee that your code will find it.  AT LEAST you need to be specific in the page.  

So, your popup comes up... I still don't know EXACTLY what that popup is, but your code below will find the first textbox with the label indicated in whatever page is returned.   By the description of your behavior, probably the first page it returns is NOT the page containing your popup, so that's why it activates the page instead of the popup.

 

So:

 

1) Consider mapping all your components rather than relying on find methods solely... use Find when mapping doesn't make sense

2) Be more specific with all aspects of your object identification, even the page URL

 


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

View solution in original post

Frequent Contributor

Re: How can I stay on the popup window and perform actions?

The reason why I don't namemap it is because it is a very common field, almost 90% of the pages have text field for data input, I cannot namemap every single one, that will be huge amount of work. So I have this reusable action that finds the text field that I am looking for and enter the data I specified. Below are the screenshot of the popup and the objects in tree view.

Capture.JPGCapture2.JPG

Community Hero

Re: How can I stay on the popup window and perform actions?

Actually, yes you CAN name map every TextField... that's actually the point of it... to make sure that you have an object repository clearly and accurately identifying each object.

In the example of your screenshot, you actually have two pages...  So, if you look at your object browser, you'll see your Chrome object actually has two page objects... so, your reusable code cannot discern WHICH page to look at.... so, you need to AT LEAST specify the page... you can't just wild card it.

So... what I would do, is map the popup as it's own page in NameMapping... it IS a unique page with unique objects.  This is the whole purpose of NameMapping... yes, it's a lot of work up front, but it saves you headaches the rest of the way through your project by providing an accurate, robust, and efficient means of identifying the objects.


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
Community Hero

Re: How can I stay on the popup window and perform actions?

As for the reusable to be universally useful for any textbox, what I would do is actually pass the textbox object (Aliases.<page>.<textbox>) as a parameter to your reusable.  You don't have to FIND the text box... you already know it's there.  Hence, the NameMapping.


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: How can I stay on the popup window and perform actions?

Thanks @tristaanogre I used the namemaping and it is working now