Search code examples
typescriptcss-selectorsplaywright

Playwright trying to check if element is selected or not from the attached html


> <div id="ad-item-list" class="ad-item-list"> <div
> class="ad-search-item  " atdelegate="d185"> AMP </div> <div
> class="ad-search-item  " atdelegate="d186"> VLC </div> <div
> class="ad-search-item ad-selected " atdelegate="d187"> MMK </div> <div
> class="ad-search-item  " atdelegate="d188"> MED </div> <div
> class="ad-search-item  " atdelegate="d189"> LED </div> <div
> class="ad-search-item  " atdelegate="d190"> SED </div> <div
> class="ad-search-item  " atdelegate="d191"> DED </div> </div>

what css locator and playwright code can be used to get the value that is selected in this case MMK


Solution

  • await page.locator(".ad-search-item.ad-selected).toHaveText("MMK").

    Which would assert that the selector has the given text.