How to switch between two windows in browser using Selenium java

0 votes
I'm working with Selenium Automation. In this, When I click a link in a current window, a new window opens. I just want to switch the control to the new window. But I can't do this.

Actually, the new window is an auto-generated one. That is, a link will be generated dynamically.

kindly help!
Sep 25, 2018 in Selenium by Christine
• 15,790 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Yes, this is possible. First, you need to save the reference to the current window.

String parentWindow= driver.getWindowHandle();

The after having clicked the link, you need to switch to the other window.

List<String> allWindows = driver.getWindowHandles();
for(String curWindow : allWindows){

This is where you perform operations on the new window, finally closing it with


and switch back to the parent window

answered Sep 25, 2018 by Meci Matt
• 9,400 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

How to handle browser popup in Selenium using Java?

Generally, we scrap the data from websites ...READ MORE

Jun 7 in Selenium by Vaishnavi
• 860 points
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
+9 votes
13 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,280 points
0 votes
5 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.