Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How to switch between tabs?

The fastest way to switch between browser tabs is with a keyboard shortcut. On Windows and Linux, press Ctrl + Tab to move to the next tab and Ctrl + Shift + Tab for the previous one. On macOS, press Cmd + Option + Right Arrow or Left Arrow (or Control + Tab / Control + Shift + Tab). You can also jump straight to a numbered tab with Ctrl + 1–8 or Cmd + 1–8, with 9 reserved for the last tab. In test automation, you switch between tabs in Selenium using window handles: getWindowHandles() plus switchTo().window(handle).

Here is a quick reference for the most common tab-switching shortcuts side by side:

ActionWindows / LinuxmacOS
Next tabCtrl + TabCmd + Option + Right Arrow (or Control + Tab)
Previous tabCtrl + Shift + TabCmd + Option + Left Arrow (or Control + Shift + Tab)
Jump to tab 1–8Ctrl + 1 … Ctrl + 8Cmd + 1 … Cmd + 8
Jump to last tabCtrl + 9Cmd + 9
New tabCtrl + TCmd + T
Tab SearchCtrl + Shift + ACmd + Shift + A

How to switch between tabs on Windows and Linux

On Windows and Linux the tab-cycling shortcuts are identical across Chrome, Edge, and Firefox. Memorize these and you rarely need the mouse again:

  • Next tab: press Ctrl + Tab to move one tab to the right. Ctrl + Page Down does the same thing and is handy on keyboards where Tab is awkward to reach.
  • Previous tab: press Ctrl + Shift + Tab to move one tab to the left, or use the equivalent Ctrl + Page Up.
  • Jump to a numbered tab: Ctrl + 1 through Ctrl + 8 jumps directly to the first through eighth tab, counting from the left. This is far faster than tabbing through one at a time.
  • Jump to the last tab: Ctrl + 9 always lands on the rightmost tab, regardless of how many you have open.
  • Open and reopen tabs: Ctrl + T opens a new tab and Ctrl + Shift + T reopens the tab you closed last, in reverse order.

How to switch between tabs on Mac (and the Cmd + Tab myth, corrected)

A common piece of misinformation is that Cmd + Tab switches browser tabs on a Mac. It does not. Cmd + Tab is the macOS application switcher: it cycles between open applications (Chrome, Safari, Slack, Mail, and so on), not between the tabs inside a single browser window. Pressing it while in Chrome will flip you to a completely different app, which is exactly the confusion that trips users up.

The correct shortcuts to switch between browser tabs on macOS are:

  • Next tab: Cmd + Option + Right Arrow, or Control + Tab.
  • Previous tab: Cmd + Option + Left Arrow, or Control + Shift + Tab.
  • Jump to a numbered tab: Cmd + 1 through Cmd + 8 for the first eight tabs, and Cmd + 9 for the last tab.
  • New tab and reopen: Cmd + T opens a new tab; Cmd + Shift + T reopens the last closed tab.

In short: use Cmd + Tab to switch apps, and Control + Tab or Cmd + Option + Arrow to switch tabs.

How to switch tabs in Chrome and other browsers

The shortcuts above are not Chrome-specific. Google Chrome, Microsoft Edge, Mozilla Firefox, and Safari all honor the same core combinations, with only minor differences:

  • Chrome and Edge: full support for Ctrl/Cmd + Tab cycling, Ctrl/Cmd + 1–9 jumping, and Tab Search. Edge additionally offers vertical tabs, which stack tabs down the side for easier reading when you have many open.
  • Firefox: uses the same Ctrl/Cmd + Tab and number shortcuts. By default Ctrl + Tab can be set to cycle tabs in most-recently-used order, which you can toggle in Settings.
  • Safari: Control + Tab and Cmd + Option + Arrow switch tabs; Cmd + 1–9 jumps to a specific tab, matching the macOS conventions above.
  • Click to switch: the simplest method of all is clicking the tab you want. When tabs overflow the bar, scroll the tab strip or use Tab Search to find one by title.

Other ways to find and switch tabs (Tab Search and more)

When you have so many tabs open that the titles are no longer readable, cycling one at a time is slow. These features help you locate the right tab directly:

  • Tab Search: press Ctrl + Shift + A on Windows and Linux, or Cmd + Shift + A on Mac, to open a searchable list of every open tab. Type part of a title or URL and jump straight to it. This is the single biggest time-saver for heavy multitabbers.
  • Tab groups: in Chrome and Edge, right-click a tab and add it to a colored, named group. Collapsing a group hides its tabs until you need them, which keeps the strip uncluttered.
  • Vertical tabs: Edge (and Firefox via extensions) can move the tab strip to the side, showing full titles instead of cramped icons.
  • Mouse shortcuts: middle-click a tab to close it, and drag a tab left or right to reorder it. Reordering changes which number shortcut points to which tab.

How to switch between tabs and windows in Selenium

