Selenium close browser

Close browser in selenium using close() method

To close browser in selenium, You can use close() method. It is used to close current open window on which selenium test is being executed.

  • close() method is part of WebDriver interface which extends SearchContext interface.
  • close() method in selenium will close only current selected window.
  • If multiple browser windows are open in selenium test then all windows will be not closed using close() method.
  • Syntax for using close() method is driver.close();
Selenium Close() Method

Selenium close() method example

package testPackage;

import org.openqa.selenium.WebDriver;

public class getTitleExample {

	public static void main(String[] args) {
		System.setProperty("", "D:\\chromedriver.exe");
		WebDriver driver=new ChromeDriver();
		//close current running driver instance.		

In above given example, close() method will close the current running driver window.

No comments:

Post a Comment