Selenium 4 - New Windows and Tab Utilities
Sauce AI for Test Authoring: Move from intent to executing in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to executing in minutes.
|
x
Blog
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.
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// Java23driver.get(& quot; https: //www.selenium.dev/ & quot;);4// A new window is opened and switches to it5driver.switchTo().newWindow(WindowType.WINDOW);6// Loads Sauce Labs exposed beginning website in the freshly open window7driver.get(& quot; https: //opensource.saucelabs.com/ & quot;);89// Python1011driver.get(& # x27; https: //www.selenium.dev/ & # x27;)12// A new window is opened and replacement to it13driver.switch_to.new_window(& # x27; window & # x27;)14// Loads Sauce Labs open source site in the newly opened window15driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;)1617// C#1819driver.Navigate().GoToUrl(@& quot; https: //selenium.dev & quot;);20// A new window is opened and transposition to it21driver.SwitchTo().NewWindow(WindowType.Window);22// Loads Sauce Labs unfastened source website in the new opened window23driver.Navigate().GoToUrl(@& quot; https: //opensource.saucelabs.com/ & quot;);2425// Ruby2627driver.get& # x27; https: //selenium.dev & # x27;28// A new window is opened and switches to it29driver.manage.new_window(:window)30// Loads Sauce Labs open source site in the fresh opened window31driver.get& # x27; https: //opensource.saucelabs.com/ & # x27;3233// JavaScript3435await driver.get(& # x27; https: //selenium.dev & # x27;);36// A new window is opened and switches to it37await driver.switchTo().newWindow(& # x27; window & # x27;);38// Loads Sauce Labs exposed source site in the newly opened window39await 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// Java23driver.get(& quot; https: //www.selenium.dev/ & quot;);4// A new tab is open and switches to it5driver.switchTo().newWindow(WindowType.TAB);6// Loads Sauce Labs open beginning website in the new opened window7driver.get(& quot; https: //opensource.saucelabs.com/ & quot;);89// Python1011driver.get(& # x27; https: //www.selenium.dev/ & # x27;)12// A new tab is opened and substitution to it13driver.switch_to.new_window(& # x27; tab & # x27;)14// Loads Sauce Labs unfastened source website in the newly opened window15driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;)1617// C#1819driver.Navigate().GoToUrl(@& quot; https: //selenium.dev & quot;);20// A new tab is open and switches to it21driver.SwitchTo().NewWindow(WindowType.Tab);22// Loads Sauce Labs open rootage website in the newly opened window23driver.Navigate().GoToUrl(@& quot; https: //opensource.saucelabs.com/ & quot;);2425// Ruby2627driver.get& # x27; https: //selenium.dev & # x27;28// A new tab is opened and switches to it29driver.manage.new_window(:tab)30// Loads Sauce Labs exposed source website in the freshly opened window31driver.get& # x27; https: //opensource.saucelabs.com/ & # x27;3233// JavaScript3435await driver.get(& # x27; https: //selenium.dev & # x27;);36// A new tab is opened and switch to it37await driver.switchTo().newWindow(& # x27; tab & # x27;);38// Loads Sauce Labs unfastened beginning website in the new opened window39await driver.get(& # x27; https: //opensource.saucelabs.com/ & # x27;);40
Check out our comprehensive guide to for more info.
Sr. Developer Experience Engineer, Sauce Labs
Staff Software Engineer at Sauce Labs
Share this post
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 FreeTest 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
