I found this code on SO to automatically dismiss a confirm dialog, but it is not working in Firefox.
The problem is, var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button"
&& new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
Always returns null. Is there another way to get the handle of the dialog button in firefox?
public class OKDialogHandler : BaseDialogHandler {
public override bool HandleDialog(Window window) {
var button = GetOKButton(window);
if (button != null) {
button.Click();
return true;
} else {
return false;
}
}
public override bool CanHandleDialog(Window window) {
return GetOKButton(window) != null;
}
private WinButton GetOKButton(Window window) {
var windowButton = new WindowsEnumerator().GetChildWindows(window.Hwnd, w => w.ClassName == "Button"
&& new WinButton(w.Hwnd).Title == "OK").FirstOrDefault();
if (windowButton == null)
return null;
else
return new WinButton(windowButton.Hwnd);
}
}
The controls on the Firefox alert() dialog are not enumerable. That is, they don’t exist as separate windows like they do in IE. The best way to approach this is to create a new
DialogHandlerclass that implementsIDialogHandler. In the constructor, you can pass in the Firefox instance for which the dialog appears, and you can use the following codeto send JavaScript across to Firefox to manipulate the dialog:You can use the JavaScript below to click on the OK and Cancel buttons on an alert() or confirm() dialog.
A more complete implementation, which wraps the native IE alert() and confirm() handling in a common interface and adds Firefox handling is available at http://pastebin.com/ZapXr9Yf