Close() এবং quit() পদ্ধতির মধ্যে পার্থক্য নীচে তালিকাভুক্ত করা হয়েছে। সংক্ষেপে, উভয় পদ্ধতিই ব্রাউজার বন্ধ করে দেয় এবং কোনো প্যারামিটারের প্রয়োজন হয় না।
| ক্রমিক নং | বন্ধ() | ছেড়ে দিন() |
|---|---|---|
| 1 | close() পদ্ধতিটি ফোকাসে থাকা ব্রাউজারটি বন্ধ করবে। | quit() পদ্ধতি সব ব্রাউজার বন্ধ করে দেয়। |
| 2 | close() পদ্ধতি সক্রিয় WebDriver উদাহরণ বন্ধ করে। | quit() পদ্ধতি সমস্ত সক্রিয় WebDriver দৃষ্টান্ত বন্ধ করে দেয়। |
উদাহরণ
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import java.util.Set;
import java.util.Iterator;
import org.testng.annotations.Test
public class WindowHandles{
@Test
public void Browserclose_quit() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.tutorialspoint.com/index.htm");
String currentwindow = driver.getWindowHandle();
Set<String> allWindows = driver.getWindowHandles();
Iterator<String> i = allWindows.iterator();
while(i.hasNext()){
String childwindow = i.next();
if(!childwindow.equalsIgnoreCase(currentWindow)){
driver.switchTo().window(childwindow);
System.out.println("The child window is "+childwindow);
// close() method shall the close the child window which
//is the browser in focus
//the parent window shall still be open
driver.close()
} else {
System.out.println("There are no children");
}
}
// quit() will close all the active webdriver instances, so now the parent //window will close driver.quit();
}
}