As we've already seen how to open more than one Browser widow using the Selenium Automation code. Now lets find out how the close( ) command works when more than one window is opened.
As per my explanations in our previous posts, close( ) WebDriver command closes only one window which is having focus out of all the remaining windows. All the remaining windows wont be closed by the close( ) WebDriver command.
Lets Implement the Test on Eclipse IDE:
1. Open WebDriderver - Project33 created in Previous post for opening multiple windows and ensure that the Class33.java file contains the following code as shown below:
2. Now create a method specified with @AfterClass JUnit annotation as shown below:
3. Now write the Selenium Automation code for closing the Browser window using close( ) WebDriver command as shown below:
4. Save and Run the Class33.java file using JUnit Test and observe that the two Browser windows got opened by the Selenium Automation code and the close( ) WebDriver command has closed only one Browser window as shown in the below video:
Watch the below video:
Click here to watch the video.
Download this Project:
Click here to download this project and import into Eclipse IDE on your machine.
Click here to watch the video.
Download this Project:
Click here to download this project and import into Eclipse IDE on your machine.
6. In the Selenium Automation code, Replace close( ) with quit( ) WebDriver command as shown below:
4. Save and Run the Class33.java file using JUnit Test and observe that the two Browser windows got opened by the Selenium Automation code and the quit( ) WebDriver command has closed both the Browser windows as shown in the below video:
Watch the below video:
Click here to watch the video.
Download this Project:
Click here to download this project and import into Eclipse IDE on your machine
Please comment below to feedback or ask questions.
Understanding how close( ) and quit( ) commands work when only one window is opened will be explained in the next post.