Lucas Nunes Lucas Nunes - 7 months ago 24
HTML Question

Close dialog window on webpage

I need to trigger some actions inside one webpage (not mine)..

I have got this code so far:

IHTMLElementCollection DeleteCollection =
(IHTMLElementCollection)myDoc.getElementsByTagName("a");

foreach (HTMLAnchorElement buttonDelete in DeleteCollection){
if (buttonDelete.title != null && buttonDelete.title.StartsWith("Delete")){
buttonDelete.click();
// problem goes here
myDoc.activeElement.click();
SendKeys.Send("{ENTER}");
}
}


The dialog that pops up is this: image

As you can see above, I tried:

myDoc.activeElement.click();


and also:

SendKeys.Send("{ENTER}");


But, the dialog seems to be out of the page, and I don't know how to trigger the
OK
button.

Any help will be welcome, thanks in advance.

Answer

You cannot close a browser dialog programatically. What you can do is hijack browser popup behavior. This might work for you:

window.confirm=function(){ return true; };
window.alert=function(){ return true; };
window.prompt=function(){ return "textOfMyChoice"; };

Basically, insert this javascript before clicking your buttons. If you want to later restore the popup behavior store them in another global variable.