0

Tried everything that was posted on Stack, even mshtml.IHTMLElement nativeElement = el as mshtml.IHTMLElement;

nativeElement.click() didn't work.

This code below is standard and works for me on other button clicks in the WebBrowser control.

HtmlElementCollection pageTextElements = doc.Window.Document.GetElementsByTagName("input");
HtmlElement btnOK = null;

foreach (HtmlElement element in pageTextElements)
{
    if (element.Id == "btnOK")
    {
        btnOK = element;
    }
}

btnOK.InvokeMember("click");

//This is the button I'm trying to click:

<input id="btnOK" class="btn12" type="submit" value="OK" title="" tabindex="11"      style="position: absolute; left: 584px; height: 21px; width: 63px; …pointer; top: 1074px; padding-left: 0px; padding-right: 0px;" onfocus="saveFocusedControl("btnOK");" name="btn_btnOK" alt="OK" accesskey="O"></input>
Arraylist
  • 197
  • 1
  • 12
  • Any error message when you do `btnOK.InvokeMember("click")`? What happens when you click it manually? – noseratio Feb 05 '14 at 02:32
  • No errors, just does nothing. I have used this code in other places in the app and it works fine. – Arraylist Feb 06 '14 at 02:13
  • Set `WebBrowser.ScriptErrorsSuppressed` to `false` and implement [Browser Feature Control](http://stackoverflow.com/questions/18333459/c-sharp-webbrowser-ajax-call/18333982#18333982). – noseratio Feb 06 '14 at 02:26

1 Answers1

0
if (webBrowser1.ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)
{
    System.Threading.Thread.Sleep(100);
    System.Windows.Forms.Application.DoEvents();
    btnOK.InvokeMember("click"); //Go back to Select Date for TimeSheet...Original Url...
}
rbento
  • 5,069
  • 1
  • 40
  • 51
Arraylist
  • 197
  • 1
  • 12
  • There's `DocumentCompleted` event for this, which you should use instead of polling for `ReadyState`. A complete example: http://stackoverflow.com/a/19063643/1768303. – noseratio Feb 06 '14 at 03:08