3

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")) {
        break;
    }
}

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

driver.FindElement(By.Id("FileLeafRef_8553196d-ec8d-4564-9861-3dbe931050c8_$onetidIOFilert")).SendKeys("NewprojectTest");
2

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

driver.SwitchTo().Window(driver.WindowHandles.Last());

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

1

@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();

    driver.switchTo().window(child);

    //perform actions

    driver.close(); // only for child


    driver.switchTo().window(parent);

    //perform actions

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

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.