Test automation with Selenium can be a tough task but with the right actionable insights and practical tips, you can be proficient with test automation in Selenium.
In this article, we will understand what are Windows in Selenium and how to handle multiple windows in Selenium WebDriver using Java.
The user scenario being automated here is: Open a new tab and then switch back to the last tab to complete the other pending activities. To do so, use the Action Class approach or using selenium WebDriver interface methods getWindowHandle & getWindowHandles. In such scenarios, Selenium helps handle multiple tabs through WindowHandlers.
Now let’s take an example scenario to understand how it works. The scenario here is as follows:
- Open the DemoAutomation URL.
- Search for “open separate multiple window” in the search bar.
- Save the URL of Download.
- Open a new tab.
- Switch to the new tab and launch the stored URL.
The code below switches to the opened tab using the Window Handler methods: