One of the most popular question among selenium/Webdriver users. I used that couple of places to handle.
Selenium RC: if you are expecting javaScript alert and you want to handle using OK then use following commands and then you can use your code.
selenium.chooseCancelOnNextConfirmation()
selenium.chooseOkOnNextConfirmation()
Note: In Firefox 4.0 and higher version, you will see alerts like following and its impossible to handle this via selenium.
There is a workaround to handle this.
Type ‘about:config’ in Address bar of firefox browser and accept the warning.
Type “tab_”. You will see prompts.tab_model.enabled option with Value: true.
Double click on the row which will make it false.
Now alert will look like:
Webdriver:
There is command to handle alert are:
driver.SwitchTo().Alert().Accept();
driver.SwitchTo().Alert().Dismiss();
driver.SwitchTo().Window(“windowName”);
You can handle as per your need.
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-37496715-1']); _gaq.push(['_trackPageview']);
(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();