Note that there are some explanatory texts on larger screens.

plurals
  1. POFlow of WebBrowser Navigate and InvokeScript
    text
    copied!<p>I'm having trouble understanding the flow of this function I'm building.</p> <pre><code> public void PortalLogin(AutoResetEvent signal) { // Navigate to portal string portalUrl = "website_name"; string portalEmail = "email@email.com"; string portalPassword = "password"; Action action2 = () =&gt; { webBrowser2.Tag = signal; webBrowser2.Navigate(portalUrl); webBrowser2.DocumentCompleted -= WebBrowserDocumentCompleted; webBrowser2.DocumentCompleted += WebBrowserDocumentCompleted; }; webBrowser2.Invoke(action2); signal.WaitOne(); // Login to O365 portal webBrowser2.Invoke(new Action(() =&gt; { HtmlElement head = webBrowser2.Document.GetElementsByTagName("head")[0]; HtmlElement testScript = webBrowser2.Document.CreateElement("script"); IHTMLScriptElement element = (IHTMLScriptElement)testScript.DomElement; element.text = "function PortalLogin() { document.getElementById('userid').value = '" + portalEmail + "'; document.getElementById('password').value = '" + portalPassword + "'; document.getElementById('login').submit(); }"; head.AppendChild(testScript); webBrowser2.Document.InvokeScript("PortalLogin"); })); } ... more functions after this </code></pre> <p>When I step through it, it doesn't seem to be invoking the <code>document.getElementById('login').submit();</code> part of the script "in time". How can I make sure nothing happens until the <code>InvokeScript</code> has <strong>fully</strong> completed?</p> <p>Also- if you see any superfluous code or stuff that can be cleaned up, that's awesome too.</p> <p><strong>EDIT</strong>: Here is DocumentCompleted function.</p> <pre><code>private void WebBrowserDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs Url) { ((AutoResetEvent)((WebBrowser)sender).Tag).Set(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload