How to assert that an element's text is not empty in playwright
P粉675258598
2023-08-17 23:11:33
<p>I executed this line of code to verify that there is some text on the title. </p>
<p><code>await expect(page.locator('div.welcome-content > h2')).not.toBeEmpty;</code></p>
<p>But when I execute it, this line of code does nothing, it neither asserts nor returns an error. </p>
The correct way to use the expect function with the .not.toBeEmpty matcher is to put parentheses after .not.toBeEmpty to call the assertion and compare it with the actual value.
If you are using playwright's own assertion library, you can do this: