Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

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:
| Action | Windows / Linux | macOS |
|---|---|---|
| Next tab | Ctrl + Tab | Cmd + Option + Right Arrow (or Control + Tab) |
| Previous tab | Ctrl + Shift + Tab | Cmd + Option + Left Arrow (or Control + Shift + Tab) |
| Jump to tab 1–8 | Ctrl + 1 … Ctrl + 8 | Cmd + 1 … Cmd + 8 |
| Jump to last tab | Ctrl + 9 | Cmd + 9 |
| New tab | Ctrl + T | Cmd + T |
| Tab Search | Ctrl + Shift + A | Cmd + Shift + A |
On Windows and Linux the tab-cycling shortcuts are identical across Chrome, Edge, and Firefox. Memorize these and you rarely need the mouse again:
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:
In short: use Cmd + Tab to switch apps, and Control + Tab or Cmd + Option + Arrow to switch tabs.
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:
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:
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.
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.
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.
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.
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.
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.
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.
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.
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.
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