Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I want to select the current window,frame or popup where my browser is pointing. (i.e when i doubleclick or click it opens an popup or window) I want to get through that window or popup using selenium webdriver.So if possible please suggest me how to do it. Thanks in advance.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

To switch to new pop up window what you can do is the following:

String currentWindow = driver.getWindowHandle();
String lastWindow = null;
 Set<String> handles = driver.getWindowHandles();
    for (String aux : handles) {
        lastWindow = aux;

This will switch you to the new window opened. If you need to switch to the other window just switch to currentWindow.

Hope this helps.

share|improve this answer
sure i will work on this. –  Emmanuel Angelo.R Feb 28 '14 at 4:44

You can use the following code also to handle popup.

 String mainwindow = driver.getWindowHandle();
        for (String popup : driver.getWindowHandles()){
// Your code on poppup window
        driver.switchTo().window(mainwindow); //Switching to main/parent window

Hope this will help :)

share|improve this answer
sure i will try it QA4it –  Emmanuel Angelo.R Mar 4 '14 at 14:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.