Skip to content
CodeKruPro

Read the window handle, window count and title

Automation taskEasy-MediumAsked in: Accenture, Capgemini, Cognizant, Infosys, TCS, Wipro

"What is a window handle?" It is the string id Selenium uses for a window or tab. Read the current handle and count the open windows; switching between tabs builds on both.

Get Window Handle and Title

Get Window Handle and Title

Every browser window/tab has a unique handle. Use getWindowHandle() to get the current window's handle and getWindowHandles() to get all window handles.

Task:

  1. Navigate to https://testkru.com/Elements/Buttons
  2. Get and verify the current window handle is not empty
  3. Verify there is exactly 1 window open
  4. Print the page title

Expected output:

Handle exists: true
Window count: 1
Title: Buttons