You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{selectors}from'playwright'importxpath3from'playwright-xpath'selectors.register('xpath3',xpath3);(async()=>{awaitpage.setContent('<button>Click me</button>')// (the starts-with function is only available in xpath 2 and above)awaitpage.click("xpath3=//button[starts-with(., 'Click')]")})()
features
xpath 3.1
currently, all browsers (and playwright) only support xpath 1.0. however there are many useful features that were added in xpath 2 and above which are now supported thanks to fontoxpath
svg support
due to how xml namespaces work, svg elements do not work when using xpath on html. to work around this, the playwright-xpath selector engine allows you to specify the svg prefix:
awaitpage.setContent('<svg><text>asdf</text></svg>')awaitpage.waitForSelector('xpath=//svg/text')// doesn't workawaitpage.waitForSelector('xpath3=//svg/text')// doesn't workawaitpage.waitForSelector('xpath=//svg:svg/svg:text')// doesn't workawaitpage.waitForSelector('xpath3=//svg:svg/svg:text')// works