# \[WebUI\] How can I open a new Tab on Chrome?

**URL:** <https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [May 23, 2017, 11:53am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969 "2017-05-23T11:53:15Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Rodrigues](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Joel\_Rodrigues](https://forum.katalon.com/u/Joel_Rodrigues)\
**Post date:** [May 23, 2017, 11:53am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/1 "2017-05-23T11:53:15Z")

</div>

So, I’ve been searching and all I found about this was the this \<a href=“[http://forum.katalon.com/questions/how-to-open-a-new-chromes-tab-a-detail-example-would-be-much-appreciated/](http://forum.katalon.com/questions/how-to-open-a-new-chromes-tab-a-detail-example-would-be-much-appreciated/)”\>page\</a\>, but even this one inserted completely into a test, word for word, did not work for me, so I would apretiate if someone could give me the help I need, and explain to me can I open a new Tab on Google Chrome.

* * *

Thank you very much for your help

---

<div class="post-metadata">

**Author:** ![Joel\_Rodrigues](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Joel\_Rodrigues](https://forum.katalon.com/u/Joel_Rodrigues)\
**Post date:** [May 24, 2017, 10:12am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/2 "2017-05-24T10:12:05Z")

</div>

There are a few downsides such as the clear of any forms inserted by the user when you open a new page.

---

<div class="post-metadata">

**Author:** ![Joel\_Rodrigues](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Joel\_Rodrigues](https://forum.katalon.com/u/Joel_Rodrigues)\
**Post date:** [May 24, 2017, 10:09am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/3 "2017-05-24T10:09:25Z")

</div>

Thanks, but I actually found a way around this, some hyperlinks automatically open in a new tab as such I used one of these links on the [MediaWiki](https://www.mediawiki.org/wiki/MediaWiki) website and then I created this method:

`WebUI.openBrowser('google.com')`  
`openTab()`

`import com.kms.katalon.core.testobject.ConditionType as ConditionType`  
`//import org.openqa.selenium.Keys as Keys`  
`Void openTab() {`

`String currentPage = WebUI.getUrl()`

`int currentTab = WebUI.getWindowIndex()`

`WebUI.navigateToUrl('https://www.mediawiki.org/wiki/Special:Contributions/')`

`TestObject helpButton = new TestObject('Help')`

`helpButton.addProperty('class', ConditionType.EQUALS, 'mw-helplink', true)`

`helpButton.addProperty('text', ConditionType.EQUALS, 'Help', true)`

`helpButton.addProperty('tag', ConditionType.EQUALS, 'a', true)`

`WebUI.click(helpButton)`

`WebUI.switchToWindowIndex(currentTab+1)`

`WebUI.navigateToUrl(currentPage)`

`/*TestObject body = new TestObject('body')`

`body.addProperty('tag', ConditionType.EQUALS, 'body')`

`WebUI.sendKeys(body, Keys.chord(Keys.CONTROL + Keys.SHIFT + Keys.TAB))*/`

`WebUI.switchToWindowIndex(currentTab)`

`WebUI.navigateToUrl(currentPage)`

`WebUI.switchToWindowIndex(currentTab+1)`  
`}`

The only problem I have with it is that I can’t actually do the switching of the tabs as I intended, you can see the commented code in there that is my attempt at making the switch, it did not work, can you help me out with that?

---

<div class="post-metadata">

**Author:** ![Hari\_Charan](https://avatars.discourse-cdn.com/v4/letter/h/a88e57/32.png) [@Hari\_Charan](https://forum.katalon.com/u/Hari_Charan)\
**Post date:** [May 23, 2017, 12:31pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/4 "2017-05-23T12:31:03Z")

</div>

I think you can achieve this using  
1. Open Chrome Browser  
2. Send keys (CTRL, SHIFT, ‘N’)  
3. Switch to window

I think this should help. Use script tab to code or manual mode with built keywords

---

<div class="post-metadata">

**Author:** ![alex](https://avatars.discourse-cdn.com/v4/letter/a/db5fbb/32.png) [@alex](https://forum.katalon.com/u/alex)\
**Post date:** [October 4, 2017, 3:57pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/5 "2017-10-04T15:57:31Z")

</div>

Dear Hari  
I had tried this option, but not able to open window or tab.  
Did you try the steps you mentioned?

> I think you can achieve this using
> 
> 1. Open Chrome Browser
> 2. Send keys (CTRL, SHIFT, ‘N’)
> 3. Switch to window

Did it work?

Dear Joel Rodrigues  
Did you find any other solution for this?

Regards  
Alex  
Happy Automating 🙂

---

<div class="post-metadata">

**Author:** ![Deepthi](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@Deepthi](https://forum.katalon.com/u/Deepthi)\
**Post date:** [October 4, 2017, 7:11pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/6 "2017-10-04T19:11:37Z")

</div>

You can use Javascript to do this. Below is the sample code hope it helps!!

```
import org.openqa.selenium.JavascriptExecutor
import com.kms.katalon.core.webui.driver.DriverFactory

WebUI.openBrowser('https://www.google.com/')

WebDriver driver = DriverFactory.getWebDriver()

JavascriptExecutor js = ((driver) as JavascriptExecutor)

js.executeScript("window.open();")
    
WebUI.closeBrowser()
```

---

<div class="post-metadata">

**Author:** ![Dhaval\_Kriplani](https://avatars.discourse-cdn.com/v4/letter/d/839c29/32.png) [@Dhaval\_Kriplani](https://forum.katalon.com/u/Dhaval_Kriplani)\
**Post date:** [October 16, 2017, 7:42am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/7 "2017-10-16T07:42:38Z")

</div>

Inspired from both Joel’s and Deepthi’s answer, I’ve created a test case where it opens a new tab and navigates to link provided from the current browser tab.

According to me, you should create a new test case where, whenever you want to open a url in another tab, you just have to call the test case.

Call the test case as:  
`WebUI.callTestCase(findTestCase('Utils/Open_New_Tab'), [path:Link])`  
where Link is a url stored as a string.

Here, “path” is the url you want to visit. Create a variable (in ‘Utils/Open\_New\_Tab’ test case) named “path” (in the variables Tab in Katalon) as a String and keep it null. This test case will open the link in new tab and bring focus to the original tab.

Here’s the test case I created,

```
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

String currentPage = WebUI.getUrl()

int currentTab = WebUI.getWindowIndex()

WebDriver driver = DriverFactory.getWebDriver()

JavascriptExecutor js = ((driver) as JavascriptExecutor)

js.executeScript('window.open();')

WebUI.switchToWindowIndex(currentTab + 1)

WebUI.navigateToUrl(currentPage)

WebUI.navigateToUrl(path)

WebUI.switchToWindowIndex(currentTab)

WebUI.navigateToUrl(currentPage)

```

PS: If you only want to open a new tab, remove  
`WebUI.navigateToUrl(path)`  
from the above code.

Hope it helps.😄

---

<div class="post-metadata">

**Author:** ![Joel\_Rodrigues](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Joel\_Rodrigues](https://forum.katalon.com/u/Joel_Rodrigues)\
**Post date:** [May 24, 2017, 5:54pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/8 "2017-05-24T17:54:56Z")

</div>

That’s amazing, thank you

---

<div class="post-metadata">

**Author:** ![Zarashima](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/zarashima/32/928_2.png) [@Zarashima](https://forum.katalon.com/u/Zarashima)\
**Post date:** [May 23, 2017, 3:11pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/9 "2017-05-23T15:11:36Z")

</div>

Hi there,

Please try with below code:

`import java.awt.Robot`  
`import java.awt.event.KeyEvent`

`import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI`

`WebUI.openBrowser("www.google.com")`  
`Robot robot = new Robot()`  
`robot.keyPress(KeyEvent.VK_CONTROL)`  
`robot.keyPress(KeyEvent.VK_T)`  
`robot.keyRelease(KeyEvent.VK_CONTROL)`  
`robot.keyRelease(KeyEvent.VK_T)`

It uses RobotFramework to simulate pressing Ctrl + T hotkeys for opening a new tab in Chrome

---

<div class="post-metadata">

**Author:** ![alok](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@alok](https://forum.katalon.com/u/alok)\
**Post date:** [February 12, 2018, 12:43pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/10 "2018-02-12T12:43:58Z")

</div>

you can find detailed info on this :

[http://helping-eachothers.blogspot.in/2018/02/how-to-move-to-new-tab-in-chrome-using.html#more](http://helping-eachothers.blogspot.in/2018/02/how-to-move-to-new-tab-in-chrome-using.html#more)

---

<div class="post-metadata">

**Author:** ![Rajitha\_Kithuldeniya](https://avatars.discourse-cdn.com/v4/letter/r/9de0a6/32.png) [@Rajitha\_Kithuldeniya](https://forum.katalon.com/u/Rajitha_Kithuldeniya)\
**Post date:** [March 13, 2018, 7:04pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/11 "2018-03-13T19:04:45Z")

</div>

It is easy with WebUI.executeJavaScript()

```auto
WebUI.openBrowser('https://www.katalon.com/')
WebUI.executeJavaScript('window.open();', [])
currentWindow = WebUI.getWindowIndex()
//Go in to new tab
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.navigateToUrl('https://www.google.lk')
//Comming back
WebUI.switchToWindowIndex(currentWindow)

```

---

<div class="post-metadata">

**Author:** ![bhupendra\_Patidar](https://avatars.discourse-cdn.com/v4/letter/b/e56c9b/32.png) [@bhupendra\_Patidar](https://forum.katalon.com/u/bhupendra_Patidar)\
**Post date:** [March 28, 2018, 11:33am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/12 "2018-03-28T11:33:59Z")

</div>

Really easy with Javascript

WebUI.openBrowser(’’)

WebUI.executeJavaScript(‘window.open();’, [])

---

<div class="post-metadata">

**Author:** ![Jambunath](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Jambunath](https://forum.katalon.com/u/Jambunath)\
**Post date:** [June 12, 2018, 5:02am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/13 "2018-06-12T05:02:35Z")

</div>

> [alok](https://forum.katalon.com/profile/1657/alok) said:
> 
> you can find detailed info on this :
> 
> [Alok Srivastav](http://helping-eachothers.blogspot.in/2018/02/how-to-move-to-new-tab-in-chrome-using.html#more)

It is very helpful. great work.

---

<div class="post-metadata">

**Author:** ![Magyar\_Zoltan](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@Magyar\_Zoltan](https://forum.katalon.com/u/Magyar_Zoltan)\
**Post date:** [June 13, 2018, 2:22pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/14 "2018-06-13T14:22:20Z")

</div>

Can you open a new window in incognito mode with JS?

---

<div class="post-metadata">

**Author:** ![ayesha.khanam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ayesha.khanam/32/16104_2.png) [@ayesha.khanam](https://forum.katalon.com/u/ayesha.khanam)\
**Post date:** [June 17, 2020, 7:07pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/15 "2020-06-17T19:07:24Z")

</div>

@Rajitha_Kithuldeniya

What do I do if I want to switch contentiously from Tab1 to Tab 2 and Tab2 to Tab1 and so onn  
Ex:  
// TAB1  
WebUI.openBrowser(‘[https://www.katalon.com/](https://www.katalon.com/)’)  
WebUI.executeJavaScript(‘window.open();’, [])  
currentWindow = WebUI.getWindowIndex()  
//Go in to new tab TAB2  
WebUI.switchToWindowIndex(currentWindow + 1)  
WebUI.navigateToUrl(‘[https://www.google.lk](https://www.google.lk)’)

//Comming back TAB1 Does not work for me  
WebUI.switchToWindowIndex(currentWindow)

---

<div class="post-metadata">

**Author:** ![Vitallica](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/vitallica/32/16104_2.png) [@Vitallica](https://forum.katalon.com/u/Vitallica)\
**Post date:** [September 15, 2020, 10:02am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/16 "2020-09-15T10:02:38Z")

</div>

Did anybody try to run the WebUI.switchToWindowIndex(1) on FireFox with the latest Katalon version?  
It used to work okay, but now it doesn’t.

---

<div class="post-metadata">

**Author:** ![dietrich](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dietrich/32/4771_2.png) [@dietrich](https://forum.katalon.com/u/dietrich)\
**Post date:** [September 30, 2020, 10:25am UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/17 "2020-09-30T10:25:50Z")

</div>

Try to do it via JavaScript instead of WebUI:  
Your imports:

> import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor  
> import org.openqa.selenium.WebDriver as WebDriver  
> Your code:  
> WebDriver driver = DriverFactory.getWebDriver()  
> JavascriptExecutor js = ((driver) as JavascriptExecutor)  
> js.executeScript(‘window.open();’)

---

<div class="post-metadata">

**Author:** ![ionut.motofei](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/ionut.motofei/32/16104_2.png) [@ionut.motofei](https://forum.katalon.com/u/ionut.motofei)\
**Post date:** [April 15, 2022, 6:54pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/18 "2022-04-15T18:54:02Z")

</div>

Thank you, this worked for my needs

---

<div class="post-metadata">

**Author:** ![halen04k](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/halen04k/32/22831_2.png) [@halen04k](https://forum.katalon.com/u/halen04k)\
**Post date:** [May 1, 2023, 12:37pm UTC](https://forum.katalon.com/t/webui-how-can-i-open-a-new-tab-on-chrome/5969/19 "2023-05-01T12:37:44Z")

</div>

I have fixed my problem by changing the settings in search [page](https://thegeekpage.com/chrome-opening-new-links-in-new-tab/).
