[{"id":"playwrightadvanced-001","courseId":"playwright-advanced","domain":"locators-and-selectors","topic":"Shadow DOM traversal","prompt":"A web component draws its details panel inside an open shadow root. A teammate runs the click below against that panel. What happens?","hint":"Not every selector type is allowed to look past a shadow boundary.","explain":"Selectors differ in how far they search. Some reach into encapsulated component internals by default; others stop at the edge of such a subtree. Check a selector's reach before relying on it.","source":"https://playwright.dev/docs/locators#locate-in-shadow-dom","interaction":{"type":"single"},"options":[{"id":"a","text":"XPath cannot reach inside a shadow root, so the locator matches nothing.","why":"Locating by XPath does not pierce shadow roots, so the div inside the open shadow root is never matched."},{"id":"b","text":"Every selector type pierces open shadow roots, so the locator finds the div and clicks it.","whyNot":"Playwright locators pierce open shadow roots by default, but XPath is a listed exception."},{"id":"c","text":"The XPath matches the x-details host instead, because its shadow content is merged into it.","whyNot":"Shadow content is not merged into the host; an XPath aimed at the div simply has no match."},{"id":"d","text":"The click works only if the shadow root is closed-mode, which XPath can reach.","whyNot":"Closed-mode shadow roots are not supported by locators at all, so this has the rule backwards."}],"answer":"a","explanation":"By default locators pierce open shadow roots; XPath locators do not pierce shadow roots, and closed-mode shadow roots are not supported.","concept":"By default locators pierce open shadow roots; XPath locators do not pierce shadow roots, and closed-mode shadow roots are not supported.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"await page\n  .locator(\"xpath=//div[@id='panel']\")\n  .click();","takeaways":["A locator that works in plain DOM can still miss elements inside a shadow root if its engine does not pierce it."]},{"id":"playwrightadvanced-002","courseId":"playwright-advanced","domain":"locators-and-selectors","topic":"Locator click steps","prompt":"A test runs await page.getByRole('button', { name: 'Save' }).click(). Put these steps of what the click does in the order Playwright performs them.","hint":"Think about what must be true before any pointer input is sent, and what waits come last.","explain":"A single action on a located element runs in stages: some verify and prepare the target, one delivers the input, and a final one may wait on its effects. Think about which stage depends on the rest.","source":"https://playwright.dev/docs/api/class-locator#locator-click","interaction":{"type":"sort","items":[{"text":"Wait for actionability checks on the element, unless the force option is set.","why":"Playwright first waits until the element passes its actionability checks, unless force skips them."},{"text":"Scroll the element into view if needed.","why":"The element must be on screen before the mouse can reach it, so scrolling comes before the input."},{"text":"Use page.mouse to click in the center of the element, or at the specified position.","why":"The mouse input is sent only after the element is ready and in view."},{"text":"Wait for any navigation the click starts to succeed or fail.","why":"Any navigation the click starts is awaited last, once the input has gone out."}]},"options":[],"answer":"o:abcd","explanation":"locator.click() waits for actionability checks, scrolls the element into view if needed, clicks at the center or a given position with page.mouse, then waits for any navigation to succeed or fail.","concept":"locator.click() waits for actionability checks, scrolls the element into view if needed, clicks at the center or a given position with page.mouse, then waits for any navigation to succeed or fail.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["A click can wait or fail at several points, so check the locator's readiness before blaming the click itself."]},{"id":"playwrightadvanced-003","courseId":"playwright-advanced","domain":"locators-and-selectors","topic":"Whitespace in text matching","prompt":"With exact: true, page.getByText('Welcome, John') does not match a span whose text is 'Welcome,   John' with three spaces, because the spacing differs.","hint":"Think about what the matcher does to the text before it compares.","explain":"Text locators compare what a user sees, not raw markup, and apply a fixed treatment to spacing first. The exact option changes how strictly the words must agree; consider which steps it changes.","source":"https://playwright.dev/docs/locators#locate-by-text","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Exact matching compares the raw string, so the three spaces would have to equal the single space in the argument."},{"id":"b","text":"False","why":"Whitespace is normalized even with exact matching: runs of spaces collapse to one, so the strings do match."}],"answer":"b","explanation":"getByText always normalizes whitespace, even with exact: true, collapsing runs of spaces and line breaks and trimming the ends.","concept":"getByText always normalizes whitespace, even with exact: true, collapsing runs of spaces and line breaks and trimming the ends.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Do not write tests that depend on exact spacing inside a text locator; the spacing is normalized first."]},{"id":"playwrightadvanced-004","courseId":"playwright-advanced","domain":"locators-and-selectors","topic":"Deprecated layout selectors","prompt":"A login form has a Password label, with its input to the right. A teammate writes the line below, with no tag name before the layout pseudo-class. What is the most likely result?","hint":"Think about what a rule based only on position can end up hitting.","explain":"Position-based selectors measure where things sit on screen, not what they are. A rule that only describes position can therefore land on whatever happens to lie in that spot.","source":"https://playwright.dev/docs/other-locators#css-matching-elements-based-on-layout","interaction":{"type":"single"},"options":[{"id":"a","text":"It fills the input, because the pseudo-class only considers form fields.","whyNot":"Layout pseudo-classes match by position for any element; they do not restrict results to form fields."},{"id":"b","text":"It targets an empty element between the label and the input, not the input you wanted.","why":"Used alone, a layout pseudo-class most likely matches an empty element in between, not the target input."},{"id":"c","text":"It fills the label, since the label is the anchor and matches itself.","whyNot":"The anchor is only the reference point, and an element is never matched as being to the right of itself."},{"id":"d","text":"It fails with a syntax error, because layout pseudo-classes need a tag name.","whyNot":"The selector is valid as written; a tag name narrows the match but is not required."}],"answer":"b","explanation":"Layout pseudo-classes are most useful alongside a tag such as input; used alone, :right-of(...) most likely matches an empty element in between rather than the target.","concept":"Layout pseudo-classes are most useful alongside a tag such as input; used alone, :right-of(...) most likely matches an empty element in between rather than the target.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","code":"await page\n  .locator(':right-of(:text(\"Password\"))')\n  .fill('secret');","takeaways":["Combine layout pseudo-classes with a tag; on their own they often match a neighboring element instead."]},{"id":"playwrightadvanced-005","courseId":"playwright-advanced","domain":"locators-and-selectors","topic":"XPath parent lookup fragility","prompt":"Markup is a list of items, each holding a label such as <label>Hello</label> inside an <li>. You need the parent <li> of the label that says Hello. Which TWO selectors reach it?","hint":"Consider narrowing candidates by their contents, versus moving out of a matched node.","explain":"A selector usually starts from what is visible and narrows down. To reach a container, you can pick candidates by what they contain, or step out of a found node through the document structure.","source":"https://playwright.dev/docs/other-locators#parent-element-locator","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"page.getByRole('listitem').filter({ has: page.getByRole('list').getByText('Hello') })","whyNot":"The inner locator starts from each list item, so the outer list it names is never inside it."},{"id":"b","text":"page.getByRole('listitem').filter({ has: page.getByText('Hello') })","why":"Filtering the list items by the label they contain is the approach the docs recommend first."},{"id":"c","text":"page.getByText('Hello').locator('css=..')","whyNot":"CSS has no parent selector; the css= prefix forces CSS, which rejects the double dot."},{"id":"d","text":"page.getByText('Hello').locator('xpath=..')","why":"An XPath of double dots steps from the label up to its parent, the li, but it breaks more easily when the DOM changes."},{"id":"e","text":"page.getByRole('listitem').getByText('Hello')","whyNot":"This returns the label inside the item, not the item itself."},{"id":"f","text":"page.getByText('Hello').locator('xpath=../..')","whyNot":"Two steps up from the label reaches the ul, not the li."}],"answer":"bd","explanation":"Prefer locator.filter() with has to reach a parent; xpath=.. from the child also works, but it depends on the DOM structure and is less reliable.","concept":"Prefer locator.filter() with has to reach a parent; xpath=.. from the child also works, but it depends on the DOM structure and is less reliable.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["To find a parent, filter the parent candidates by a child locator before reaching for xpath=.."]}]