Select Page
Selenium Testing

Selenium WebDriver Window Handling using Python

In this blog article, we have covered all the Selenium WebDriver window handling techniques which are helpful for automation testers.

Selenium WebDriver Window Handling using Python
Listen to this blog

In this blog article, we have covered all the Selenium WebDriver window handling techniques which are helpful for automation testers. Let’s learn the commands.

Get Window Handles

driver.window_handles
  

Switch To Window

window_handle = driver.window_handles[1]
driver.switch_to.window(window_handle)
  

As per WebDriver W3C specification, you can switch between windows only with window handle. However, you can also write your own method to switch windows using Window name.

Switch To Window By Name

#Method Definition
def switch_window_by_name(webdriver,window_name):
    for handle in webdriver.window_handles:
        webdriver.switch_to.window(handle)

        if webdriver.title == window_name:
            return handle

#Method Call
switch_window_by_name(driver,"Window1")
  

Switch To Window Position

window_handle = driver.window_handles[1]
driver.set_window_position(10,10)
  

Comments(0)

Submit a Comment

Your email address will not be published. Required fields are marked *

Talk to our Experts

Amazing clients who
trust us


poloatto
ABB
polaris
ooredo
stryker
mobility