Next-Gen App & Browser
Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How to make another window in Selenium?

In Selenium, you can create a new window by using the "window_handles" attribute, which returns the handles of all currently open windows. Then, using the “switch to.window()” method, you may go to the chosen window.

What is the window_handles attribute?

When you open a new browser window or tab, Selenium generates a new window handle for that window. The window handles attribute allows you to access and switch between these handles.

Here are different use cases of the window_handles attribute in Python:

  • Moving between windows: You can acquire a list of all open window handles by using the window_handles attribute and then use the switch to.window() method to switch between them.
  • Closing windows: Use the window handles attribute to acquire a list of all open window handles, and then use the close() method to close a specific window.
  • Opening new windows: The execute_script() method can open a new window, and the window handles attribute can be used to receive a list of all open window handles, including the newly launched window.
  • Counting the number of open windows: The length of the list supplied by the window handles attribute can be used to calculate the number of open windows using the len() function.

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...
ShadowLT Logo

Start your journey with LambdaTest

Get 100 minutes of automation test minutes FREE!!

Signup for free