View it on GitHub npm install css2xpath


CSS extras

!> Parent a !> .//a/parent::* a !> b .//a/parent::b
! Ancestors a ! .//a/ancestor-or-self::* a ! b .//a/ancestor-or-self::b
!^ Last Child a !^ .//a/child::*[last()]/self::* a !^ b .//a/child::*[last()]/self::b
!~ Preceeding Siblings a !~ .//a/preceding-sibling::* a !~ .//a/preceding-sibling::b
!+ Preceeding Adjacent Siblings
a !+ .//a/preceding-sibling::*[1]/self::*
a !+ b .//a/preceding-sibling::*[1]/self::b
:after Appears after
a:after(b) .//a[count(preceding::b) > 0]
:after-sibling Appears after sibling
a:after-sibling(b) .//a[count(preceding-sibling::b) > 0]
:before Appears before
a:before(b) .//a[count(following::b) > 0]
:before-sibling Appears before sibling
a:before-sibling(b) .//a[count(following-sibling::b) > 0]
:contains Contains text
a:contains("Exact Case") .//a[contains(normalize-space(),"Exact Case")]
a:icontains("CaSe InSenSiTiVe") .//a[contains(translate(normalize-space(), 'ABC..', 'abc..'),translate("CaSe InSenSiTiVe", 'ABC..', 'abc..'))]
:starts-with Starts with text
a:starts-with("Exact Case") //a[starts-with(normalize-space(),"Exact Case")]
a:istarts-with("CaSe InSenSiTiVe") .//a[starts-with(translate(normalize-space(), 'ABC..', 'abc..'),translate("CaSe InSenSiTiVe", 'ABC..', 'abc..'))]
:ends-with Ends with text
a:ends-with("Exact Case") //a[ends-with(normalize-space(),"Exact Case")]
a:iends-with("CaSe InSenSiTiVe") .//a[ends-with(translate(normalize-space(), 'ABC..', 'abc..'),translate("CaSe InSenSiTiVe", 'ABC..', 'abc..'))]
:first First in set
a b:first (.//a//b)[1]
a b:first(3) (.//a//b)[position()<=3]
a b:limit(3) (.//a//b)[position()<=3]
:has Contains child node
a:has(b) .//a[count(.//b) > 0]
:has-sibling Has sibling node
a:has-sibling(b) .//a[count(preceding-sibling::b) > 0 or count(following-sibling::b) > 0]