Search code examples
puppeteerplaywright

How to check with puppeteer or playwright if an element is of a specific color?


I have an element that has this style color: #dc7709 and I want to check if that element's text is of that color. How do I do that with Puppeteer or playwright?


Solution

  • You can use window.getComputedStyle. Notice that it will return an rgb value:

     assert(await page.$eval('span', e => getComputedStyle(e).color)).toBe('rgb(220, 119, 9)');