Question

I'm running integration tests with Selenium 2.41 over a web application whose console is developed with Apache Wicket 6, and I created an instance of Selenium Firefox web driver:

protected WebDriver seleniumDriver = new FirefoxDriver();

I've a page calling the famous Wicket ModalWindow, in particular if a click a button it shows odal window page to edit or create something. Modal window has two input text fields and a Save button. With Selenium I'm trying to type something into these text fields but I'm only able to access modal window so:

seleniumDriver.findElement(By.xpath("//a[contains(text(),'Create new item')]")).click();

then selenium web driver control stucks on main page, so (following some internet examples) I wrote this code to "switch" control on open modal window:

//Store the current window handle
        String parentWindow = seleniumDriver.getWindowHandle();

//   switch to configuration modal window
            for (String winHandle : seleniumDriver.getWindowHandles()) {
                seleniumDriver.switchTo().window(winHandle);
            }

            WebDriverWait webDriverWaitHalfMinModal = new WebDriverWait(seleniumDriver, 10L);

            webDriverWaitHalfMinModal.until(ExpectedConditions.presenceOfElementLocated(By.
                    xpath("//input[@name='key:textField']")));

            // do something in modal window

            //Close the new window, if that window no more required
            seleniumDriver.close();
           //Switch back to original browser (parent window)
            seleniumDriver.switchTo().window(parentWindow); 

I tried also:

seleniumDriver.switchTo().activeElement();

and

seleniumDriver.switchTo().alert();

But there is no way to make it work, in fact list of window handles has only 1 element, the main page, and not two elements (main and modal page) and there is no way to find text field in the modal window opened with button press. I point out that the rest of my code is working, I'm not able to work only with modal windows. So my question is: How can I manage APACHE WICKET 6 modal windows with Selenium 2.41? Is there a way to switch control from main page to APACHE WICKET 6 modal window?

Was it helpful?

Solution 2

Apache Wicket modal window is a frame, in particular a jquery iframe so I needed:

seleniumDriver.switchTo().frame(seleniumDriver.findElement(By.className("wicket_modal")));

but this was not enough, infact I used web driver backend (higher level API) and created selenium web driver backend so:

seleniumDriver = new FirefoxDriver();
    selenium = new WebDriverBackedSelenium(seleniumDriver, BASE_URL);

and switchTo() and find() worked fine.

OTHER TIPS

Selenium has a bug present for handling modal dialog. Read here : https://code.google.com/p/selenium/issues/detail?id=284

There is a workaround though. Replace your click method with the one written below:

seleniumDriver.executeScript("var el=arguments[0]; setTimeout(function() { el.click(); }, 100);", seleniumDriver.findElement(By.xpath("//a[contains(text(),'Create new item')]")));

And then use your existing code to switch to the modal window. It should work.

The following has worked for me, but for Apache Wicket 1.4.x. Related to Selenium WebDriver: How to wait for iFrames to load completely?

WebElement iFrame = wait.until(visibilityOfElementLocated(By.tagName("iframe")));
driver.switchTo().frame(iFrame);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top