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
15,663 views

1 answer to this question.

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){
    driver.switchTo().window(curWindow);
}

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

driver.close();

and switch back to the parent window

driver.switchTo().window(parentWindow);
answered Sep 25, 2018 by Meci Matt
• 9,460 points

Related Questions In Selenium

0 votes
1 answer

How to open new tab in same browser and switch between them using Selenium?

Hi Mugdha, you can use following code ...READ MORE

answered May 24, 2019 in Selenium by Abha
• 28,140 points
22,022 views
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, 2019 in Selenium by Vaishnavi
• 1,180 points
1,577 views
0 votes
1 answer

How to switch between tabs on a browser and get titles of each tab using Selenium?

Hi Abhimanyu, you can use following code ...READ MORE

answered Jul 22, 2019 in Selenium by Abha
• 28,140 points
9,498 views
0 votes
2 answers

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,500 points
12,743 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,618 views
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,910 points
6,696 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,557 views
+10 votes
17 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,360 points
194,211 views
0 votes
8 answers

How to open a link in new tab of chrome browser using Selenium WebDriver?

This below code works for me in ...READ MORE

answered Dec 14, 2020 in Selenium by Gitika
• 65,910 points
101,633 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP