title: CefSharp Wait For Element to Appear Javascript Not Triggering Raise Event
body: <p>I've been at this quite a while, have dug everywhere and I'm about at my wits end. The solution seems simple: Inject some javascript code into the chromium browser to wait for an element to appear (the browser has already finished loading and without waiting for the element, my .net code races past the automation parts I want to do on the page), then proceed.</p>
  
  <p>I'm following the examples set <a href="https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Example/ScriptedMethodsBoundObject.cs" rel="nofollow">here</a> and <a href="https://github.com/cefsharp/CefSharp/blob/master/CefSharp.WinForms.Example/BrowserTabUserControl.cs" rel="nofollow">here</a> (see the constructor).</p>
  
  <p>However, the raise event isn't firing like I figured it should be. It's probably due to my javascript code - or it's possible I've missed something somewhere else. </p>
  
  <p>Here is the js code:</p>
  
  <pre><code>private void InjectJsWait(string eventName, string selector, int time, string eventStage)
      {
          string script = @"function waitForElementToDisplay(##SELECTOR##, ##TIME##) {
                                      if(document.querySelector(##SELECTOR##)!=null) {
                                          window.boundEvent.raiseEvent('##EVENTNAME##', {eventStage: ##STAGE##});
                                          return;
                                      }
                                      else {
                                          setTimeout(function() {
                                              waitForElementToDisplay(##SELECTOR##, ##TIME##);
                                          }, ##TIME##);
                                      }
                                  }";
  
          script = Regex.Replace(script, "##SELECTOR##", selector);
          script = Regex.Replace(script, "##TIME##", time.ToString());
          script = Regex.Replace(script, "##EVENTNAME##", eventName);
          script = Regex.Replace(script, "##STAGE##", eventStage);
  
          browser.ExecuteScriptAsync(script);
      }
  </code></pre>
  
  <p>Any help would be greatly appreciated. </p>