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;
import org.openqa.selenium.chrome.ChromeDriver;

public class getTitleExample {

	public static void main(String[] args) {
				
		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
		WebDriver driver=new ChromeDriver();
		
		driver.navigate().to("http://only-testing-blog.blogspot.com/2013/09/testing.html");
		
		//close current running driver instance.		
		driver.close();		
	}
}

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

No comments:

Post a Comment