Wednesday, October 24, 2012

How to switch between browser windows in Selenium 2 (WebDriver Java)

 // Store you current window handle in a String variable.  
 String parentWindow = driver.getWindowHandle();  
   
 // Click on the the page element which causes a new window to be opened,suppose a link.  
 driver.findElement(BY.linkText("myLink")).click();  
   
 // Get the window handle of the new browser window opened.  
 String childWindow = (String) driver.getWindowHandles().toArray()[1];  
   
 // Switch to newly opened window.  
 driver.switchTo().window(childWindow);  
   
 // Switch back to main window.  
 driver.switchTo().window(parentWindow);  


© automatethebox. All Rights Reserved

24 comments:

Amirtha rao said...

Informative Post! Thanks admin.
Selenium Training

Arjun Kumar said...

Useful post.
Selenium Training in Chennai

Saradha Devi said...

keep blogging on Selenium Topics

Selenium Training Chennai

isabellaJoseph said...

I read your blog from the beginning.it s very informative.Thank you so much for sharing... Selenium Training in Chennai
Dot Net Training in Chennai
Android Training in Chennai

santhosh k said...

The blog gave me idea to switch between browser windows my sincere thanks for sharing this post please continue to share this post
Selenium Training in Bangalore

Logavani G said...

really nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge about this so keep on sharing such kind of an interesting blogs.
Selenium Training in Bangalore

Melba henry said...

Selenium play an important role in today’s era of technology. And You have post an very informative post. Your blog gave me a lots of new ideas. Keep posting such kind of useful information. Thanks.. Selenium Training in Chennai | Software Testing Training in Chennai

JamesWilliam said...

Interesting post! This is really helpful for me. I like it! Thanks for sharing!
Mobile application developers in Chennai | PHP developers Chennai

Sara mathew said...

Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating.
ME/M.Tech Project Center in Chennai | ME/M.Tech Project Center in Velachery

HADOOP TRAINING IN CHENNAI said...


Thanks for one marvelous posting! I enjoyed reading it;Great post.The information was very useful.Keep the good work goin on!!
Hadoop training in chennai | Mainframe training in chennai | SAP SD training in chennai

aravindsai said...

Wonderful post. I am learning so many things from your blog.keep posting.
PHP Online Training | Pega Online Training | Oracle Soa Online Training

sri krishna kumar said...


Very useful content

Sap MM Training In Chennai | Mainframe Training In Chennai | Hadoop Training In Chennai

john kevin said...

I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.


Best Java Training Institute Chennai

mari A said...

Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.

AWS Training in Chennai

Apsara G said...

Excellent Article ...thank u for sharing, such a valuable content Learners to get good knowledge after read this article.. Selenium Training in Chennai | Selenium Training institutes in Chennai

Divya D said...

Informative blogs.. Keep posting more useful blogs about selenium

Selenium training in Velachery
Selenium training institute in chennai
Selenium training in chennai

Unknown said...

Your good knowledge and kindness in playing with all the pieces were
very useful. I don’t know what I would have done if I had not
encountered such a step like this.

hadoop training in chennai

vimal kumar said...

I am really happy with your blog because your article is very unique and powerful for new reader.
Selenium Training in Chennai

Sai Elakiyaa said...

Great website and content of your website is really awesome.

Selenium Training in Chennai
software testing selenium training
iOS Course in Chennai
iOS Training Chennai
Java training institute in chennai
Best JAVA Training institute in Chennai

Vicky Ram said...

I am happy to find this post Very useful for me, as it contains lot of information

Article submission sites
Guest posting sites

nanadhini chandran said...

Thanks first of all for the useful info.
the idea in this article is quite different and innovative please update more.
angularjs training center in bangalore
AngularJS courses in Anna Nagar
AngularJS Certification Training in T nagar

LindaJasmine said...

Awesome Post. I was searching for such a information for a while. Thanks for Posting. Pls keep on writing.
Informatica Training in Chennai
Informatica Training center Chennai
Informatica Training Institute in Chennai
Best Informatica Training in Chennai
Informatica Course in Chennai
Informatica Training center in Chennai
Informatica Training chennai


Anjali Siva said...

Thanks for taking time to share this concepts admin.
DevOps Training
DevOps course in Chennai
DevOps course
Best DevOps Training in Chennai
Data Analytics Courses in Chennai
Blue Prism Training Institutes in Chennai
RPA courses in Chennai

Sathish K said...

Thanks for your efforts in sharing this information in detail. Kindly keep continuing the great work.

Best Oracle Training Institute in Chennai
Best Oracle Training in Chennai
Oracle Training Center in Chennai
VMware Training
Vmware Training center in Chennai
VMware Training institute in Chennai

AWS Certified Solutions Architect Associate - AWS Introduction - Questions

All the Best !!! Show Result !! Try Again !! ×