Forum Discussion

riponalwasim's avatar
riponalwasim
Occasional Contributor
10 years ago
Solved

How to verify that a new tab is opened in a browser with TestComplete using C#

I am testing a website. In the body of website has a URL. After clicking that URL it should be opened in new tab, not in same window. After clicking the URL link it is opened in new tab. I want to verify that feature by using TestComplete.

 

How to do it?

  • Hi Ripon,

     

    You can count the number of the Page objects before and after clicking the link to open a new page in a new tab. Here is an example:

     

    function test()
    {
      var before = getNumberofPages();
      // Open a new tab
      var after = getNumberofPages();
    }
    
    function getNumberofPages()
    {
      var browser = Sys.Browser("chrome"); 
      var pages = browser.FindAllChildren("ObjectType", "Page", 1);
      pages = (new VBArray(pages)).toArray();
      return pages.length; 
    }

     

2 Replies

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Ripon,

     

    You can count the number of the Page objects before and after clicking the link to open a new page in a new tab. Here is an example:

     

    function test()
    {
      var before = getNumberofPages();
      // Open a new tab
      var after = getNumberofPages();
    }
    
    function getNumberofPages()
    {
      var browser = Sys.Browser("chrome"); 
      var pages = browser.FindAllChildren("ObjectType", "Page", 1);
      pages = (new VBArray(pages)).toArray();
      return pages.length; 
    }

     

    • riponalwasim's avatar
      riponalwasim
      Occasional Contributor

      Many many thanks Tanya Gorbunova. It's really helpful for me.