Ask a Question

new tab

SOLVED
ḥari
Occasional Contributor

new tab

Hello team,

 

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

Smart.png

 

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

Also tried rightclick that link 

 

Let me know

 

 

11 REPLIES 11
rraghvani
Valued Contributor

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
Occasional Contributor

Hi rrahvani,

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

 

 

KB1
Frequent Contributor

 

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.

rraghvani
Valued Contributor

@ḥari how would you do this manually?

 

Alternative solutions are provided by @KB1 

ḥari
Occasional Contributor

I will check this KB1. Thanks

ḥari
Occasional 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
Valued Contributor

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.

MW_Didata
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
Occasional Contributor

@MW_Didata Thanks simply it works for my scenario.

To focus tabs

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

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

 

 

 

 

cancel
Showing results for 
Search instead for 
Did you mean: