Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I read JavaScript alert box with WatiN?

Tags:

watin

I want to use WatiN to verify the error message in a JavaScript alert box. Is this possible? Thanks.

like image 330
Les Avatar asked Jan 19 '09 16:01

Les


People also ask

How to display alert message box in JavaScript?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

How alert works in JavaScript?

The alert() method in JavaScript displays an alert box with a specified message and an OK button. It is often used to make sure that information comes through to the user. The alert box takes the focus away from the current window and forces the browser to read the message.

What is a JavaScript alert box?

An alert dialog box is mostly used to give a warning message to the users. For example, if one input field requires to enter some text but the user does not provide any input, then as a part of validation, you can use an alert box to give a warning message.

Should I use JavaScript alert?

Alerts should never be used for debugging unless you intend for it to stop the execution of the code for a purpose. Otherwise, you should be using console. log because alert can actually change the result of your code if your code involves asynchronous logic.


1 Answers

see Trev's Blog and here as well.

using(IE ie = new IE("http://hostname/pagename.htm"))
{
    AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
    using (new UseDialogOnce(ie.DialogWatcher, alertDialogHandler ))
    {
        /*************************************
        * -- alert -- *
        * *
        * must use the "NoWait" to allow *
        * the code to goto the next line *
        * *
        *************************************/

        alertDialogHandler.WaitUntilExists();
        alertDialogHandler.OKButton.Click();
        ie.WaitForComplete();
    }
}
like image 196
Dror Avatar answered Jan 03 '23 18:01

Dror