Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago
Solved

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")

  • 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

     

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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.

    • whuang's avatar
      whuang
      Regular Contributor

      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

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        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