Picture: there is Popup window in the html
try:
all_handles = self.driver.window_handles
for handle in all_handles:
if handle != now_handle:
print handle
try:
self.driver.switch_to_window(handle)
self.driver.find_element_by_xpath(".//*[@id='ks-overlay-close-ks-component9045']").click()
except:
continue
but it is failed, i can not switch to the window and close it
This one does not look like a browser pop up window. In this case you don't need switch_to_window and window_handles functions, just find the DOM element that represents the close button and have click on it.