Is there a way to physically close a tab via Protractor or WebDriver?
I ask because while I know how to switch tabs programmatically, but it does not bring the acti
if use keyboard library with selenium its very simple for switch on tab and close or etc :
first install keyboard library :
pip install keyboard
second use keyboard for close tab in code for example :
def change_tab_my_func(self, number):
driver.switch_to.window(driver.window_handles[number])
change_tab_my_func(0) #your tab index
keyboard.send('ctrl+w')
You can try the following:
Switch back to the first window.
browser.getAllWindowHandles().then(function (handles) {
browser.driver.switchTo().window(handles[1]);
browser.driver.close();
browser.driver.switchTo().window(handles[0]);
});