* @param {number} position * @returns {Locator}
(position)
| 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} |
no test coverage detected