Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

I have a situation, then click on the button opens the new browser window with search results.

Is there any way to connect and focus on the newly opened browser window?

And work with it, then return back to the original(first) window.

1 Answer

0 votes
by (62.9k points)

You can switch between windows as below:


// Store the current window handle

String winHandleBefore = driver.getWindowHandle();


// Perform the click operation that opens new window 

// Switch to the new window opened

for(String winHandle : driver.getWindowHandles()){




// Perform the actions on a new window

// Close the new window if that window no more required



// Switch back to the original browser (first window)


// Continue with the original browser (first window)

Browse Categories