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

Method at

lib/locator.js:273–288  ·  view source on GitHub ↗

* @param {number} position * @returns {Locator}

(position)

Source from the content-addressed store, hash-verified

271 * @returns {Locator}
272 */
273 at(position) {
274 if (position === 0) {
275 throw new Error('0 is not valid element position. XPath expects first element to have index 1')
276 }
277
278 let xpathPosition
279
280 if (position > 0) {
281 xpathPosition = position.toString()
282 } else {
283 // -1 points to the last element
284 xpathPosition = `last()-${Math.abs(position + 1)}`
285 }
286 const xpath = sprintf('(%s)[position()=%s]', this.toXPath(), xpathPosition)
287 return new Locator({ xpath })
288 }
289
290 /**
291 * @returns {Locator}

Callers 5

firstMethod · 0.95
lastMethod · 0.95
locator_test.jsFile · 0.80
within_test.jsFile · 0.80

Calls 2

toXPathMethod · 0.95
toStringMethod · 0.45

Tested by

no test coverage detected