In general JavaScript popups are generated by web application and can be handled by WebDriver.
Webdriver offers the ability to handle with javascript alerts using Alerts API
See more details here : http://selenium.googlecode.com/svn@7074/trunk/docs/api/java/index.html
// Get a handle to the open alert, prompt or confirmation
Alert alert = driver.switchTo().alert();
//Will Click on OK button.
alert.accept(); alert.authenticateUsing(Credentials credentials)
// Will click on Cancel button.
alert.dismiss()
//will get the text which is present on the alert.
alert.getText();
//Will pass the text to the prompt popup
alert.sendkeys();
Alert is an interface. There below are the methods that are used
Lets take an example
1. Open google chrome
2. Navigate to site : http://admin-demo.nopcommerce.com/login
3. Go to Catalog->Product tags
4. And delete the product
4. And delete the product
SCRIPT :