title: Simulate two clicks using httpclient C# and pass PKI Certificate
body: <p>Using a client, I want to login to a webpage using PKI certificate. On the website, I would need to agree to an acknowledgement by clicking on a checkbox, then the login button will be enabled to see and then I can click on that. From there, a window will popup for me to select a certificate and input a password and then I can log in.</p>
  <p>On a different website, I was able to press the agree button by doing this:</p>
  <pre><code>using (var client = new HttpClient())
  {
       var content = new FormUrlEncodedContent(new Dictionary&lt;string, string&gt; { { &quot;value&quot;, &quot;agree&quot; } });
       var agreementPost = await client.PostAsync(url, content);
  }
  </code></pre>
  <p>where 'value' is the element of &quot;input&quot; in html and 'agree' is in between the quotes for the value tag.</p>
  <p>For the website I'm working on, the input tag is under several div's, but the tag looks like this:</p>
  <pre><code>&lt;input id=&quot;agree_cb&quot; type=&quot;checkbox&quot; click=&quot;handleOnClick(this);&quot;&gt;
  </code></pre>
  <p>and for the button I press after that, it looks like this:</p>
  <pre><code>&lt;button value=&quot;X509&quot;&gt;&lt;/button&gt;
  </code></pre>
  <p>So my code is this:</p>
  <pre><code>X509Certificate2 cert = GetCertificate();
  HttpClientHandler handler = new HttpClientHandler();
  handler.ClientCertificateOptions = ClientCertificateOption.Manual;
  handler.ClientCertificates.Add(cert);
  
  HttpClient client = new HttpClient(handler);
  var content = new FormUrlEncodedContent(new Dictionary&lt;string, string&gt; 
  { 
      { &quot;id&quot;, &quot;agree&quot; },
      { &quot;value&quot; , &quot;X509&quot;} 
  });
  var agreementPost = await client.PostAsync(entry_url, content);
  
  var connectionEntry = await client.GetAsync(main_URL);
  var output = await connectionEntry?.Content.ReadAsStringAsync();
  </code></pre>
  <p>But when I output it, it outputs the html page as if it never logged in. I'm not sure if I am clicking the buttons or not. I know the PKI certificate is being passed into the client, but I don't know if the timing of it, is correct or not?</p>
  <p>Any help is appreciated</p>