Using chooseOkOnNextConfirmation you can do that.
selenium.chooseOkOnNextConfirmation(); // prepares Selenium to handle next alert
selenium.click(locator);
String alertText = selenium.getAlert(); // verifies that alert was shown
assertEquals("This is a popup window", alertText);
For more information, go through this link link
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…