Selenium 4 - New Windows and Tab Utilities

Sauce AI for Test Authoring: Move from intent to executing in minutes.|xBack to ResourcesBlogPosted

January 20, 2026 · 4 min read · Tool Comparison

Sauce AI for Test Authoring: Move from intent to executing in minutes.

|

x

Back to Resources

Blog

Posted October 20, 2021

Selenium 4 - New Windows and Tab Utilities

Selenium 4 includes a new bidding to help users create a new tab or a new window. This clause ply some code examples that evidence how to use it.

quote

It might be necessary to open a new tab or a new window in a given test scenario. Before, it was common to see automation scripts send a combination of keys such as “ Ctrl ” + “ T ” to open a new tab, which usually led to different consequence depending on the browser.

Selenium 4 includes the newnewWindowcommand to help users make a new tab or a new window. After the command is habituate, the focusing will be on the created tab or window. Here are some code illustration prove how to use it. For links to these exemplar in our demo repos, look at our.

1
// Java
2
3
driver.get(& quot; https: //www.selenium.dev/ & quot;);
4
// A new window is opened and switches to it
5
driver.switchTo().newWindow(WindowType.WINDOW);
6
// Loads Sauce Labs exposed beginning website in the freshly open window
7
driver.get(& quot; https: //opensource.saucelabs.com/ & quot;);
8
9
// Python
10
11
driver.get(& # x27; https: //www.selenium.dev/ & # x27;)
12
// A new window is opened and replacement to it
13
driver.switch_to.new_window(& # x27; window & # x27;)
14
// Loads Sauce Labs open source site in the newly opened window
15
driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;)
16
17
// C#
18
19
driver.Navigate().GoToUrl(@& quot; https: //selenium.dev & quot;);
20
// A new window is opened and transposition to it
21
driver.SwitchTo().NewWindow(WindowType.Window);
22
// Loads Sauce Labs unfastened source website in the new opened window
23
driver.Navigate().GoToUrl(@& quot; https: //opensource.saucelabs.com/ & quot;);
24
25
// Ruby
26
27
driver.get& # x27; https: //selenium.dev & # x27;
28
// A new window is opened and switches to it
29
driver.manage.new_window(:window)
30
// Loads Sauce Labs open source site in the fresh opened window
31
driver.get& # x27; https: //opensource.saucelabs.com/ & # x27;
32
33
// JavaScript
34
35
await driver.get(& # x27; https: //selenium.dev & # x27;);
36
// A new window is opened and switches to it
37
await driver.switchTo().newWindow(& # x27; window & # x27;);
38
// Loads Sauce Labs exposed source site in the newly opened window
39
await driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;);

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Open a New Tab

1
// Java
2
3
driver.get(& quot; https: //www.selenium.dev/ & quot;);
4
// A new tab is open and switches to it
5
driver.switchTo().newWindow(WindowType.TAB);
6
// Loads Sauce Labs open beginning website in the new opened window
7
driver.get(& quot; https: //opensource.saucelabs.com/ & quot;);
8
9
// Python
10
11
driver.get(& # x27; https: //www.selenium.dev/ & # x27;)
12
// A new tab is opened and substitution to it
13
driver.switch_to.new_window(& # x27; tab & # x27;)
14
// Loads Sauce Labs unfastened source website in the newly opened window
15
driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;)
16
17
// C#
18
19
driver.Navigate().GoToUrl(@& quot; https: //selenium.dev & quot;);
20
// A new tab is open and switches to it
21
driver.SwitchTo().NewWindow(WindowType.Tab);
22
// Loads Sauce Labs open rootage website in the newly opened window
23
driver.Navigate().GoToUrl(@& quot; https: //opensource.saucelabs.com/ & quot;);
24
25
// Ruby
26
27
driver.get& # x27; https: //selenium.dev & # x27;
28
// A new tab is opened and switches to it
29
driver.manage.new_window(:tab)
30
// Loads Sauce Labs exposed source website in the freshly opened window
31
driver.get& # x27; https: //opensource.saucelabs.com/ & # x27;
32
33
// JavaScript
34
35
await driver.get(& # x27; https: //selenium.dev & # x27;);
36
// A new tab is opened and switch to it
37
await driver.switchTo().newWindow(& # x27; tab & # x27;);
38
// Loads Sauce Labs unfastened beginning website in the new opened window
39
await driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;);
40

Check out our comprehensive guide to for more info.

Titus Fortner

Sr. Developer Experience Engineer, Sauce Labs

Diego Molina

Staff Software Engineer at Sauce Labs

Published:
Oct 20, 2021
Share this post
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.
robot
quote

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free