title: How to login and navigate in code with CefSharp
body: <p>I am using CefSharp in a WPF application and want to load a website, login and then navigate to a part of the same website. Loading the website and logging in is working fine. But when I try to navigate to a specific URL, I am not logged in anymore. This is not the case when I manually click on links in the CefSharp Browser Control. Here is what I basically do:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class MainWindow
  {
     public MainWindow()
     {
         Cef.Initialize(new CefSettings()
         {
              CachePath = "C:\\Users\\Documents\\CefCachePath"
         });
         InitializeComponent();
         AutoNavigation()
     }
  
     private async void AutoNavigation()
     {
         await InvokeBrowserActionAsync(browser, () =&gt; browser.Address = loginUrl);
         await InvokeBrowserActionAsync(browser, () =&gt; browser.ExecuteScriptAsync(loginScript);
         await InvokeBrowserActionAsync(browser, () =&gt; browser.Address = targetUrl);
     }
  
      public static Task InvokeBrowserActionAsync(ChromiumWebBrowser browser, Action action)
      {
          var tcs = new TaskCompletionSource&lt;bool&gt;();
          EventHandler&lt;NavStateChangedEventArgs&gt; handler = null;
          handler += (sender, args) =&gt;
          {
              if (!args.IsLoading)
              {
                  browser.NavStateChanged -= handler;
                  tcs.TrySetResult(true);
              }
          };
          browser.NavStateChanged += handler;
          action.Invoke();
          return tcs.Task;
      }
  }
  </code></pre>
  
  <p>Thank you for your help</p>