Default

Which method is used to close the browser in Selenium?

Which method is used to close the browser in Selenium?

  • a) exit()
  • b) quit()
  • c) tearDown()
  • d) browserClose()

Correct Answer: b) 

The correct method to close the browser in Selenium is b) quit().

Explanation

quit(): Terminates the WebDriver session, closes all browser windows, and releases resources. This is the proper way to end a Selenium session.

Incorrect answers

  • exit(): Typically refers to terminating a process (e.g., System.exit() in Java) and is not Selenium-specific.
  • tearDown(): A common method in testing frameworks (like JUnit/TestNG) for cleanup but not a direct Selenium browser-closing method.
  • browserClose(): Not a standard Selenium WebDriver method.