0 votes
1 view
in Devops and Agile by (19.8k 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 (63.4k 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()){

    driver.switchTo().window(winHandle);

}

 

// Perform the actions on a new window

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

driver.close();

 

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

driver.switchTo().window(winHandleBefore);

// Continue with the original browser (first window)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...