Selenium does not currently provide processing for the IE modal dialog box (that is, a pop-up dialog box opened through the ShowModalDialog method). The reason for this is that the modal dialog box will suspend the parent page's JS until the dialog is finished and the parent page JS will continue to execute. Because the underlying implementation of the selenium is based on JS, the modal dialog box will suspend selenium, selenium cannot select the modal dialog box until timeout.
But many systems tend to have a large number of modal dialog boxes applied. These applications are divided into two categories: the selection of people, the choice of business types, such as operations, the purpose of which is to fill the corresponding fields of the parent page, does not trigger other operations, and the other kind of more special, such as workflow distribution, This type of operation continues to perform a series of operations after the selected person returns a value in the modal dialog box (that is, the call to the ShowModalDialog method is sandwiched between a bunch of JS operations).
For the first case, the corresponding data constants can be established in the test code to avoid invoking the ShowModalDialog method by direct assignment, but only hack in the second case.
In the current test case, use the following hack method:
A typical modal dialog box opens (for example, a button) after a page element is clicked, and the ShowModalDialog method is overwritten the first time the page element is clicked. Open the modal dialog box to open the page for window.open and select the pop-up page selenium:
Java code
public void clickAndSelectModalDialog(String locator){
clickForModalDialog(locator);
selenium.selectWindow(“name=modal”);
}
private void clickForModalDialog(String locator){
String overrideShowModalDialogJs=="if(selenium.browserbot.getCurrentWindow().showModalDialog){";
overrideShowModalDialogJs += "selenium.browserbot.getCurrentWindow().showModalDialog = function( sURL, vArguments, sFeatures)";
overrideShowModalDialogJs +="selenium.browserbot.getCurrentWindow().open(sURL, 'modal', sFeatures);";
overrideShowModalDialogJs += "};}";
//showModalDialog方法进行覆盖
selenium.getEval(overrideShowModalDialogJs);
selenium.click(locator);
selenium.openWindow(“”,”modal”);
selenium.waitForPopUp(“modal”,”15000”);
}
You can then work on the pop-up page to get the values you want to return to the parent page, which is typically an array. Close the pop-up page and return to the parent page after getting the value. Click on the elements of the modal dialog box again on the parent page to overwrite the ShowModalDialog method for the second time and return the value obtained above directly.