How to handle onload javascript alerts in selenium?
It is not being captured in Selenium IDE neither it is being handled by getAlert() function.
Even I faced the same problem. After several hours spent with selenium, found the solution for handling java script alerts and popups.
we can use the keyPressNative of selenium to handle the java script alerts from the selenium RC.
Here is how the key*Native() method have to be used:
selenium.keyPressNative("27"); // Escape
selenium.keyPressNative("10"); // Enter
selenium.keyDownNative("16"); // Press and do not relase the shift key, so that
selenium.keyPressNative("79"); // this character will be capitals
selenium.keyUpNative("16"); // Release the shift key, as we don't need it for the
selenium.keyPressNative("67");
It is not advisable but helped me in handling some of the selenium failures.
It can't be done. As stated in Selenium documentation:
Selenium tries to conceal those dialogs from you (by replacing window.alert, window.confirm and window.prompt) so they won’t stop the execution of your page. If you’re seeing an alert pop-up, it’s probably because it fired during the page load process, which is usually too early for us to protect the page.
It is a known limitation of Selenium RC (and, therefore, Selenium IDE, too) and one of the reasons why Selenium 2 (WebDriver) was developed. If you want to catch onload JS alerts, you need to use WebDriver alert handling.
As a workaround, you could use Robot to fill in any text and press Enter and confirm the dialog blindly. It's not the cleanest way, but it could work. You won't be able to get the alert message, however.