0
def switch_to_new_window(self):
    sleep(5)
    print("Parent window title: " + self.webdriver.title)
    parentWindow = self.webdriver.current_window_handle
    childWindows = self.webdriver.window_handles
    for window in childWindows:
        if(window!=parentWindow):
            self.webdriver.switch_to.window(window)
            break
    sleep(2)
    print("Child window title: " + self.webdriver.title)

The above works for other popup windows but not for gmail popup window. The gmail popup window doesn't have a close button. Gmail popup

2 Answers2

0

This is how I switch windows in java, there might be something similar in python.

driver.SwitchTo().Window(WindowName);

you may also want to check out this thread: How to switch to the new browser window, which opens after click on the button?

Again, its about java but might offer some help.

Lobstergoat
  • 113
  • 1
  • 9
0

In Python you can switch to popup window like this

driver.switch_to.window(driver.window_handles[x])
x would be 1

in your case if there is only one tab and window and then you need to get back to default window in order to avoid error

driver.switch_to.window(driver.window_handles[x])
x would be 0

the same it work for switching the tabs hopefully it work

Haseeb Ahmed
  • 265
  • 3
  • 10