1

I'm using a WebBrowser control in a C# Window Forms application, and trying to confirm a confirm() box that was opened in the webBrowser by JavaScript.

The JavaScript code:

confirm("confirmMe");

How can I click OK on the dialog that opened?

enter image description here

mason
  • 31,774
  • 10
  • 77
  • 121
Sagi
  • 127
  • 2
  • 9
  • Do you mean "confirm"? – wingerse Oct 14 '15 at 19:22
  • If you want to close it from the server side, there's no way. If you want to do it from the client side, take a look at [this](http://stackoverflow.com/questions/6297804/can-i-close-confirm-box-in-javascript-code) question. – Anderson Pimentel Oct 14 '15 at 19:24
  • @empereurAiman - yes, im sry. – Sagi Oct 14 '15 at 19:24
  • This is a Windows Forms or WPF application, with a WebBrowser control? – mason Oct 14 '15 at 19:26
  • @andersonPimentel - there is alot of things that people said that there is no way to do them, like call a javascript function in c# - there is a way that i found by myself, but i mean like - there is anyway i will be able to change the javasscript code over there? i mean cancel the confirm message by doing something? make a new function on-page? – Sagi Oct 14 '15 at 19:27
  • @mason - Windows Forms – Sagi Oct 14 '15 at 19:27
  • Can you explain why are you trying to close a `confirm` window on a web browser from a Windows Forms application? – Anderson Pimentel Oct 14 '15 at 19:45
  • You can use the same technique to automate `confirm`: http://stackoverflow.com/a/18691219/1768303 – noseratio Oct 14 '15 at 21:14

1 Answers1

0

If you have no control over the web application, there's no way to close the confirm window, as it pauses the script execution waiting for the user input.

If you have control over the web application, try using something like JQueryUI dialog, which has a close method.

Anderson Pimentel
  • 5,086
  • 2
  • 32
  • 54
  • Having control over the WebApplication doesn't nessicarily mean that you can modify the web page your navigating to – johnny 5 Oct 14 '15 at 20:00
  • It's actually quite possible, provided the OP has control over the browser: http://stackoverflow.com/a/18691219/1768303. – noseratio Oct 14 '15 at 21:19
  • @Noseratio True. That's way beyond my knowledge in WinForms. Thanks for the info. I think you should post as an answer. – Anderson Pimentel Oct 15 '15 at 01:05
  • @johnny5 Know that, but I'm afraid he wants a complex solution for something that could be a lot simpler. – Anderson Pimentel Oct 15 '15 at 01:07
  • if the alert box pops up in the same position percent wise you could probably trigger a click from c# – johnny 5 Oct 15 '15 at 14:11
  • Im gald you people trying to help me but still I cant find the soulotion, thats not my site so I cant do anything to the code. – Sagi Oct 15 '15 at 16:00