* @param {string} [pseudoSelector] CSS to XPath extension pseudo: https://www.npmjs.com/package/csstoxpath?activeTab=explore#extension-pseudos * @returns {string}
(pseudoSelector = '')
| 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 | /** |
no test coverage detected