Identifying and handling a pop-up window by its name
In Selenium WebDriver, testing pop-up windows involves identifying a pop-up window, switching the driver context to the pop-up window, then executing steps on the pop-up window, and finally switching back to the parent window.
The Selenium WebDriver allows us to identify a pop-up window by its name
attribute or window handle and switching between the pop-up window and the browser window is done using the Webdriver.switchTo().window()
method.
In this recipe, we will identify and handle a pop-up window by using its name
attribute. Developers provide the name
attribute for a pop-up window that is different from its title. In the following example, a user can open a pop-up window by clicking on the Help button. In this case, the developer has provided HelpWindow
as its name:
<button id="helpbutton" onClick='window.open("help.html","HelpWindow","width=500,height=500");'>Help</button>
How to do it...
Let's implement a test that identifies...