How do i open a new tab in the same window?

I’m testing a web application that requires me to add a new tab in the same window and open a new url. For an example, i have google.com opened in 1 tab and need to open second tab ktalon.com. How do i achieve that? Please help.

2 Likes

The below links lists several ways to open a new tab while you already have an open tab.

[WebUI] How can I open a new Tab on Chrome? - Product Forums / Katalon Studio - Katalon Community

1 Like

You can try this one too: How to open multiple Chrome browser tabs using Incognito

Achieve doing following

I think i figured out how to resolve this issue please see my example below and the TRICK i found out.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor

// Open the first website in a new tab
WebUI.openBrowser(‘’)

// Go to the first Site on TAB 1
WebUI.navigateToUrl(‘https://www.google.com’)

// Open the next TAB
WebUI.executeJavaScript(“window.open();”, )

// Defining the Window Index
currentWindow = WebUI.getWindowIndex()

// Switch to TAB or Window 1 - Current
WebUI.switchToWindowIndex(currentWindow)

// Switch to TAB or Window 2
WebUI.switchToWindowIndex(currentWindow + 1)

// Navigate to TAB or Window 2 Site
WebUI.navigateToUrl(‘https://www.att.com’)

// This is the Trick to make it work… DO IT AGAIN! This will open the URL
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.navigateToUrl(‘https://www.att.com’)

// Now switch to whatever TAB or Window you want…
WebUI.switchToWindowIndex(currentWindow)

// DO SOME ACTION ON THE CURRENT WINDOW
WebDriver driver = DriverFactory.getWebDriver()
‘To locate Search Bar’
WebElement GoogleSearchBar = driver.findElement(By.xpath(‘//*[@id=“APjFqb”]’))
‘To locate Search Button’
WebElement GoogleSearchButton = driver.findElement(By.xpath(“/html/body/div[1]/div[3]/form/div[1]/div[1]/div[4]/center/input[1]”))

// Perform actions on the Google page
GoogleSearchBar.sendKeys(‘Katalon Studio’)
GoogleSearchButton.click()

// TO OPEN ANOTHER TAB or WINDOW… TRICK IS DO IT TWICE!
WebUI.executeJavaScript(“window.open();”, )
WebUI.switchToWindowIndex(currentWindow + 2)
WebUI.navigateToUrl(‘https://www.apple.com’)
WebUI.switchToWindowIndex(currentWindow + 2)
WebUI.navigateToUrl(‘https://www.apple.com’)

// NOW EXERCISE SWITCHING TO OTHER TABS
WebUI.switchToWindowIndex(currentWindow + 1)
WebUI.switchToWindowIndex(currentWindow)

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team