MCPcopy
hub / github.com/codeceptjs/CodeceptJS / toXPath

Method toXPath

lib/locator.js:216–230  ·  view source on GitHub ↗

* @param {string} [pseudoSelector] CSS to XPath extension pseudo: https://www.npmjs.com/package/csstoxpath?activeTab=explore#extension-pseudos * @returns {string}

(pseudoSelector = '')

Source from the content-addressed store, hash-verified

214 * @returns {string}
215 */
216 toXPath(pseudoSelector = '') {
217 const locator = `${this.value}${pseudoSelector}`
218 const limitation = [':nth-of-type', ':first-of-type', ':last-of-type', ':nth-last-child', ':nth-last-of-type', ':checked', ':disabled', ':enabled', ':required', ':lang', ':nth-child', ':has']
219
220 if (limitation.some(item => locator.includes(item))) {
221 cssToXPath = require('css-to-xpath')
222 } else {
223 cssToXPath = require('csstoxpath')
224 }
225
226 if (this.isXPath()) return this.value
227 if (this.isCSS()) return cssToXPath(locator)
228
229 throw new Error("Can't be converted to XPath")
230 }
231
232 // DSL
233 /**

Callers 15

orMethod · 0.95
findMethod · 0.95
withChildMethod · 0.95
withDescendantMethod · 0.95
atMethod · 0.95
withTextMethod · 0.95
withTextEqualsMethod · 0.95
withAttrMethod · 0.95
withAttrStartsWithMethod · 0.95
withAttrEndsWithMethod · 0.95
withAttrContainsMethod · 0.95
withClassMethod · 0.95

Calls 3

isXPathMethod · 0.95
isCSSMethod · 0.95
includesMethod · 0.80

Tested by

no test coverage detected