[英]Handling ui-dialog in Selenium Webdriver using Java
在我们的应用程序中,在提供了创建订单的详细信息之后,单击“保存”,便会打开一个对话框,并要求用户重新确认是否需要下订单。
现在,困难在于在此新打开的对话框上标识并提交确认–无法切换到此新对话框。
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);
不确定window方法是否也适用于对话框。
有人可以帮我解决这个问题。
以下是此对话框的HTML。
<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>
在您的代码中,您可以首先通过it.next()
获得子窗口。 请尝试以下操作:
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.