===
open selectors page
%require
===
plwr -S plwr-test open "http://localhost:8599/selectors.html"
---

===
has-text pseudo-class
===
plwr -S plwr-test text 'li:has-text("Walk dog")'
---
Walk dog

===
nth=0 picks first match
===
plwr -S plwr-test text 'li.item >> nth=0'
---
Buy milk

===
nth=1 picks second match
===
plwr -S plwr-test text 'li.item >> nth=1'
---
Walk dog

===
compound class selector
===
plwr -S plwr-test count 'li.item.done'
---
2

===
descendant combinator
===
plwr -S plwr-test text '.card:has-text("Section A") p'
---
Hello world

===
child combinator >
===
plwr -S plwr-test count '#list > li'
---
3

===
adjacent sibling combinator +
===
plwr -S plwr-test count '.mixed-children span + p'
---
2

===
general sibling combinator ~
===
plwr -S plwr-test count '.mixed-children span ~ p'
---
2

===
attribute exact match [attr=val]
===
plwr -S plwr-test count 'input[type=text]'
---
1

===
attribute starts with [attr^=val]
===
plwr -S plwr-test count "a[href^='/']"
---
4

===
attribute ends with [attr$=val]
===
plwr -S plwr-test count "a[href$=en]"
---
1

===
attribute contains [attr*=val]
===
plwr -S plwr-test count "a[href*=example]"
---
1

===
attribute presence [attr]
===
plwr -S plwr-test count 'a[data-external]'
---
1

===
:not pseudo-class
===
plwr -S plwr-test count 'li.item:not(.done)'
---
1

===
:has pseudo-class
===
plwr -S plwr-test count '.card:has(h2:has-text("Section B"))'
---
1

===
:first-child
===
plwr -S plwr-test text '#list li:first-child'
---
Buy milk

===
:last-child
===
plwr -S plwr-test text '#list li:last-child'
---
Clean house

===
:visible
===
plwr -S plwr-test count 'li:visible'
---
6

===
:checked
===
plwr -S plwr-test count 'input:checked'
---
1

===
:disabled
===
plwr -S plwr-test count 'input:disabled'
---
1

===
:enabled
===
plwr -S plwr-test count 'input:enabled'
---
3

===
:required
===
plwr -S plwr-test count 'input:required'
---
1

===
:empty
===
plwr -S plwr-test count 'div:empty'
---
1

===
data attributes (no quotes around value)
===
plwr -S plwr-test text '[data-testid=login-form] [data-action=submit]'
---
Submit

===
aria-label attribute
===
plwr -S plwr-test exists 'nav[aria-label=breadcrumb]'
---

===
aria-current attribute
===
plwr -S plwr-test text '[aria-current=page]'
---
Widget

===
label for attribute
===
plwr -S plwr-test text 'label[for=terms]'
---
I agree to the terms

===
HTML5 semantic elements
===
plwr -S plwr-test text 'summary'
---
Click to expand

===
text= selector shorthand
===
plwr -S plwr-test exists 'text=Walk dog'
---

===
:nth-match picks from multiple matches
===
plwr -S plwr-test text ':nth-match(.mixed-children span, 2)'
---
Second span

===
exists returns 0 for matching selector
===
plwr -S plwr-test exists '.card:has-text("Goodbye")'
---

===
exists returns 1 for non-matching selector
===
! plwr -S plwr-test exists '.card:has-text("Nonexistent")'
---

===
>> chains Playwright selectors
===
plwr -S plwr-test text '#data-table >> tr:has-text("Bob") >> td.status'
---
Inactive

===
attr reads type
===
plwr -S plwr-test attr 'input[placeholder=Email]' type
---
email

===
attr reads placeholder
===
plwr -S plwr-test attr 'input[type=text]' placeholder
---
Name

===
attr reads class
===
plwr -S plwr-test attr '#list li >> nth=0' class
---
item done

===
attr reads data attribute
===
plwr -S plwr-test attr '[data-testid=login-form]' data-count
---
3

===
attr reads href with special characters
===
plwr -S plwr-test attr 'a[data-external]' href
---
https://example.com/page?q=1&lang=en

===
count table rows via child combinator chain
===
plwr -S plwr-test count '#data-table > tbody > tr'
---
4

===
count active statuses with compound selector
===
plwr -S plwr-test count 'td.status.active'
---
3

===
has-text with >> chain finds nested content
===
plwr -S plwr-test text 'tr:has-text("Carol") >> td.status'
---
Active

===
css= prefix: last-of-type
===
plwr -S plwr-test text 'css=.mixed-children span:last-of-type'
---
Third span

===
css= prefix: first-of-type
===
plwr -S plwr-test text 'css=.mixed-children p:first-of-type'
---
A paragraph

===
css= prefix: nth-of-type
===
plwr -S plwr-test text 'css=.mixed-children span:nth-of-type(2)'
---
Second span

===
css= prefix: nth-last-child
===
plwr -S plwr-test text 'css=#list li:nth-last-child(1)'
---
Clean house

===
css= prefix: :is() pseudo-class
===
plwr -S plwr-test count 'css=:is(.card, .mixed-children)'
---
3

===
css= prefix: quoted attribute values
===
plwr -S plwr-test text 'css=[data-testid="login-form"] [data-action="submit"]'
---
Submit

===
css= prefix: nth-child(odd)
===
plwr -S plwr-test count 'css=#list li:nth-child(odd)'
---
2
