1

I am using the .NET WebBrowser control to automate some web tasks, however now and again the website I am visiting will produce a dialogue box with a YES/NO button that I need to press.

The dialogue is popped up using a Javascript modal window. I need the WebBrowser to detect a Javascript modal popup, get the source of the popup to define the response to give, and then click one of the buttons.

Can this be achieved?

noseratio
  • 59,932
  • 34
  • 208
  • 486
John Cliven
  • 973
  • 1
  • 8
  • 21
  • send me your code or tell me your requirements like you want YES/No type dialog box and you want to perform operation on click on YES and No buttons. – Manoj Pilania Oct 21 '13 at 12:38
  • Have you managed to click any button in a web browser control with code? If not then I doubt this will be possible. – Nunners Oct 21 '13 at 12:38
  • @Nunners I have managed to click other buttons with no problem, I just don't know how to interact with a JS dialogue popup box – John Cliven Oct 21 '13 at 12:49
  • @johndyas, is it a real modal dialog window, which blocks the browser window and which you can drag outside the web browser window, all over the desktop? I.e., a window created with `window.alert()` or `window.confirm()`? – noseratio Oct 22 '13 at 06:40

1 Answers1

0

I've encountered a similar situation

But in my case it is just a simple confirm dialog so I simply skip it by removing the confirm javascript command from the html element.

Here's the javascript code that invoke the dialog

       confirm('Comfirm to kill');

here's the full html tag of the button that invoke the dialog

       <a id="inputID" onclick="return confirm('Comfirm to kill.');" href="javascript:__doPostBack('ctl00$ContentMainContent$gvOnlineUser$ctl02$btnAction','')">

And here I remove the js to call the function

        HtmlElement elementButton = doc.GetElementById("inputID");
        elementButton.SetAttribute("onclick", "return true;");
        elementButton.InvokeMember("Click");

That should skip the confirmation dialog part I'm not sure it would work in your case though Hope this help anyway

LameLoura
  • 148
  • 1
  • 9