top of page
Search
Writer's pictureTuyen Nguyen

Open new browser windows - Selenium Java

Updated: Jul 29

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:

Many Tabs vs Many Windows.

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:

  1. Create a new web driver.

  2. Optional: Create a list to handle a collection of web drivers (if you need to do action on many different drivers).

  3. Optional: Close old drivers to ensure all browser windows are closed when the test is done.

  4. Set your working driver to the driver you want.

  5. Go to the URL.

Example code:


32 views0 comments

Comments


bottom of page