Forum Discussion

Gabriela's avatar
Gabriela
New Contributor
9 years ago

Problem with closing a browser window

Hello, 

 

Currently, I'm doing automation with TestComplete and Javascript of a web application. I have faced a problem with closing a new browser window (clicking on one button opens link in that new browser window). Tried to map it with Find method and all properties and values, and then used Close() function, but this didn't work (it closes current browser tab, but not this new window). 

Can someone help me with this one?

Thank you in advance!

  • Hi Garbiela,

     

    Try calling the Close method of the page that is inside that browser window. This should automatically close that browser window (assuming there are no other pages in that window).

     

    For example, suppose you have two windows opened:

     

    +-----------------+
    | smartbear.com   |
    |                 |
    +-----------------+
    +-----------------+ | example.com | | | +-----------------+

    To close the window with example.com, you can use:

    // JScript
    Aliases.browser.AliasOfTheExamplePage.Close();
    Sys.Browser().Page("http://example.com/").Close(); 
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Can you screenshot your object browser in TC after the new window opens?  My suspicion is that it's a new process object with a different index so, when you call the "close" method, you need to make sure you're indicating the proper process.  

    • Gabriela's avatar
      Gabriela
      New Contributor

      Thank you for the quick reply, 

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        OK... something is a little odd there.  You're using an "&&" call between two find calls that will return an object and then you are using an "Exists" property off the object.  That just seems a little off to me.  Shouldn't you just have the first half of that and drop the "IE.Find" part? Otherwise, I'm not entirely sure what sort of object you're getting back as "&&" is a boolean operator.