Selenium WebDriver
Benefits of Selenium
Four components of Selenium
Difference b/w Selenium IDE, RC & WebDriver
Selenium WebDriver Architecture
Background when user execute selenium code
Download and Install Java
Download and Install Eclipse
Download Selenium WebDriver
Selenium WebDriver Locators
Selenium - Launch Browser
Selenium WebDriver Waits
Selenium- Implicit wait
Selenium- Explicit wait
Selenium- Fluent wait
Selenium- Commonly used commands
Selenium- findElement & findElements
Selenium- Selenium-Handling check Box
Selenium- Handling Radio button
Selenium- Handling drop down
Selenium- Take Screenshot
Selenium- Handle Web Alerts
Selenium- Multiple Windows Handling
Selenium- Handle iframes
Selenium- Upload a file
Selenium- Download a file
Selenium- Actions Class Utilities
Selenium- Mouse Actions
Selenium- Keyboards Events
Selenium- Handle mouse hover Actions
Selenium- Drag and Drop
Selenium- Scroll a WebPage
Selenium- Context Click / Right Click
Selenium- Double Click
Selenium- Desired Capabilities
Selenium- Assertions
Selenium- Exceptions and Exception Handling
Selenium- Difference b/w driver.close() & driver.quit()
Selenium- difference b/w driver.get() & driver.navigate()
Selenium- JavascriptExecutor
Selenium- Read excel file using Fillo API
Selenium- Database Testing using Selenium
Selenium- Read & write excel file using Apache POI
Selenium- Read and Write csv file in Selenium
Selenium- Dynamic Web Table Handling
Selenium- Maven Integration with Selenium
Selenium- Set up Logging using Log4j
Selenium-Implement Extent Report
Difference between driver.close() and driver.quit() in selenium webdriver
This article will present to you the difference between driver.close() and driver.quit() .
driver.close() and driver.quit() are two different methods provided by webdriver interface for closing the browser session in Selenium WebDriver.Â
We will learn below commands in detail
- driver.close()Â
- driver.quit()
- driver.quit(): The quit() method quits the driver, closing every associated window.
- driver.close(): The close() method closes the currently focused window.
Let us read about it in more detail.
driver.close()
This method closes the browser window on which the focus is set.Â
If one browser is open then calling driver.close() closes the current browser window or we can say close() method closes the active WebDriver instance.
For example – During the automation process, If we click on a link on the current browser and it opens a new window and we need to perform some action/validation on the new window so after performing validation then we can close the browser using driver.close() command.
The following code can be used to close the current browser window:
driver.close()
driver.quit()Â
This method basically calls driver.dispose() (internal method) which in turn closes all of the browser windows and ends the WebDriver session . For example if three browsers are opened from a single driver instance , then it will close all the browsers and end the webdriver session.
We cannot use this driver instance to do other operations after calling quit() ,If you do it will throw an Exception.
Before ending the execution/program , if we do not use driver.quit() at the end of the program, the WebDriver session will not close properly and files would not be cleared from memory. This may result in memory leak errors.
The following code can be used to close the all browser windows associated with current driver:
driver.quit()
package com.test; import java.util.Iterator; import java.util.Set; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class Demo { public static WebDriver driver; public static void main(String[] args) throws InterruptedException { // Create a new instance of the Chrome driver System.setProperty("webdriver.chrome.driver", "D:\\Drivers\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch the URL driver.get("https://tutorialshut.com/demo-website-for-selenium-automation-practice/"); // Maximize the window driver.manage().window().maximize(); driver.findElement(By.xpath("//button[text()='New Browser Window']")).click(); String MainWindow = driver.getWindowHandle(); // To handle all new opened window. Set s1 = driver.getWindowHandles(); Iterator i1 = s1.iterator(); while (i1.hasNext()) { String ChildWindow = i1.next(); if (!MainWindow.equalsIgnoreCase(ChildWindow)) { // Switching to Child window driver.switchTo().window(ChildWindow); // get the page title of Child window String childPageTitle = driver.getTitle(); System.out.println("Title of Child Page is :" + childPageTitle); // Closing the Child Window. driver.close(); } } // Switching to Parent window i.e Main Window. driver.switchTo().window(MainWindow); driver.quit();Â //close all the browsers and end webdriver session } }
In the above example driver.close() will close the child window only which was opened by clicking on a button present on the main page.
driver.quit() will close all the open pages and end the driver session , if we haven’t used driver.close() before then the quit statement will close child and main both the browser windows and will end the driver session as well.
Â
Selenium WebDriver Tutorials
Benefits of Selenium
Four components of Selenium
Difference b/w Selenium IDE, RC & WebDriver
Selenium WebDriver Architecture
Background when user execute selenium code
Download and Install Java
Download and Install Eclipse
Download Selenium WebDriver
Selenium WebDriver Locators
Selenium - Launch Browser
Selenium WebDriver Waits
Selenium- Implicit wait
Selenium- Explicit wait
Selenium- Fluent wait
Selenium- Commonly used commands
Selenium- findElement & findElements
Selenium- Selenium-Handling check Box
Selenium- Handling Radio button
Selenium- Handling drop down
Selenium- Take Screenshot
Selenium- Handle Web Alerts
Selenium- Multiple Windows Handling
Selenium- Handle iframes
Selenium- Upload a file
Selenium- Download a file
Selenium- Actions Class Utilities
Selenium- Mouse Actions
Selenium- Keyboards Events
Selenium- Handle mouse hover Actions
Selenium- Drag and Drop
Selenium- Scroll a WebPage
Selenium- Context Click / Right Click
Selenium- Double Click
Selenium- Desired Capabilities
Selenium- Assertions
Selenium- Exceptions and Exception Handling
Selenium- Difference b/w driver.close() & driver.quit()
Selenium- difference b/w driver.get() & driver.navigate()
Selenium- JavascriptExecutor
Selenium- Read excel file using Fillo API
Selenium- Database Testing using Selenium
Selenium- Read & write excel file using Apache POI
Selenium- Read and Write csv file in Selenium
Selenium- Dynamic Web Table Handling
Selenium- Maven Integration with Selenium
Selenium- Set up Logging using Log4j
Selenium-Implement Extent Report