TypeError: 'SwitchTo' object is not callable

1.8k Views Asked by At

I'm here to ask a question. I'm trying to close a pop-up window. This is my code

from selenium import webdriver

driver.switch_to(driver.window_handles\[1\])
driver.close()
driver.switch_to(driver.window_handles\[0\])

But i could get only this.

TypeError: 'SwitchTo' object is not callable

How can i please help me and Thx for reading this.

1

There are 1 best solutions below

0
Shubham Damkondwar On

You are trying to call the switch_to() method on the driver object directly. You should first get the driver object from webdriver.Chrome().

Below is the solution.

from selenium import webdriver

driver = webdriver.Chrome()
driver.switch_to.window(driver.window_handles[1])
driver.close()
driver.switch_to.window(driver.window_handles[0])