Keyboard shortcuts switch tabs for a human, but automated tests need a programmatic way to move focus. In Selenium, this is done with window handles. A window handle is a unique string ID that Selenium assigns to every browser tab and window. The driver always points at exactly one handle at a time, and any command you issue applies only to that focused tab.

  • getWindowHandle(): returns the handle of the tab the driver is currently focused on.
  • getWindowHandles(): returns a Set of every handle currently open, so you can find the new tab a click just spawned.
  • switchTo().window(handle): moves the driver's focus to the tab identified by that handle.

The typical flow is: save the parent handle, trigger the action that opens a new tab, iterate over all handles to find the one that is not the parent, switch to it, do your work, optionally close it, and switch back to the parent.

import org.openqa.selenium.WebDriver;

// 1. Remember the current (parent) tab before a new one opens
String parentHandle = driver.getWindowHandle();

// 2. A click (or link) opens a new tab - loop through every handle
for (String handle : driver.getWindowHandles()) {
    if (!handle.equals(parentHandle)) {
        driver.switchTo().window(handle);   // switch focus to the new tab
        // ... interact with the page in the new tab ...
        // driver.close();                  // optional: close just this tab
    }
}

// 3. Switch focus back to the original tab
driver.switchTo().window(parentHandle);

The same approach in Python uses current_window_handle, window_handles, and switch_to.window():

# Remember the current (parent) tab
parent_handle = driver.current_window_handle

# Loop through all open tabs/windows and switch to the new one
for handle in driver.window_handles:
    if handle != parent_handle:
        driver.switch_to.window(handle)   # switch focus to the new tab
        # ... interact with the page in the new tab ...
        # driver.close()                  # optional: close just this tab

# Switch focus back to the original tab
driver.switch_to.window(parent_handle)

Selenium 4 added a cleaner way to open a tab without any JavaScript or Robot key-press hacks. switchTo().newWindow(WindowType.TAB) opens a brand-new tab and moves focus to it in a single call (use WindowType.WINDOW for a new window instead):

import org.openqa.selenium.WindowType;

// Save the original tab
String original = driver.getWindowHandle();

// Selenium 4: open AND switch to a brand-new tab in one call
driver.switchTo().newWindow(WindowType.TAB);
driver.get("https://www.lambdatest.com");
// ... work in the new tab ...

// Close the new tab and return to the original
driver.close();
driver.switchTo().window(original);

For window-based pop-ups specifically, see Can Selenium Handle a Windowbased Popup?. For a deeper, end-to-end walkthrough, the Handling Browser Tabs with Selenium guide covers the full lifecycle in detail.

Run multi-tab Selenium tests across real browsers

Multi-tab and multi-window flows can behave differently from one browser or OS to the next, so it is worth validating them on real environments rather than a single local machine. You can run the same window-handle tests across thousands of browser and OS combinations in parallel on the TestMu AI Selenium Automation cloud grid by pointing your RemoteWebDriver at https://hub.lambdatest.com/wd/hub, with no local browser setup to maintain.

Frequently Asked Questions

What is the keyboard shortcut to switch between tabs?

On Windows and Linux, press Ctrl + Tab to move to the next tab and Ctrl + Shift + Tab to move to the previous one. On macOS, use Cmd + Option + Right Arrow and Cmd + Option + Left Arrow, or Control + Tab and Control + Shift + Tab. These combinations work in Chrome, Edge, and Firefox.

Why doesn't Cmd + Tab switch tabs on my Mac?

Because Cmd + Tab is the macOS application switcher. It cycles between open applications such as Chrome, Safari, and Slack, not between the tabs inside a single browser window. To cycle browser tabs on a Mac, use Control + Tab or Cmd + Option + Right/Left Arrow instead.

How do I jump straight to a specific tab?

Press Ctrl + 1 through Ctrl + 8 on Windows and Linux, or Cmd + 1 through Cmd + 8 on Mac, to jump directly to the first through eighth tab counting from the left. Ctrl + 9 (or Cmd + 9) always jumps to the last tab, no matter how many are open.

How do I switch between tabs in Selenium?

Selenium assigns every tab and window a unique string called a window handle. Call getWindowHandle() to read the current tab, getWindowHandles() to get the full set of open tabs, and switchTo().window(handle) to move focus to a different tab.

How do I open a new tab in Selenium 4?

Use driver.switchTo().newWindow(WindowType.TAB), which opens a brand-new tab and moves focus to it in a single call. Pass WindowType.WINDOW to open a new window instead. Earlier Selenium versions needed JavaScript or Robot key presses to achieve the same result.

How do I switch back to the original tab after closing one?

Store the parent tab's handle before a new tab opens. After you finish with the new tab and call close() on it, pass the saved parent handle to switchTo().window() so the driver refocuses the original tab. Always switch back explicitly, because the driver does not refocus automatically when a tab closes.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests