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

Method toAbsoluteXPath

lib/element/WebElement.js:468–499  ·  view source on GitHub ↗

* Normalize locator for element search * @param {string|Object} locator Locator to normalize * @returns {string} Normalized CSS selector * @private

()

Source from the content-addressed store, hash-verified

466 * @private
467 */
468 async toAbsoluteXPath() {
469 const xpathFn = (el) => {
470 const parts = []
471 let current = el
472 while (current && current.nodeType === Node.ELEMENT_NODE) {
473 let index = 0
474 let sibling = current.previousSibling
475 while (sibling) {
476 if (sibling.nodeType === Node.ELEMENT_NODE && sibling.tagName === current.tagName) {
477 index++
478 }
479 sibling = sibling.previousSibling
480 }
481 const tagName = current.tagName.toLowerCase()
482 const pathIndex = index > 0 ? `[${index + 1}]` : ''
483 parts.unshift(`${tagName}${pathIndex}`)
484 current = current.parentElement
485 }
486 return '//' + parts.join('/')
487 }
488
489 switch (this.helperType) {
490 case 'playwright':
491 return this.element.evaluate(xpathFn)
492 case 'puppeteer':
493 return this.element.evaluate(xpathFn)
494 case 'webdriver':
495 return this.helper.browser.execute(xpathFn, this.element)
496 default:
497 throw new Error(`Unsupported helper type: ${this.helperType}`)
498 }
499 }
500
501 async toOuterHTML() {
502 switch (this.helperType) {

Callers 1

fetchDetailsMethod · 0.80

Calls 1

evaluateMethod · 0.80

Tested by

no test coverage detected