MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / buildLocatorString

Function buildLocatorString

lib/helper/Playwright.js:4177–4194  ·  view source on GitHub ↗
(locator)

Source from the content-addressed store, hash-verified

4175export default Playwright
4176
4177export function buildLocatorString(locator) {
4178 if (locator.isXPath()) {
4179 // Make XPath relative so it works correctly within scoped contexts (e.g. within()).
4180 // Playwright's XPath engine auto-converts "//..." to ".//..." when the root is not a Document,
4181 // but only when the selector starts with "/". Locator methods like at() wrap XPath in
4182 // parentheses (e.g. "(//...)[position()=1]"), bypassing that auto-conversion.
4183 // We fix this by prepending "." before the first "//" that follows any leading parentheses.
4184 const value = locator.value.replace(/^(\(*)\/\//, '$1.//')
4185 return `xpath=${value}`
4186 }
4187 if (locator.isShadow()) {
4188 // Convert shadow locator to CSS with >> chaining operator
4189 // Playwright pierces shadow DOM by default, >> chains selectors
4190 // { shadow: ['my-app', 'my-form', 'button'] } => 'my-app >> my-form >> button'
4191 return locator.value.join(' >> ')
4192 }
4193 return locator.simplify()
4194}
4195
4196/**
4197 * Handles role locator objects by converting them to Playwright's getByRole() API

Callers 11

_withinBeginMethod · 0.85
dragAndDropMethod · 0.85
_contextLocatorMethod · 0.85
waitForElementMethod · 0.85
waitForVisibleMethod · 0.85
waitForInvisibleMethod · 0.85
waitToHideMethod · 0.85
switchToMethod · 0.85
findElementsFunction · 0.85
findElementFunction · 0.85

Calls 3

isXPathMethod · 0.80
isShadowMethod · 0.80
simplifyMethod · 0.65

Tested by

no test coverage detected