Reputation: 841
Using Selenium I am opening a window. I want to close and Quit the Window after the Button is Clicked. How can I achieve that in Selenium. The function which I want to perform before Closing The window is Below
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='css-vote-button pds-vote-button' and starts-with(@id, 'pd-vote-button10359300')]/span[text()='Vote']"))).click();
Upvotes: 0
Views: 234
Reputation: 3225
With driver.close()
you can close the tab/window which WebDriver controlling.
I use this code to close all tabs/windows.
var tabs = new ArrayList<>(driver.getWindowHandles());
while(tabs.size() > 0){
driver.switchTo().window(tabs.get(0)); //NoSuchWindowException
driver.close();
tabs = new ArrayList<>(driver.getWindowHandles());
}
Upvotes: 1