Wednesday, April 17, 2013

What is the difference between WebDriver.close() and WebDriver.quit()

WebDriver.close() method closes the current window.

See the below example, here it opens the new link in a different window and upon executing the close() method, it closes the parent window and leaving the new window open.

WebDriver driver=new FirefoxDriver();
driver.get("http://google.com");
driver.manage().window().maximize();
WebElement oWE=driver.findElement(By.linkText("About Google"));
Actions oAction=new Actions(driver);
oAction.moveToElement(oWE);
oAction.contextClick(oWE).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
driver.close();

Whereas, WebDriver.quit() method quits the driver, and closing every associated window.
In the above example, if you use driver.quit() in place of close , then first opens "google" page and then open the "about google" in new window and closes both the windows.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.