Forum Discussion

ḥari's avatar
ḥari
Frequent Contributor
2 years ago

new tab

Hello team,

 

How to open a link in new tab. I want to open the product documentation in new tab.

 

I have tried through testedobj.keys (cntrl+t) it opens only a new tab. 

Also tried rightclick that link 

 

Let me know

 

 

  • Maybe you could use middle mouse button?

    when browsing normally I always use mmb to open links in a new tab so TC should be able to do that too.

     

     

    EDIT: I just tested it with chrome and TC does open new tabs, but those tabs are not focussed.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    For example,

     

    function newtab()
    {
        var browser = Sys.Browser("chrome");
        browser.Page("*").Keys("^t");
        var page = browser.ToUrl("https://support.smartbear.com/testcomplete/");
    }

     

    You need to give instructions to TC, as to what URL you want to load

    • ḥari's avatar
      ḥari
      Frequent Contributor

      Hi rrahvani,

      without giving URL is it possible to open in newtab in any other ways.

       

       

  • KB1's avatar
    KB1
    Champion Level 2

     

    There are a few different ways to open a link in a new tab the way rraghvagni explained is the way that I also use. but depending on the programming language and framework you are using. In TestComplete, you can open a link in a new tab using the following method:

     

    Alternatively, you can use the .click() method on the link element and set the 'ctrl' property to true:

     

     

    link.Object.click(1, 1, {ctrl: true});

    You can also use the right-click context menu option to open a link in a new tab, by simulating a right-click on the link element and selecting the "Open Link in New Tab" option.

    Example:

     

     
    link.Object.rightClick()
    Aliases.browser.popupMenu("Open Link in New Tab").click()

    You can also use the JavaScript inbuilt function window.open("link","_blank") to open the link in new tab.

    Example:

     
    link.Object.eval("window.open(this.href,'_blank');")

    Please note that you need to be careful while using the above JavaScript functions as they may be blocked by the browser.

  • MW_Didata's avatar
    MW_Didata
    Regular Contributor

    Maybe you could use middle mouse button?

    when browsing normally I always use mmb to open links in a new tab so TC should be able to do that too.

     

     

    EDIT: I just tested it with chrome and TC does open new tabs, but those tabs are not focussed.

    • ḥari's avatar
      ḥari
      Frequent Contributor

      MW_Didata Thanks simply it works for my scenario.

      To focus tabs

      Sys.keys("^[Tab]");

      var newTab=Sys.Browser("chrome").Page("*")

       

       

       

       

    • KB1's avatar
      KB1
      Champion Level 2

      Sometimes it's the easiest fixes haha

      • ḥari's avatar
        ḥari
        Frequent Contributor

        OfCourse KB1 sometimes easiest fixes needs lots of research.

         

        Anyway, thanks for all the replies.

    • ḥari's avatar
      ḥari
      Frequent Contributor

      Manually i will right click and click open new tab it's right clicked but not hit the open new tab so only asked if any other ways. Any way thanks..

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    See Click Action

     

    Using TestObj.Click(1, 1, skCtrl) will open the link in a new tab, whereas TestObj.Click(1, 1, skShift) will open the link in a new window.