I need to trigger some actions inside someone else's webpage. I have 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}");
}
}
This dialog pops up:
I tried myDoc.activeElement.click();
and SendKeys.Send("{ENTER}");
but the dialog seems to be out of the page, so I don't know how to trigger the OK
button. How can I close the window?
Simply call window. close() and it will close the current window. If it doesn't work... it should always work.
The close() method closes the dialog. Tip: This method is often used together with the show() method.
Right-click the icon referring to the dialog box from the Windows taskbar and click “Close”.
By default, dialog can be closed by pressing Esc key and clicking the close icon on the right of dialog header. It can also be closed by clicking outside of the dialog using hide method. Set the CloseOnEscape property value to false to prevent closing of the dialog when pressing Esc key.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With