title: Playwright: How to search for an element that has a specific empty tag in the element tree?
body: <p>How to search for an element that has a specific empty tag in the element tree in Playwright tests (using their test-runner)?</p>
  <p>I have tried an empty text filter (obviously not the best idea)</p>
  <pre><code>// variant 1
  page.locator(`[aria-label=&quot;label name&quot;].has(span:text-is(&quot;&quot;))`);
  // variant 2
  page.locator(`[aria-label=&quot;label name&quot;].has(div[role=&quot;button&quot;] span[text=&quot;&quot;])`);
  </code></pre>
  <p>but got error</p>
  <pre><code>locator.textContent: Unexpected token &quot;&quot; while parsing selector &quot;[aria-label=&quot;label name&quot;]&quot;
  </code></pre>
  <p>The only solution that works for me is to check each text content using JS, for example:</p>
  <pre><code>const locator = page.locator('div[role=&quot;button&quot;] &gt;&gt; span');
  const elementsCount = await locator.count();
  for(let i = 0; i &lt; elementsCount; i++) {
    const spanTextContent = await locator.nth(i)?.textContent();
    return spanTextContent === '' ? locator.nth(i) : null;
  }
  </code></pre>
  <p>Another example that gives <code>Unexpected token &quot;&quot; while parsing selector</code> error:</p>
  <pre><code>    locator = page.locator(`body:has(div[class=&quot;L3eUgb&quot;] &gt;&gt; a &gt;&gt; text=&quot;About&quot;)`);
      console.log(`locator.count(): ${await locator.count()}`);
  </code></pre>