Pages

Friday, 5 October 2012

Way to handle frames in selenium. Handling new window in selenium.


Below command is used to handle frame application.

driver.switchTo().frame(driver.findElement(By.tagName("iframe"))); .

child window is opened from parent window.
to access child window elements we need to select child window then only we can click/access child window elements.

    final String thisWindow = driver.getWindowHandle();
        String newWindow = new WebDriverWait(driver, 10)
                .until(new ExpectedCondition<String>() {
                    @Override
                    public String apply(WebDriver d) {
                        Set<String> handles = d.getWindowHandles();
                        handles.remove(thisWindow);
                        return handles.size() > 0 ? handles.iterator().next()
                                : null;
                    }
                });
        //newWindow.wait(10000);
        driver.switchTo().window(newWindow);

No comments:

Post a Comment