You can do it programmatically by running some javascript code and make window.open
function to do nothing!
Example
Here is a test page I made that has a very simple form and when the user clicks the Sum button, it sums up numA
+ numB
and it displays the result inside a <span id="result"></span>
element. After the result text update, it opens a popup window by calling window.open
. In order to make this popup window disappear, we need to eliminate the window.open
function:
window['open'] = function() { return false; }
To do that using Watin, we have to use the Eval
function and inject the javascript code like this:
browser.Eval("window['open'] = function() { return false; }");
Then all popups are gone for that page load only and we have the wanted result.
Sample C# code
private void buttonPopupdEnabled_Click(object sender, EventArgs e)
{
WatiN.Core.Settings.Instance.MakeNewIeInstanceVisible = false;
IE ie = new IE();
ie.GoTo("http://zikro.gr/dbg/html/watin-disable-popups/");
ie.Eval("window['open'] = function() { return false; }");
ie.TextField(Find.ById("numA")).TypeText("15");
ie.TextField(Find.ById("numB")).TypeText("21");
ie.Button(Find.ById("sum")).Click();
string result = ie.Span(Find.ById("result")).Text;
ie.Close();
labelResult.Text = String.Format("The result is {0}", result);
}
Program running before javascript injection (Popup shows up)

Program running after javascript injection (Popup is gone)
