[{"id":"playwrightintermediate-001","courseId":"playwright-intermediate","domain":"locators-and-selectors","topic":"Strictness with multiple matches","prompt":"Calling click() on a locator that matches three buttons clicks the first of them and does not throw.","hint":"Think about what an action that needs one target does when several elements match.","explain":"Locators check how many elements they match before acting on them. Some calls need exactly one target, while others, such as counting, accept any number of matches.","source":"https://playwright.dev/docs/locators#strictness","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Playwright does not pick one of the three for you. A single-target action throws a strictness error when several elements match."},{"id":"b","text":"False","why":"A click needs exactly one element, so the call throws a strictness error and no button is clicked."}],"answer":"b","explanation":"Locators are strict: an action that targets one element throws when more than one matches, while multi-element calls such as count() accept any number of matches.","concept":"Locators are strict: an action that targets one element throws when more than one matches, while multi-element calls such as count() accept any number of matches.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"await page.getByRole('button').click();","takeaways":["An action that needs one target throws when several match; count() is the multi-match exception."]},{"id":"playwrightintermediate-002","courseId":"playwright-intermediate","domain":"locators-and-selectors","topic":"Filtering by text","prompt":"A page has a list item whose text is 'Product 2'. Your code calls filter({ hasText: 'product 2' }) on the list items. What happens?","hint":"Think about whether the filter needs the whole text or only part of it, and how it handles capitals.","explain":"A text filter looks for its string somewhere inside each element, even in nested children. Its rules for matching letters are part of the method's contract, so check them.","source":"https://playwright.dev/docs/locators#filter-by-text","interaction":{"type":"single"},"options":[{"id":"a","text":"It matches the item, because the text filter ignores letter case.","why":"hasText searches for the string anywhere inside the element and compares case-insensitively, so 'product 2' finds 'Product 2'."},{"id":"b","text":"It matches nothing, because hasText compares letters exactly.","whyNot":"hasText is case-insensitive, so differing capitals do not stop a match."},{"id":"c","text":"It throws, because hasText accepts only a regular expression.","whyNot":"hasText takes a plain string or a regular expression, so a string works fine."},{"id":"d","text":"It matches only if 'product 2' is the whole text of the item.","whyNot":"hasText looks for the string inside the element, so extra text around it does not block a match."}],"answer":"a","explanation":"filter({ hasText }) keeps elements whose text contains the string anywhere inside them, including descendants, and matches case-insensitively.","concept":"filter({ hasText }) keeps elements whose text contains the string anywhere inside them, including descendants, and matches case-insensitively.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"await page\n  .getByRole('listitem')\n  .filter({ hasText: 'product 2' })\n  .click();","takeaways":["hasText is a case-insensitive substring match, not an equality check."]},{"id":"playwrightintermediate-003","courseId":"playwright-intermediate","domain":"locators-and-selectors","topic":"Filtering by a child locator","prompt":"Each list item holds an h3 heading and an Add to cart button. Starting from page.getByRole('listitem'), which filter keeps only the item whose heading reads 'Product 2'?","hint":"Ask which filter option accepts a locator, and where the nested search starts.","explain":"A filter can keep an element only when a locator finds a match nested inside it. That nested search starts from each candidate, not from the top of the page, so consider what it can see.","source":"https://playwright.dev/docs/locators#filter-by-childdescendant","interaction":{"type":"single"},"options":[{"id":"a","text":"filter({ has: page.getByRole('heading', { name: 'Product 2' }) })","why":"has keeps an item when a descendant matches the locator, and the heading is a descendant of its item."},{"id":"b","text":"filter({ has: page.getByRole('list').getByText('Product 2') })","whyNot":"The inner locator is searched from inside the item, and an item contains no list, so nothing matches."},{"id":"c","text":"filter({ hasText: page.getByRole('heading', { name: 'Product 2' }) })","whyNot":"hasText takes a string or a regular expression. A locator belongs in has."},{"id":"d","text":"filter({ hasNot: page.getByRole('heading', { name: 'Product 2' }) })","whyNot":"hasNot keeps the items that lack that heading, so it returns the wrong ones."}],"answer":"a","explanation":"filter({ has }) keeps elements that contain a descendant matching another locator; that inner locator is queried from each matched element, not from the document root.","concept":"filter({ has }) keeps elements that contain a descendant matching another locator; that inner locator is queried from each matched element, not from the document root.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Inner locators in has and hasNot start from the outer match, so they cannot reach up to a parent list."]},{"id":"playwrightintermediate-004","courseId":"playwright-intermediate","domain":"locators-and-selectors","topic":"Filtering by missing text","prompt":"A product list has five items marked 'Out of stock' and three in-stock items. Which TWO locators match only the three in-stock items?","hint":"One family of filter options keeps items for what they lack.","explain":"A filter can keep elements by what they contain or by what they lack. Check each expression's direction, and whether it returns every match or only one.","source":"https://playwright.dev/docs/locators#filter-by-not-having-text","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"page.getByRole('listitem').filter({ hasNotText: 'Out of stock' })","why":"hasNotText keeps only the items whose text does not contain the string."},{"id":"b","text":"page.getByRole('listitem').filter({ hasNot: page.getByText('Out of stock') })","why":"hasNot keeps the items with no descendant matching the locator, which drops the marked ones."},{"id":"c","text":"page.getByRole('listitem').filter({ hasText: 'Out of stock' })","whyNot":"hasText keeps the items that contain the string, so this returns the five out-of-stock items."},{"id":"d","text":"page.getByRole('listitem').filter({ hasNotText: 'Out of stock' }).first()","whyNot":"first() keeps a single element, so the other in-stock items are lost."},{"id":"e","text":"page.getByRole('listitem', { hasNotText: 'Out of stock' })","whyNot":"hasNotText belongs to filter(); getByRole only takes role options such as name."},{"id":"f","text":"page.getByRole('listitem').filter({ hasNotText: 'Out of stock' }).or(page.getByRole('listitem').filter({ hasText: 'Out of stock' }))","whyNot":"or() combines both sides, so it matches every item, including the out-of-stock ones."}],"answer":"ab","explanation":"filter({ hasNotText }) and filter({ hasNot }) keep elements that lack the given text or a matching descendant.","concept":"filter({ hasNotText }) and filter({ hasNot }) keep elements that lack the given text or a matching descendant.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use hasNotText or hasNot to exclude elements; getByRole takes role options, not filter options."]},{"id":"playwrightintermediate-005","courseId":"playwright-intermediate","domain":"locators-and-selectors","topic":"Combining locators with and","prompt":"A page has several buttons. Exactly one is a button element whose own title attribute is 'Subscribe'. Which locator matches only that button?","hint":"Think about whether you need elements matching both conditions or either one.","explain":"Two locators can be combined so that an element must satisfy both, or so that it may satisfy either. Each combination gives a different set, so read the intent of the condition before choosing.","source":"https://playwright.dev/docs/locators#matching-two-locators-simultaneously","interaction":{"type":"single"},"options":[{"id":"a","text":"page.getByRole('button').and(page.getByTitle('Subscribe'))","why":"and() keeps only elements that satisfy both locators, here the button with that title."},{"id":"b","text":"page.getByRole('button').or(page.getByTitle('Subscribe'))","whyNot":"or() matches elements that satisfy either locator, so every button comes back."},{"id":"c","text":"page.getByRole('button', { title: 'Subscribe' })","whyNot":"getByRole takes role options such as name; the title attribute is matched with getByTitle."},{"id":"d","text":"page.getByTitle('Subscribe').getByRole('button')","whyNot":"A chained locator searches inside the titled element, and a button does not contain itself."}],"answer":"a","explanation":"locator.and() narrows a locator to elements matching both locators; locator.or() matches elements that match either one or both.","concept":"locator.and() narrows a locator to elements matching both locators; locator.or() matches elements that match either one or both.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use and() to match both role and title on one element; or() widens the match instead."]}]