in robot-server-plugin/src/main/resources/static/xpathEditor.js [76:126]
constructor() {
this.generators = [
// class
(element) => {
if (element.getAttribute("class")) {
return [new PrioritizedXpath(`//div[@class='${element.getAttribute("class")}']`, 2)]
}
},
// visible text
(element) => {
if (element.getAttribute("visible_text")) {
return element.getAttribute("visible_text").split("||")
.map((it) => new PrioritizedXpath(`//div[contains(@visible_text, '${it.trim()}')]`, 4))
}
},
// visible text key
// (element) => {
// if (element.getAttribute("visible_text_keys")) {
// return element.getAttribute("visible_text_keys").split("||")
// .flatMap(keys => keys.split(" "))
// .map((it) => new PrioritizedXpath(`//div[contains(@visible_text_keys, '${it.trim()}')]`, 3))
// }
// },
//all attributes
(element) => {
return Array.prototype.slice.call(element.attributes)
.filter((a) => a.nodeValue.length > 0)
.flatMap((a) => {
let priority = 3
if (a.nodeValue.length > 30) priority = 4
return [new PrioritizedXpath(`//${element.tagName.toLowerCase()}[@${a.nodeName}='${a.nodeValue}']`, priority)]
})
},
// combination of good attributes
(element) => {
return [new PrioritizedXpath(`//${element.tagName.toLowerCase()}${this._formatAttributes(element)}`, 3)]
},
(element) => {
const result = []
Array.prototype.slice.call(element.attributes).forEach((a) => {
const attrName = a.nodeName
a.nodeValue.split(" ")
.filter((v) => v.length > 0)
.forEach((v) => {
result.push(new PrioritizedXpath(`//${element.tagName.toLowerCase()}[contains(@${attrName}, '${v}')]`, 4))
})
})
return result
}
]
}