Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

How To Open Duplicate Tab In Chrome Browser – Selenium WebDriver

Posted on 02/19/2025 By admin

Have you used “Duplicate a tab in browser” feature? Do not worry if it is something new to you, let me start from basics.

You love shopping online on an E-Commerce site. Suppose you have navigated as Dresses – > Men -> Formal -> Bottoms -> Top Rated and so on. Now you need to go to different section from “Bottoms” and you need currently loaded section as well. We have three options to do so :-

  1. Start from beginning in a new tab. – You will create new browsing history and takes time.
  2. Copy current URL and open in a new tab – New tab looses browsing history.
  3. Duplicate current tab – Duplicated tab retains Browsing history.

So duplicating a tab is better option.

Every browser provides an option to duplicate a tab in a browser. If you take example of Chrome browse then you just need to right click on tab which you want to duplicate and select “Duplicate” option as shown below:-

Note :- I have launched Facebook, Google then Flipkart’s URL to generate browsing history. You can open any URL.

Once you click on Duplicate option, a duplicate tab opens with history.

Please note Back and Forward arrow are enabled which means that there are browsing history.

There is a shortcut key ALT+D+ENTER to duplicate tab but it does not retain history. It is similar to second option discussed above.

If we want to open a duplicate tab with browsing history then we need to install a chrome extension “Duplicate tab shortcut“.

Either you can search and add this extension in Chrome Web Store or directly open this URL.

When you add above extension to chrome then you see a icon at top right corner as in above image. Now you got a new shortcut key as ALT+SHIFT+D in Windows and OPTION+SHIFT+D in Mac to duplicate a tab with browsing history. Try it.

We may need to duplicate a tab in automated scripts. For an example :- You need to do some setup at Settings page. To navigate to setting page flow is as Home Page -> Login -> Dashboard -> Profile -> Settings. Now you need to go back to Home page then come back to Setting page again.

If you do exactly what same steps described above then it will take more execution time. But if you duplicate tab when you are done setup at setting page then it will save execution time and extra navigation. Switch to duplicated tab and there you can go to home page and do required setup there. Now switch to first tab and continue from Settings page.

You must have faced many scenarios where you may need to duplicate a tab during manual testing. It is also helpful in maintaining session. Let’s learn how can we achieve duplicate tab functionality in Chrome using Selenium WebDriver.

We know by default Selenium WebDriver launches a fresh browser i.e without any extensions and plugins. We use ChromeOptions class to add an extension in Chrome browser. ChromeOptions class provides a method addExtensions which accepts a File input which is basically extension file depending on browser. A file with .crx extension is a Chrome Extension file used to extend the functionality of the Google Chrome web browser.

The easiest way to download a CRX file of any chrome extension is using Get CRX chrome extension. Add it to your chrome browser and you will see a icon at top right corner of browser.

Now open Duplicate Tab Shortcut extension URL and select option as shown below:-

It will download a .crx file for Duplicate Tab Shortcut extension.

Downloaded CRX file path we need to pass in ChromeOptions. Let’s see a complete program below :-

package SpecialConcepts;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.time.Duration;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;

import io.github.bonigarcia.wdm.WebDriverManager;

public class DuplicateTabWithHistory {
        
        @Test
        public void doActions() throws AWTException, InterruptedException {
                // Setup browser
                WebDriverManager.chromedriver().setup();
                // Adding .crx file
                ChromeOptions chromeOptions = new ChromeOptions();
                String fileURL = System.getProperty("user.dir");
                chromeOptions.addExtensions(new File(fileURL + "/src/test/resources/extensions/Duplicate Tab Shortcut.crx"));
                WebDriver driver = new ChromeDriver(chromeOptions);
                
                // Loading some URLs
                driver.get("http://automationpractice.com/index.php?controller=authentication&back=my-account");
                driver.get("http://google.com/");
                driver.get("http://facebook.com/");
                
                // One Way 
                /*
                 * Actions action_chains = new Actions(driver);
                 * action_chains.keyDown(Keys.ALT).keyDown(Keys.SHIFT).sendKeys("d").build().
                 * perform(); action_chains.keyUp(Keys.ALT).keyUp(Keys.SHIFT).build().perform();
                 */
                
                // Another way - Press ALT + SHIFT + D
                Robot r = new Robot();
                r.keyPress(KeyEvent.VK_ALT);
                r.keyPress(KeyEvent.VK_SHIFT);
                r.keyPress(KeyEvent.VK_D);
                r.keyRelease(KeyEvent.VK_D);
                r.keyRelease(KeyEvent.VK_SHIFT);
                r.keyRelease(KeyEvent.VK_ALT);
                
                // Wait till another duplicate is opened 
                new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.numberOfWindowsToBe(2));
                
                // Let's Switch to new tab and navigate back and forward
                driver.switchTo().window(driver.getWindowHandles().stream().skip(1).findFirst().get());
                
                // Verifying history is retained
                driver.navigate().back();
                new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.titleIs("Google"));
                System.out.println("Title is : "+ driver.getTitle());
                driver.navigate().back();
                new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.titleIs("Login - My Store"));
                System.out.println("Title is : "+ driver.getTitle());
                
                // Loading a new URL
                driver.get("http://www.makeseleniumeasy.com");
                System.out.println("Title is : "+ driver.getTitle());
                
                driver.quit();
                                
        }

}

Output :-

Title is : Google
Title is : Login - My Store
Title is : Make Selenium Easy

You can download/clone above sample project from here.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: Compare Two Excel Workbooks Using Apache POI
Next Post: TestNG Tutorials 38: How to Execute Groups in TestNG without Using TestNG XML

Related Posts

REST Assured Tutorial 26 – How To Use Java Object As Payload For API Request Uncategorized
November 10, 2018 – Make Selenium Easy Uncategorized
July 2018 – Page 2 – Make Selenium Easy Uncategorized
image – Make Selenium Easy Uncategorized
Frequently Asked Java Program 02: Java Program to Check if Any String is Palindrome Without Using Reverse Method Uncategorized
REST Assured Tutorial 67 – How to assert full response JSON body in Rest Assured? Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark