I'm using Watin library in a windows forms app. In order to hide the browser I use this instruction :
Settings.Instance.MakeNewIeInstanceVisible = false;
However, it doesn't hide the popups (when simulating a click on an element that opens a popup). Is there a way to hide them?
You can do it programmatically by running some javascript code and make
window.openfunction 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+numBand it displays the result inside a<span id="result"></span>element. After the result text update, it opens a popup window by callingwindow.open. In order to make this popup window disappear, we need to eliminate thewindow.openfunction:To do that using Watin, we have to use the
Evalfunction and inject the javascript code like this:Then all popups are gone for that page load only and we have the wanted result.
Sample C# code
Program running before javascript injection (Popup shows up)
Program running after javascript injection (Popup is gone)