The difference between quit() and close()

Two very important methods available in the WebDriver interface are quit() and close(). For beginners in Selenium, this is a topic of confusion because of a lack of understanding of its usage. Let's next understand both these methods, using these distinctions:

  • driver.quit(): The quit() method quits the driver, closing every associated window.
  • driver.close(): The close() method closes the currently focused window, quitting the driver if the current window is the only open window. If there are no windows open, it will error out.

We will be looking in detail at these two methods when we learn about handling popups.

Get Selenium WebDriver Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.