Handling ui-dialog in Selenium Webdriver using Java

1.7k views Asked by At

In our application, once after providing the details of creating an order clicks Save, a dialog gets open and wants user’s re-confirmation whether the order needs to place or not.

Now the difficulty comes in identifying and submitting confirmation on this newly opened dialog – where unable to switch into this new dialog.

Set<String> window = wd.getWindowHandles();
Iterator<String> it = window.iterator();
String parentwindow = it.next();
String childwindow = it.next();
wd.switchTo().window(childwindow);
ccg.clickconfirmSalesEntitySave();
wd.switchTo().window(parentwindow); 

Not for certain, whether the window method works for dialog too..

Can someone help me on this concern, please.

Below is the HTML of this dialog.

<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable" style="display: block; z-index: 1002; outline: 0px none; height: auto; width: 300px; top: 37px; left: 514px;" tabindex="-1" role="dialog" aria-labelledby="ui-dialog-title-dialog-confirm">
    <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" unselectable="on" style="-moz-user-select: none;">
        <span id="ui-dialog-title-dialog-confirm" class="ui-dialog-title" unselectable="on" style="-moz-user-select: none;">Create an order</span>
        <a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button" unselectable="on" style="-moz-user-select: none;">
            <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span>
        </a>
    </div>
    <div id="dialog-confirm" class="popup ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 155px;">
        <br/>
        <table>
            <tbody>
                <tr>
                    <td class="dialogContent">Please confirm your request</td>
                </tr>
            </tbody>
        </table>
        <br/>
        <br/>
        <div style="border:0.1px solid #DCDCDC;"/>
        <br/>
        <form id="xyzGroupVO" method="post" action="/xyz/xyz/Maintenance?execution=e2s2">
            <div align="center">
                <input id="confirmOrderSave" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="submit" value="Yes" name="_eventId_xyzGroupSave"/>
                <input id="confirmOrderDontSave" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="submit" value="No" name="_eventId_xyzGroupDontSave"/>
            </div>
        </form>
    </div>
</div>
1

There are 1 answers

0
Aru On

In your code,you can get child window through first it.next(). Try following:

String parentWindowHandle = browser.getWindowHandle(); // save the current window handle.   
Iterator<String> windowIterator = browser.getWindowHandles();  
while(windowIterator.hasNext()) 
{ 
    String windowHandle = windowIterator.next(); 
     browser.switchTo().window(windowHandle);
}