Wednesday, September 09, 2009

Selenium - alert and confirm in the page's onload() event

Selenium does NOT support _javascript_ alerts that are generated in a page's onload() event handler. Selenium does NOT support _javascript_ confirmations that are generated in a page's onload() event handler.

You may have some alert in the login page to display some alert on invalid username and password. When you want to automate the test cases on those pages, you need to add some javascript code on those pages before displaying the alert or confirm. These following lines makes the selenium to capture the alert or confirm messages.
var browserbot = parent.selenium.browserbot;
if (browserbot) {
browserbot.modifyWindowToRecordPopUpDialogs(window, browserbot);
}
alert("Alert message after those selenium workaround js snippet");

7 comments:

ANTENANDOTECH said...

where i have to put this code?

ANTENANDOTECH said...

do i have to put this code in html page (into tag head)? and add the reference to selenium-browserbot.js in the tag head?

Raffi said...

Add that code in the javascript anywhere before your alert code.

Raffi said...

No need to reference selenium-browserbot.js

ravikiran said...

why cant i do a selenium.runscript with the java script?

Unknown said...

if we don't have the opention to change the code,then what should we do

Unknown said...

In our application we cannot make any changes in code.What to do in that case?

Please help...........its very urgent