| 98 | } |
| 99 | |
| 100 | function buildXPath(input, options) { |
| 101 | const literal = xpathLocator.literal(input) |
| 102 | if (options.field) return Locator.field.byText(literal) |
| 103 | if (options.click || options.clickable) return Locator.clickable.wide(literal) |
| 104 | if (options.checkable) return Locator.checkable.byText(literal) |
| 105 | if (options.select) { |
| 106 | return Locator.select.byVisibleText(literal).replace(/\.\/(option|optgroup)/g, './/$1') |
| 107 | } |
| 108 | |
| 109 | if (options.xpath) return new Locator({ xpath: input }).toXPath() |
| 110 | if (options.css) return new Locator({ css: input }).toXPath() |
| 111 | |
| 112 | const loc = new Locator(input) |
| 113 | if (loc.type === 'fuzzy') { |
| 114 | return xpathLocator.combine([Locator.clickable.wide(literal), Locator.field.byText(literal)]) |
| 115 | } |
| 116 | return loc.toXPath() |
| 117 | } |
| 118 | |
| 119 | function htmlToDoc(html) { |
| 120 | const p5doc = parse5.parse(html, { sourceCodeLocationInfo: true }) |