Open In App
Related Articles

How to Switch between Window using Selenium in Python?

Like Article
Save Article
Report issue

Selenium is an effective device for controlling an internet browser through the program. It is purposeful for all browsers, works on all fundamental OS and its scripts are written in numerous languages i.e Python, Java, C#, etc, we can be running with Python.

It’s miles fantastically viable that we open a massive range of windows. Each window might also additionally require us to carry out a few moves for finishing a stop-to-stop flow. For this, we need to be capable of transfer among them. We want to interchange over the manage additionally after which do the desired operation, because, with the aid of using the default, the point of interest stays at the figure window.


You need to install chromedriver and set path. Click here to download for more information follows this link. WebDriver supports moving between these windows using the “switch_to_window()” method.


Step-by-step approach:

If we open multiple windows then we want the print the title of every window page, but we print only a parent window of the title not an all window page title. This problem will solve through the driver.switch_to_window(“). Using this method we are capable of printing every page of the title.

  • Taking any URL.
  • We want the child window of this web page then click on any button using the find_element_by_xpath() method to find XPath.
  • Create a handles variable who store of all handles value of open browser window


  • Then using loop print all the titles of webpages.



# import selenium module
from selenium import webdriver
# import select class
from import Select
# using chrome driver
driver = webdriver.Chrome()
# web page url and open first window page
# find xpath of button for child window page
# this page no. 2
# return all handles value of open browser window
handles = driver.window_handles
for i in handles:
    # print every open window page title



Last Updated : 04 Jan, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads