There's have been a myriad of questions raised about opening new tabs and opening new browser windows in selenium. But first, we should go fundamentally into the differences between those two.
New Tabs vs New Windows
In code, with many tabs, we just use one browser driver and execute js script window.open('URL') to open new tabs. But remember, this just open new tabs in same window browser, while using many windows browsers means we must have many windows like the picture below:
Open New Tabs - Java Code
Simply use JavascriptExecutor to run the script window.open()
Or:
Open New Windows - Java Code
One simple and easy to approach method is to create a new web driver and open a new web page on that browser. In this post, I will show you some steps to do it:
Create a new web driver.
Optional: Create a list to handle a collection of web drivers (if you need to do action on many different drivers).
Optional: Close old drivers to ensure all browser windows are closed when the test is done.
Set your working driver to the driver you want.
Go to the URL.
Example code:
Comments