Switch Tabs

You can use the I.switchTab command to switch to another tab.

Automatic switch to new tabs

Note that whenever any command (e.g. I.click) opens a new tab, UIlicious will automatically switch to the newly opened tab. You generally don't need to explicitly use I.switchTab to switch to a new tab, unless you want to go to a previously opened tab.

Switch to the next tab

The I.switchTab command switches the active tab to the next tab. If the current active tab is the last tab in the browser window, this will switch to the first tab instead.

// First, go to google.com
I.goTo("https://google.com")

// Then, open a new tab, and go to wikipedia.com
// The test browser will automatically switch to the new tab.
I.goTo("https://wikipedia.com", {newTab: true})

// Now, switch to the next tab.
// Since the current tab is last tab, this will go to the first tab, which has google.com opened
I.switchTab()

Switch using page title or tab number

You can switch to the specific tab by using the I.switchTab command with the title of the page or number of the tab to switch to.

// First, go to google.com.
I.goTo("https://google.com") 

// Then, open a new tab, and go to wikipedia.com.
// The test browser will automatically switch to the new tab.
I.goTo("https://wikipedia.com", {newTab: true})

// Switch to the first tab, which has google.com opened
I.switchTab(1)

// Switch to the second tab, which as the page title "Wikipedia"
I.switchTab("Wikipedia")

Close tabs when they are not needed

When you no longer need to use a tab, we recommend using the I.closeTab() command instead of the I.switchTab() command, because having more tabs open will slow down the overall test execution.

Reference

Usage

I.switchTab() // switch to the next tab
I.switchTab(tab) // switch to a specific tab by tab number or page title

Parameters

ParameterTypeRemarks
tabnumber or string

(Optional)
Tab number or page title to switch to.
If not provided, switch to the next tab.

Last Updated: