title: Filtering Puppeter Sharp's ElementHandle[] with async linq
body: <p>I've been rewritting my Selenium Application in Puppeter Sharp to learn more about that framework. My application runs on a site that i haven't access to modifyu its source, I've been only gathering some informations.</p>
  
  <p>Based on that, I wrote a function using Selenium that can filter a desired element inside of a <code>IEnumerable&lt;IWebElement&gt;</code>, this way:</p>
  
  
  
  <pre><code>var element = Driver.FindElements(By.Id("User"))
      .First(x =&gt; 
             x.Text.ToLower().Trim() == "AAA" &amp;&amp;
             x.FindElement(By.Id("contact")).Text.ToLower().Trim() == "BBB")
      .FindElement(By.XPath("../input"));
  </code></pre>
  
  <p>But i was not able to write a code that does the same thing using Puppeteer Sharp. The most accurate approach that I wrote was:</p>
  
  
  
  <pre><code>var users = await Page.QuerySelectorAllAsync("#User");
  var baseElement = users.First(async x =&gt;
      (await x.JsonValueAsync&lt;string&gt;()).ToLower().Trim() == "AAA" &amp;&amp;
      (await (await x.QuerySelectorAsync("#contact")).JsonValueAsync&lt;string&gt;()).ToLower().Trim() == "BBB");
  var element = await baseElement.XPathAsync("../input");
  </code></pre>
  
  <p>The code above still return me an error: </p>
  
  <blockquote>
    <p>Cannot convert async lambda expression to delegate type 'Func'.</p>
  </blockquote>
  
  <p>Yes, it makes sense, but I was not able to found another approach with linq, to make it at least legible and small.</p>
  
  <p><strong>Edit</strong>:</p>
  
  <p>Html example bellow: I need to return the radio input based on Attack Name and Type. I understand that i can write a great, ugly and illegible xpath to query it for me, but i tried to do a more readable and fluent approach to be easier o maintenance.</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="player"&gt;
      &lt;div class="attklist"&gt;
          &lt;h2&gt;Choose an Attack&lt;/h2&gt;
          &lt;ul&gt;
              &lt;li class="batsel" style="cursor: pointer;"&gt;
                  &lt;input type="radio" value="1" name="selected" checked="checked" id="atkopt1"&gt;
                  &lt;label for="atkopt1"&gt;Strength
                      &lt;br&gt;&lt;span class="tbtn tbtn-normal"&gt;normal&lt;/span&gt;
                  &lt;/label&gt;
              &lt;/li&gt;
              &lt;li style="cursor: pointer;"&gt;
                  &lt;input type="radio" value="2" name="selected" id="atkopt2"&gt;
                  &lt;label for="atkopt2"&gt;Strength
                      &lt;br&gt;&lt;span class="tbtn tbtn-fighting"&gt;fighting&lt;/span&gt;
                  &lt;/label&gt;
              &lt;/li&gt;
              &lt;li style="cursor: pointer;"&gt;
                  &lt;input type="radio" value="3" name="selected" id="atkopt3"&gt;
                  &lt;label for="atkopt3"&gt;Spectre Slash
                      &lt;br&gt;&lt;span class="tbtn tbtn-ghost"&gt;ghost&lt;/span&gt;
                  &lt;/label&gt;
              &lt;/li&gt;
              &lt;li style="cursor: pointer;"&gt;
                  &lt;input type="radio" value="4" name="selected" id="atkopt4"&gt;
                  &lt;label for="atkopt4"&gt;Fire Puch
                      &lt;br&gt;&lt;span class="tbtn tbtn-fire"&gt;fire&lt;/span&gt;
                  &lt;/label&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>