I use Selenium WebDriver. I open the first page then open the second page - perform some action and go back to first page. Before I want to close the second page I use the c
In Python
default_handle = driver.current_window_handle handles = list(driver.window_handles) assert len(handles) > 1 handles.remove(default_handle) assert len(handles) > 0 driver.switch_to_window(handles[0]) # do your stuffs driver.close() driver.switch_to_window(default_handle)