Forum Discussion

kevin_kapell's avatar
kevin_kapell
Frequent Contributor
9 years ago

How do I navigate between browser tabs using TestComplete

I have a script (JScript) where I open a second browser tab (currently in Chrome) and do some actions. After completing those actions int he second browser tab I want to navigate back to the first browser tab and do some actions.

I will then want to switch back to the second browser tab.

 

Other possible options is to close the second tab so that I return back to the first tab but not sure howt o do that either.

 

Any information you can provide will be appreciated.

 

Thanks

Kevin

  • Do you have the Page Objects NameMapped or do you know the URLs of the two separate tabs? If so you can just reference each Page object separately and TestComplete will pick the correct tab to perform actions on.

     

    Course that won't work if you have two tabs with the same web page open. If that's the case you can differentiate the two tabs by looking at the ObjectGroupIndex and Visible properties of the Page objects.

      • ghuff2's avatar
        ghuff2
        Contributor

        osaid_ahmad Really? What action are you trying to perform where it's not working?

         

        Say you have a browser open with a tab on google.com and another on yahoo.com with the yahoo.com tab being selected/focused. If you run the following script statement it should perform an action on the google tab without the need to do anything specific to gain control of that tab (specifically it puts text into the search textbox).

         

        Aliases.browser.Page("https://www.google.com/").Panel("viewport").Panel("searchform").Form("tsf").Panel(0).Panel(0).Panel("sbtc").Panel(0).Panel("sfdiv").Panel(0).Panel("sb_ifc0").Panel("gs_lc0").Textbox("lst_ib").SetText('Search for something')
    • kevin_kapell's avatar
      kevin_kapell
      Frequent Contributor

      Thanks ghuff2. However while I have the page objects NamedMapped I have them changed to be generic for direct URLS

       

      *.domainname.com

       

      so it does not appear to work.

       

      Also I am using Chrome so from the article below that will be a problem.

       

      Can you elaborate on using the ObjectGroupIndex and Visible properties of the Page objects? I am new to coding in TestComplete so I am not sure what you are suggesting I do.

      • ghuff2's avatar
        ghuff2
        Contributor

        All objects have properties, the Page object has a Visible property which is a boolean value. If the Page object corresponds to a tab that isn't currently selected the Visible property will be False. So if you want to find the tab that isn't selected you would look for the one that has Visible set to False.

         

        You can view the properties of an object when you highlight it in the Object Browser. Take a look at the ObjectGroupIndex, if you have two Page objects that can't be differentiated in any meaningful way this value will differ between the two Pages.

         

         

         

  • kevin_kapell's avatar
    kevin_kapell
    Frequent Contributor

    Using Ctrl+Shift+Tab through Sys.Keys to navigate between the tabs worked and is the simplest solution.

    Thanks everyone for your help.