I have to create a new record, for that a new popup window opens. so i am unable to switch to that window. I used this code to switch the popup window

foreach (string handle in driver.WindowHandles) {
    IWebDriver popup = driver.SwitchTo().Window(handle);
    if (popup.Title.Contains("New Document Set: Project")) {

This is the element where I need to enter the data

HTML Snippet

<input type="text" value="" maxlength="256" id="FileLeafRef_8553196d-ec8d-4564-9861-3dbe931050c8_$onetidIOFile" title="Name Required Field" class="ms-long" size="35">

Code tried


You're not focused in the right window. With this case you want to use:


Last() will switch to the most recently opened window which should be the one you just clicked.

| improve this answer | |

@santhosh - Seems you're unable to handle pop-up and switch on new/child window. You can consider child = pop-up window and parent = your actual window. Its just we need to redirect control properly.

    Set <String> handles =driver.getWindowHandles();
    Iterator<String> it = handles.iterator();

    String parent = it.next();
    String child = it.next();


    //perform actions

    driver.close(); // only for child


    //perform actions

    driver.quit(); // After execution of main thread and for parent window
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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