ff-dom 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cdn.js +1 -1
- package/dist/types/browser/browser/xpath.d.ts +9 -6
- package/dist/types/browser/utils/cssSelector.d.ts +10 -10
- package/dist/types/browser/utils/xpath.d.ts +2 -2
- package/dist/types/browser/utils/xpathHelpers.d.ts +12 -0
- package/dist/types/node/node/xpath.d.ts +14 -2
- package/dist/types/node/utils/getElementsFromHTML.d.ts +17 -0
- package/dist/types/node/utils/xpath.d.ts +29 -0
- package/dist/types/node/utils/xpathHelpers.d.ts +101 -0
- package/dist/xpath.mjs +1 -1
- package/dist/xpath.mjs.map +1 -1
- package/package.json +70 -70
- package/tsconfig.json +1 -1
package/dist/index.cdn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){"use strict";const t=/^[\S]+( [\S]+)*$/gi;const n={};let l,a=new Map,r=[];const o=e=>/\d/.test(e),s=e=>{const t=e?.textContent;return t},i=e=>e?.childNodes[0]?.nodeValue||"",c=(e,t,l,a=!1)=>{try{let r;if(void 0!==n[e])r=n[e];else{r=(9===l.nodeType?l:l.ownerDocument).evaluate(`count(${e})`,l,null,XPathResult.NUMBER_TYPE,null).numberValue,n[e]=r}if(a&&Array.isArray(t)){if(r>1){const n=y(e,l,!0);let a,r=0;if(n instanceof XPathResult)for(;(a=n?.iterateNext())&&(!t.includes(a)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return y(e,l)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},u=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},m=e=>{const t=e.split("");let n=t.length;const l=[];for(;"["!==t[n-2];)l.push(t[n-2]),n--;l.reverse();let a="";for(let e=0;e<l.length;e++)a+=l[e];const r=a.length+2;let o=e.slice(0,e.length-r);return o=o.startsWith("(")&&o.endsWith(")")?o.slice(1,-1):e,o},h=(e,t,n,l)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let r=0;if(l){if(1===c(`${e}[${l}]`,t,n))return`${e}[${l}]`;if(1===c(`(${e})[${l}]`,t,n))return`(${e})[${l}]`}const o=a.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s;for(;s=o.iterateNext();)if(r++,s.isSameNode(t))return 1===c(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===c(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},f=e=>(e=(e=(e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(e)).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim()).split("/")[0].trim(),d=e=>e?e.replace(/\s\s+/g," ").trim():e,g=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},p=(e,t,n)=>!(!e?.value||"boolean"==typeof e?.value||["true","false","on","off","flntooltip"].some(t=>t===e.value)||["type","style","locator-data-tooltip","value"].some(t=>t===e.name)||r?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name)||0===e?.name?.indexOf("on")&&e?.name?.length>3||"function"==typeof e.value||n&&o(e.value)),$=e=>e instanceof SVGElement,v=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,y=(e,t,n=!1)=>{let l=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(l=t.host??t);const a=l.nodeType===Node.DOCUMENT_NODE?l:l.ownerDocument;return n?a.evaluate(e,l,null,XPathResult.ANY_TYPE,null):a.evaluate(e,l,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},b=(e,n,l,a,r,s)=>{if(a){const{tagName:i}=e;let m,h="";const f=[];let g;if(a&&(!s||!o(a))&&(g=t.test(a)?`//${i}[${l}=${u(a)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${l})=${u(d(a)).trim()}`,$(e),e.tagName.toLowerCase()),m=c(g,e,n),1===m&&!r))return g;if(a&&s){const o=a.split(" ");if(o?.length)if(1===o.length){const s=[...new Set(o[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&d(s[0].trim())?.length>1&&a.startsWith(s[0])&&(h=t.test(s[0])?`starts-with(${l},${u(s[0]).trim()})`:`starts-with(${l},${u(d(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&d(s[s.length-1].trim())?.length>1&&a.endsWith(s[s.length-1])&&(h=t.test(s[s.length-1])?`ends-with(${l},${u(s[s.length-1]).trim()})`:`ends-with(${l},${u(d(s[s.length-1])).trim()})`),h?.length&&(g=$(e)?`//*[local-name()='${i}' and ${h}]`:`//${i}[${h}]`,m=c(g,e,n),1===m&&!r))return g}else{const s=o.length%2==0?o.length/2:o.length%2,f=o.slice(0,s).join(" ");let p=[...new Set(f.match(/([^0-9]+)/g))];if(p?.length&&p[0]&&d(p[0].trim())?.length&&a.startsWith(p[0])&&(h=t.test(p[0])?`starts-with(${l},${u(p[0]).trim()})`:`starts-with(${l},${u(d(p[0])).trim()})`),h?.length&&(g=$(e)?`//*[local-name()='${i}' and ${h}]`:`//${i}[${h}]`,m=c(g,e,n),1===m&&!r))return g;const v=o.slice(s,o.length-1).join(" ");if(p=[...new Set(v.match(/([^0-9]+)/g))],p?.length&&p[0]&&d(p[0].trim())?.length>3&&a.endsWith(p[0])&&(h=t.test(p[0])?`ends-with(${l},${u(p[0]).trim()})`:`ends-with(${l},${u(d(p[0])).trim()})`),h?.length&&(g=$(e)?`//*[local-name()='${i}' and ${h}]`:`//${i}[${h}]`,m=c(g,e,n),1===m&&!r))return g}}if(a&&s&&o(a)){const o=[...new Set(a.match(/([^0-9]+)/g))];if(o?.length)for(let e=0;e<o?.length;e++)o[e]&&d(o[e].trim())?.length>1&&(t.test(o[e])?f.push(`contains(${l},${u(o[e].trim()).trim()})`):f.push(`contains(${l},${u(d(o[e])).trim()})`));if(f?.length&&(g=$(e)?`//*[local-name()='${i}' and ${f.join(" and ")}]`:`//${i}[${f.join(" and ")}]`,m=c(g,e,n),1===m&&!r))return g}if(g=$(e)?`//*[local-name()='${i}' and text()]`:`//${i}[text()]`,m=c(g,e,n),1===m&&!r)return g}},N=(e,t)=>{try{if(!e)return"";let n=$(e)?`/*[local-name()='${e.tagName}']`:`/${e.tagName}`;if(e.parentElement){const t=Array.prototype.slice.call(e.parentElement.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}else if(e instanceof HTMLElement&&e.offsetParent){const t=Array.prototype.slice.call(e.offsetParent.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}return N(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},E=(e,t,n,l=!1,r)=>{try{if(a.has(e))return a.get(e);const s=[];let m=e;for(;m;){let a="",f=!1,g=e===m?r??m.attributes:m.attributes;for(const e of Array.from(g))if(p(e,m,l)){let l=e.nodeValue;l=l?.replace("removePointers","")??"";const r=e.name;a=C(m,r,l);let o=0;if(a&&(o=c(a,m,t),1===o)){s.unshift(v(a)),f=!0;break}if(o>1&&n&&(a=h(a,m,t,o),a)){s.unshift(v(a)),f=!0;break}}if(m.textContent)if(!l||l&&!o(m.textContent)){a=new RegExp(/^[\S]+( [\S]+)*$/gi).test(m.textContent)?$(m)?`//*[local-name()='${m.tagName}' and .=${u(i(m))}]`:`//${m.tagName||"*"}[.=${u(i(m))}]`:$(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${u(i(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${u(i(m))}]`;let e=c(a,m,t);if(1===e)return a;if(e>1&&n)return a=h(a,m,t,e),a}else{let e=[];const l=[...new Set(i(m).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&d(l[t].trim())&&(r.test(l[t])?e.push(`contains(.,${u(l[t].trim()).trim()})`):e.push(`contains(.,${u(d(l[t])).trim()})`));if(e?.length){a=$(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`;let l=c(a,m,t);if(1===l)return a;if(l>1&&n)return a=h(a,m,t,l),a}}if(f)break;{let e=$(m)?`/*[local-name()='${m.tagName}']`:`/${m.tagName}`;if(m.parentElement){const t=Array.from(m.parentElement.children).filter(e=>e.tagName===m.tagName);if(t.length>1){e+=`[${t.indexOf(m)+1}]`}}s.unshift(e)}m=m.parentElement}const f=`${s.join("")}`;return a.set(e,f),f}catch(e){return console.log(e),null}},x=(e,n)=>{const l=[];let a="";if(e&&!o(e.value)&&"function"!=typeof e.nodeValue){const r=[...new Set(e.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&d(r[n].trim())?.length>2&&(t.test(r[n])?l.push(`contains(@${e.name},${u(r[n].trim())})`):l.push(`contains(@${e.name},${u(d(r[n])).trim()})`));if(l?.length)return a=$(n)?`//*[local-name()='${n.tagName}' and ${l.join(" and ")}]`:`//${n.tagName}[${l.join(" and ")}]`,a}},S=(e,n,l,a)=>{try{const r=[];if(l.length>1)for(const o of l)if(p(o,e,a)){const l=o.nodeValue;t.test(l)?"class"===o.nodeName?r.push(`contains(@${o.nodeName},"${l}")`):r.push(`@${o.nodeName}="${l}"`):r.push(`normalize-space(@${o.nodeName})="${l}"`);const a=$(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let s;try{s=c(a,e,n)}catch(e){continue}if(1===s&&!a.includes("and"))return"";if(1===s&&a.includes("and"))return a}}catch(e){console.log(`'${JSON.stringify(e,null,2)}'`)}},w=(e,n,l)=>{let a=$(e),r="";if(p(n,e,l)){let l=n.value;l=l.replace("removePointers","");const o=n.name;r=t.test(l)?a?`*[local-name()='${e.tagName}' and @${o}=${u(l)}]`:`${e.tagName||"*"}[@${o}=${u(l)}]`:a?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${u(l)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${u(l)}]`}return r},k=(e,n)=>{if(!e.textContent)return"";const l=i(e);let a;return a=t.test(l)?$(e)?`//*[local-name()='${e.tagName}' and .=${u(l)}]`:`//${e.tagName||"*"}[.=${u(l)}]`:$(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${u(l)}]`:`//${e.tagName||"*"}[normalize-space(.)=${u(l)}]`,a},R=e=>{const t=s(e)?.trim(),n=t?u(f(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},C=(e,t,n)=>{const l=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";return n&&(a=l.test(n)?"class"===t?$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`:$(e)?`//*[local-name()='${e.tagName}' and @${t}=${u(n)}]`:`//${e.tagName||"*"}[@${t}=${u(n)}]`:$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`),a},P=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,A=(e,n,l)=>{let a;const r=[];if(e.textContent&&(!l||l&&!o(e.textContent))&&(t.test(e.textContent)?(a=$(e)?`*[local-name()='${e.tagName}' and .=${u(s(e))}]`:`${e.tagName}[.=${u(s(e))}]`,a&&r.push({key:"getReferenceElementsXpath",value:a})):(a=$(e)?`*[local-name()='${e.tagName}' and ${R(e)})]`:`${e.tagName}[${R(e)}]`,a&&r.push({key:"getReferenceElementsXpath",value:a}))),e.attributes)for(const t of Array.from(e.attributes))if(p(t,e,l)){let n=t.nodeValue;if(n){n=n.replace("removePointers","");const l=t.name;a="class"===l?$(e)?`*[local-name()='${e.tagName}' and contains(@${l},${u(n)})]`:`${e.tagName}[contains(@${l},${u(n)})]`:$(e)?`*[local-name()='${e.tagName}' and @${l}=${u(n)}]`:`${e.tagName}[@${l}=${u(n)}]`,a&&r.push({key:"getReferenceElementsXpath",value:a})}}if(!r?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=S(e,n,Array.prototype.slice.call(e.attributes),l);t&&r.push({key:"getReferenceElementsXpath",value:t})}}if(!r?.length){const n=[];let a;const s=$(e);if(e.textContent&&l&&o(e.textContent)){const l=[...new Set(e.textContent.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&d(l[e].trim())?.length>1&&(t.test(l[e])?n.push(`contains(.,${u(l[e]).trim()})`):n.push(`contains(.,${u(d(l[e])).trim()})`));n?.length&&(a=s?`//*[local-name()='${s}' and ${n.join(" and ")}]`:`//${s}[${n.join(" and ")}]`,a&&r.push({key:"getReferenceElementsXpath",value:a}))}}if(!r?.length){const t=((e,t,n,l)=>{const a=Array.prototype.slice.call(e),r=[];try{a.map(e=>{if(p(e,t,l)){const n=x(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(e.attributes,e,0,l);t?.length&&r.concat(t)}return r},O=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1"),X=(e,t)=>{let n=t,l=1;for(;l>0;){const t=e[++n];"("==t?l++:")"==t&&l--}return n},D={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:A,getAbsoluteXPath:N,getRelativeXPath:E,getCombinationXpath:x,getAttributeCombinationXpath:S,getElementFromXpath:y,isSvg:$,findXpathWithIndex:h,isNumberExist:o,getTextContent:s,getCountOfXPath:c,normalizeXPath:O,getShadowRoot:g,escapeCharacters:u,removeParenthesis:m,checkBlockedAttributes:p,getRelationship:(e,t)=>{let n=e.compareDocumentPosition(t);return 2===n?"preceding":4===n?"following":8===n?"ancestor":16===n?"descendant":32===n?"self":""},findMatchingParenthesis:X,deleteGarbageFromInnerText:f,replaceTempAttributes:v,createObserver:e=>{l=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&($(t.target)&&t.oldValue?.trim()===t.target.classList.value?.trim()||"marked-element-temp"===t.target.classList?.value?.replace(t.oldValue,"").trim()||"marked-element-temp"===t?.oldValue?.replace(t.target.classList?.value,"").trim())||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||r.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{l?.observe(e,t)},stopObserver:()=>{l?.disconnect()},modifiedElementAttributes:r,cspEnabled:!1};let T=[],j=[],L=new Map,V=new Map;const _=new Map,Y=(e,t,n,l,a,r)=>{if(e){let o;o="parent"===r?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of o){L?.get(e)||L.set(e,c(e,n,l));const t=L?.get(e);if(1===t)return e;if(t>1&&(j.length?t<j[0].count&&(j.pop(),j.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):j.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!T.length){const r=h(e,n,l,t);r&&1===c(r,n,l)&&T.push({key:"relative xpath by unique parent "+(a?"index":""),value:r})}}}return null},M=(e,n,l,a,r,s)=>{try{if(_.has(e))return _.get(e);const m=[];let h=e;for(;h&&1===h.nodeType;){const e=!1;for(const e of Array.from(h.attributes))if(p(e,h,a)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const a=e.name,o=C(h,a,t);let i;try{i=Y(o,r,l,n,s,"parent")}catch(e){continue}if(i)return i}if(h.textContent&&!h.textContent)if(!a||a&&!o(h.textContent)){let e;e=t.test(h.textContent)?$(h)?`//*[local-name()='${h.tagName}' and .=${u(i(h))}]`:`//${h.tagName||"*"}[.=${u(i(h))}]`:$(h)?`//*[local-name()='${h.tagName}' and normalize-space(.)=${u(i(h))}]`:`//${h.tagName||"*"}[normalize-space(.)=${u(i(h))}]`;const a=Y(e,r,l,n,s,"parent");if(a)return a}else{const e=[],t=[...new Set(i(h).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&d(t[n].trim())&&(a.test(t[n])?e.push(`contains(.,${u(t[n].trim()).trim()})`):e.push(`contains(.,${u(d(t[n])).trim()})`));if(e?.length){const t=$(h)?`//*[local-name()='${h.tagName}' and ${e.join(" and ")}]`:`//${h.tagName||"*"}[${e.join(" and ")}]`,a=Y(t,r,l,n,s,"parent");if(a)return a}}if(!e){const e=$(h)?`/*[local-name()='${h.tagName}']`:`/${h.tagName}`;m.unshift(e)}h=h.parentElement}const f=m.join("")+r;if(1===c(f,e,n))return _.set(e,f),f}catch(e){return console.error(e),null}},I=(e,t,n,l)=>{const a=new Map;if(a.has(e))return a.get(e);const r=[];let o=e;try{for(;o&&1===o.nodeType;){if(!o.tagName)return"";let e=!1;for(const n of Array.from(o.attributes))if(p(n,o,l)){let l=n.nodeValue;l=l?.replace("removePointers","")??"";const a=n.name,s=C(o,a,l);let i;try{i=c(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=k(o);if(n){if(1===c(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=$(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}const s=r.join("");return a.set(e,s),s}catch(e){return console.log(e),null}},q=(e,t,n)=>{const l=[];let a;const r=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?r.unshift(e.firstElementChild):null!=e.nextElementSibling&&r.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&r.unshift(t.nextElementSibling);try{do{let e=!1;for(a=r.pop();null!==a;){for(const n of Array.from(a.attributes))if(p(n,a,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=C(a,o,r);let i;try{i=c(s,a,t)}catch(e){continue}if(1===i){e=!0,l.push(s);break}}if(!e&&a.textContent&&!n.textContent){const n=k(a);if(n){if(1===c(n,a,t)){e=!0,l.push(n);break}}}if(e)break;{const e=$(a)?`/*[local-name()='${a.tagName}']`:`/${a.tagName}`;l.push(e),null!=a.firstElementChild?(r.push(a.nextElementSibling),a=a.firstElementChild):a=a.nextElementSibling}}}while(r.length>0);const o=l.join("");return V.set(e,o),o}catch(e){return console.log(e),null}},H=(e,t,n,l)=>{try{const a=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==a;r=r.nextElementSibling)W(r,e,t,l,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==a;r=r.previousElementSibling)W(r,e,t,l,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},W=(e,t,n,l,a,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=w(e,{name:t.name,value:t.value},r);if(o){o+=`/${a}::${l}`;const t=c(o,e,n);if(1===t)return void T.push({key:`xpath by ${a}`,value:o});t>1&&(j.length?t<j[0].count&&(j.pop(),j.push({key:`relative xpath by ${a}`,value:o,count:t})):j.push({key:`relative xpath by ${a}`,value:o,count:t}))}}if(!r){let t;if(t=w(e,{name:"text",value:e.textContent},r),t){const l=c(t,e,n);if(1===l)return void T.push({key:`xpath by ${a}`,value:t});l>1&&(j.length?l<j[0].count&&(j.pop(),j.push({key:`relative xpath by ${a}`,value:t,count:l})):j.push({key:`relative xpath by ${a}`,value:t,count:l}))}}}catch(e){console.log(`${a} xpath-error`,e)}};function z(e,t,n,l){const{tagName:a}=t,r=t.textContent.trim();for(const o of e)if(p(o,t,l)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const l=`//${a}[@${o.name}='${e}' and text()='${r}']`;if(l){if(1==c(l,t,n))return l}}}const F=(e,t,n,l,a)=>{try{let r,o,s=[];if(T=[],console.log(a),a)for(const t of a){let n=w(e,{name:t.name,value:t.value},l);console.log(n),n&&s.push(n)}if(e.textContent){let t=w(e,{name:"text",value:e.textContent},l);console.log(t),t&&s.push(t)}if(s.push(e.tagName),s?.length)for(let a=0;a<s.length;a++)if(!T.length){if(H(e,t,l,s[a]),!T.length&&(r||(r=I(e.parentElement,t,e,l)),console.log(r),r&&(r.includes("@")||r.includes("text()")||r.includes(".="))&&r.match(/\//g)?.length-2<5)){const l=r+`/${s[a]}`,o=c(l,e,t);if(1===o)T.push({key:"relative xpath by relative parent",value:l});else if(o>1&&n){const a=h(l,e,t,o);a&&1===c(a,e,t)&&T.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!T.length&&(o||(o=q(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const l=`/${s[a]+o.substring(1)}`,r=c(l,e,t);if(1===r)T.push({key:"relative xpath by relative child",value:l});else if(r>1&&n){const a=h(l,e,t,r);a&&1===c(a,e,t)&&T.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===T?.length&&T?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const l=G(e,t,n,!1);l&&T.unshift({key:"xpath by text"+(n?"index":""),value:l})}if(!T.length){let r=M(e.parentElement,t,e,l,s[a],n);r&&T.push({key:"xpath by unique parent",value:r})}}return T}catch(e){console.log(e)}},U=(e,t,n,l,a)=>{let r;return r=e.name,b(t,n,`@${r}`,e.value,l,a)},B=(e,t,n,l)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=a?.replace("removePointers",""),a=a?.trim(),a)return b(e,t,"@class",a,n,l)},G=(e,t,n,l)=>{if(""!=e.textContent){const a=s(e);if(a)return b(e,t,".",a,n,l)}},J=(e,t,n,l,a)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&p(e,t,a)){const r=U(e,t,n,l,a);r&&T.push({key:`xpath by ${e.name}${l?" index":""}`,value:r})}});const o=G(t,n,l,a);if(o&&T.push({key:"xpath by text"+(l?" index":""),value:o}),r.find(e=>"className"===e.name)&&p(r?.find(e=>"className"===e.name),t,a)){let e=B(t,n,l,a);e&&T.push({key:"xpath by class",value:e})}if(!T.length){const l=z(e,t,n,a);l&&T.push({key:"xpath by textAttribute",value:l})}if(!T.length&&r.length>1){const e=S(t,n,r,a);e&&T.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},Z=(e,t,n,l)=>{T=[],console.log(e);const a=e,r=a?.ownerDocument||t,o=a.tagName,{attributes:s}=a;if(J(Array.from(s),a,r,n,l),T.length){const t=T.length;for(let n=0;n<t;n++){let t=T[n].value;t="//*"+t.substring(t.indexOf("//")+2+o.length);1===c(t,e,r)&&T.push({key:`${T[n].key} regex`,value:t})}}return console.log(T),T.length||F(a,r,n,l,Array.from(a.attributes)),T},K={parseDOM:Z,getTextXPath:G,getUniqueClassName:B,attributesBasedXPath:U,addAllXPathAttributes:J,addRelativeXpaths:F,getXPathUsingAttributeAndText:z,getSiblingRelativeXPath:H,getChildRelativeXpath:q,getParentRelativeXpath:I,getUniqueParentXpath:M,checkRelativeXpathRelation:Y};let Q=[],ee=[];const te=/^[\S]+( [\S]+)*$/gi,ne=(e,t,n,l,a,r,o,s=0,i=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)c.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const m=re(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,l,n,a,i);if(m)return m}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${P(t,e[e.length-1])}`;let r=c(u,e[e.length-1],l);if(1===r)return[{key:`dynamic ${n}`,value:v(u)}];if(r>1&&a&&(u=h(u,e[e.length-1],l,r),u&&(r=c(u,e[e.length-1],l),1===r)))return[{key:`dynamic ${n} ${a?" index":""}`,value:v(u)}]}},le=(e,t,n,l,a,r=!1,o=!1)=>{const i=e[e.length-2],c=e[e.length-1],m=g(c)??c.ownerDocument,h=n.find(e=>e?.key?.includes("absolute"))?.value||N(i,i.ownerDocument),f=[],d=[];h.split("/").map(e=>f.push(e)),f.map(e=>d.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=l.find(e=>e?.key?.includes("absolute"))?.value||N(c,c.ownerDocument),y=[],b=[];v.split("/").map(e=>y.push(e)),y.map(e=>b.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var E=0;E<f.length&&f[E]==y[E];E++);const S=[];for(let e=E-1;e<f.length;e++)f[e]&&S.push(d[e]);const w=[];for(let e="descendant"===a?E:E-1;e<y.length;e++)y[e]&&(w.length?w.push(b[e]):w.push(b[e].replace(/\[([0-9]+)\]/gm,"")));let k;if(ee=l,e[e.length-2].textContent){k=te.test(e[e.length-2].textContent)?$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${u(s(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${u(s(e[e.length-2]))}]`:$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${R(e[e.length-2])})]`:`${e[e.length-2].tagName}[${R(e[e.length-2])}]`,S[S.length-1]=k;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<ee.length;n++){let s;if(s=ee[n].value.startsWith("//")?ee[n].value.substring(ee[n].value.indexOf("//")+2):ee[n].value,s)return ne(e,s,a,m||t,r,w,i,l,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const s=n.name;k=$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${u(l)}]`:`${e[e.length-2].tagName}[@${s}=${u(l)}]`,S[S.length-1]=k;const i=S.join("["),c=S.length-1,h=i;for(let n=0;n<ee.length;n++){let l;return l=ee[n].value.startsWith("//")?ee[n].value.substring(ee[n].value.indexOf("//")+2):ee[n].value,ne(e,l,a,m||t,r,w,h,c,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const s=x(n,e[e.length-2]);if(s){k=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,S[S.length-1]=k;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<ee.length;n++){let s;return s=ee[n].value.startsWith("//")?ee[n].value.substring(ee[n].value.indexOf("//")+2):ee[n].value,ne(e,s,a,m||t,r,w,i,l,o)}}}}}const C=S.join("["),P=S.length-1,A=re(`${C+(P?"]".repeat(P):"")}`,w,e[e.length-1],e,t,a,r,o);if(A)return A},ae=(e,t,n,l,a,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const u=[];try{s=l.filter(e=>!e?.key?.includes("absolute")),i=a.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let l=0;l<i.length;l++){let a=`//${0!==s[e].value.indexOf("//")?P(s[e].value):P(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[l].value.indexOf("//")?P(i[l].value):P(i[l].value.substring(i[l].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",a);const o=c(a,t,t.ownerDocument);if(o>1)if(r){if(a=h(a,t,t.ownerDocument,o),a)return u.push({key:`dynamic ${n}${r?" index":""}`,value:v(a)}),u}else o>1&&(Q.length?o<Q[0].count&&(Q.pop(),Q.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o})):Q.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:v(a)}),u}if(!u.length)for(let l=0;l<s.length;l++)for(let a=0;a<i.length;a++){const c=`${0!==i[a].value.indexOf("//")?i[a].value:i[a].value.substring(i[a].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(c.length>1){const a=re(`${0!==s[l].value.indexOf("//")?P(s[l].value):P(s[l].value.substring(s[l].value.indexOf("//")+2))}`,c,t,[e,t],t.ownerDocument,n,r,o);if(console.log("getXpathRelationExpression traverseXpath",a),a)return u.concat(a),u}}}catch(e){console.log(e)}return u},re=(e,t,n,l,a,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${P(s)}`;const u=c(i,n,a);if(1===u)return[{key:`dynamic ${r}`,value:v(i)}];if(u>1&&o&&(i=h(i,l[l.length-1],a,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${P(u)}`;const m=c(i,n,a);if(1===m)return[{key:`dynamic ${r}`,value:v(i)}];if(m>1&&o&&(i=h(i,l[l.length-1],a,m),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}},oe={findRelativeXpath:(e,t,n,l,a,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],m=[];if(r&&Q.length){const e=h(Q[0].value,t,t.ownerDocument,Q[0].count);e&&(m=m.concat({key:`${Q[0]?.key?Q[0]?.key:"xpath with "} index`,value:e}),Q.pop())}if(!m.length){for(e.isSameNode(t)&&(u=ae(e,t,"self",l,a,r,o),u&&(m=m.concat(u))),c=e.parentElement,c===t&&(u=ae(e,t,"parent",l,a,r,o),u&&(m=m.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=ae(e,t,"ancestor",l,a,r,o),u)){m=m.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=ae(e,t,"ancestor-or-self",l,a,r,o),u)){m=m.concat(u);break}c=c.parentNode}while(null!==c);if(s?.isSameNode(i)){for(let n=e.nextElementSibling;null!=n;n=n.nextElementSibling)if(null!=n&&n.isSameNode(t)&&(u=ae(e,t,"following-sibling",l,a,r,o),u)){m=m.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=ae(e,t,"preceding-sibling",l,a,r,o),u)){m=m.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=ae(e,t,"child",l,a,r,o),u)){m=m.concat(u);break}const h=e.compareDocumentPosition(t);2===h&&(u=ae(e,t,"preceding",l,a,r,o)),4===h&&(u=ae(e,t,"following",l,a,r,o)),u&&(m=m.concat(u));const f=le([e,t],n,l,a,"descendant",r,o);f&&(m=m.concat(f));const d=le([e,t],n,l,a,"descendant-or-self",r,o);d&&(m=m.concat(d))}if(m.length)return m.length>1&&m.sort(function(e,t){return e.value.length-t.value.length}),m.filter(e=>!e.key?.includes("index"))?.length?[m.filter(e=>!e.key?.includes("index"))[0]]:[m[0]]},getDescendantXpath:le,getXpathRelationExpression:ae,getTraverseXpathExpression:re,getReferenceElementXpath:e=>{let t=[];if(t=Z(e,e.ownerDocument,!1,!1),t?.length){let n=Z(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&X(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Z(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&X(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:E(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:E(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&X(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value})),t?.length){const n=A(e,e.ownerDocument,!1);n?.length&&(t=t.concat(n))}else t=A(e,e.ownerDocument,!1);const n=N(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}},se=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:l}=n[e];if(l&&(se(l,t),l&&!t.includes("dynamic")))return l.querySelector(t)}}catch(e){console.log(e)}return null},ie=e=>e?.id||null,ce=e=>e.className||null,ue=e=>e.textContent?.trim()||null,me=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},he=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function fe(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function de(e,t,n){if(e.includes(t)){const l=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(l,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let l;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(l=e,l):(console.error("Complete Locator is Invalid:",e),l=e,l)}console.error("Source Locator Not Found:",l)}}return null}const ge=(e,t)=>{const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const l=new Set;let a=[];function r(e,t={}){const n={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded};t.hasOwnProperty("isSelfHealed")?n.isSelfHealed=t.isSelfHealed:e?.hasOwnProperty("isSelfHealed")&&(n.isSelfHealed=e.isSelfHealed),function(e){const t=`${e.name}:${e.value}`;l.has(t)||(l.add(t),a.push(e))}(n)}const o=(e,t,n)=>{if(!e)return null;let l=e.trim();return l&&"null"!==l.toLowerCase()?(l=l.replace(/\\"/g,'"').replace(/\\'/g,"'"),l=l.replace(/^['"](.+?)['"]$/,"$1"),l=l.replace(/''/g,"'"),l=l.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(l=l.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!l||/^['"]{2}$/.test(l)?null:l:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const s=e.locators.filter(e=>"N"===e.isRecorded);if(s.length>0)for(const e of s)r(e);const i=String(n.value||n.type||"");if(i.includes("dynamic")||i.match("dynamic")||i.includes("{")||i.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let s=null;if(n.value.startsWith("iframe")){const e=t.querySelector(n.value);if(e){const t=e.contentDocument||e.contentWindow?.document;t&&(s=t.querySelector(n.value.slice(6)))}}else{const e=n.value.split(">>>");for(const l of e){if(!t){console.error("Element not found at:",l);break}{const e=l.trim();if(n.name.includes("id")||e.startsWith("#"))s=t.querySelector("#"+e);else if(n.name.includes("className")||e.startsWith("."))s=t.querySelector("."+e);else if(!n.name.includes("xpath")&&!e.startsWith("//")||n.type.match("dynamic"))s=t.querySelector(e),s||(s=se(t.body,e));else{s=fe(t,O(e)),s&&r(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const i=(e,t)=>{const n=`${e}:${t}`;return l.has(n)};if(s){const n=ie(s);n&&!i("id",n)&&e.locators.forEach(e=>{r(e,{name:"id",value:n,isRecorded:e.value===n&&"id"===e.name?e.isRecorded:"Y",isSelfHealed:e.value===n&&"id"===e.name?e.isSelfHealed:"Y"})});const l=ue(s);l&&e.locators.forEach(e=>{r(e,{name:"linkText",type:"static",value:l,isRecorded:e.value===l?e.isRecorded:"Y",isSelfHealed:e.value===l?e.isSelfHealed:"Y"})});const c=me(s);c&&!i("name",c)&&e.locators.forEach(e=>{r(e,{name:"name",type:"static",value:c,isRecorded:e.value===c&&"name"===e.name?e.isRecorded:"Y",isSelfHealed:e.value===c&&"name"===e.name?e.isSelfHealed:"Y"})});const u=ce(s);u&&""!==u.trim()&&!i("className",u)&&e.locators.forEach(e=>{r(e,{name:"className",value:u,isRecorded:e.value===u&&"className"===e.name?e.isRecorded:"Y",isSelfHealed:e.value===u&&"className"===e.name?e.isSelfHealed:"Y"})});Z(s,t,!1,!0).forEach(t=>{const n=t.value;n&&!i(t.key.replace("xpath by","").trim(),n)&&e.locators.forEach(e=>{r(e,{name:"xpath",value:n,isRecorded:e.value===n?e.isRecorded:"Y",isSelfHealed:e.value===n?e.isSelfHealed:"Y"})})});for(const n of e.locators)try{for(const l of e.locators)if(l.value)for(const e of he)if(l.value.includes(e)){const a=de(l.value,e,t);if(a){r(l,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}const m=a.map(e=>({...e,value:o(e.value,e.name,e.isRecorded)})).reduce((e,t)=>(t.value&&!e.some(e=>e.value===t.value)&&e.push(t),e),[]),h=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:m.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return h}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};let pe=[];const $e=(e,t)=>{const n=e.tagName.toLowerCase();if(t?.defaultView?.Element&&!(e instanceof t?.defaultView?.Element))return;if(n.includes("style")||n.includes("script"))return;const l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!o(e.id)){t+=`#${e.id}`,l.unshift(t);break}{let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}l.unshift(t),e=e.parentElement}return l.join(" > ")},ve=(e,t)=>{const n=e.tagName.toLowerCase();if(t?.defaultView?.Element&&!(e instanceof t?.defaultView?.Element))return;if(n.includes("style")||n.includes("script"))return;const l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase(),n=e.getAttribute("name");if(n&&!o(n)){t+=`[name=${n}]`,l.unshift(t);break}{let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}l.unshift(t),e=e.parentElement}return l.join(" > ")},ye=(e,t)=>{const n=e.tagName.toLowerCase();if(t?.defaultView?.Element&&!(e instanceof t?.defaultView?.Element))return;if(n.includes("style")||n.includes("script"))return;const l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||o(e.className)||pe?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,l.unshift(t);break}l.unshift(t),e=e.parentElement}return l.join(" > ")},be=(e,t)=>{const n=e.tagName.toLowerCase();if(t?.defaultView?.Element&&!(e instanceof t?.defaultView?.Element))return;if(n.includes("style")||n.includes("script"))return;const l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(n.includes("body")||n.includes("head")||n.includes("html")){t+=n,l.unshift(t);break}{let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}l.unshift(t),e=e.parentElement}return l.join(" > ")},Ne={parseCssSelectors:(e,t)=>{let n=[];try{let l=$e(e,t);l&&l.includes("#")&&1===t.querySelectorAll(l)?.length&&!(l.includes("body")||l.includes("head")||l.includes("html"))?n.push({key:"cssSelector by id",value:l}):l="";let a=ve(e,t);a&&a!==l&&a.includes("name")&&1===t.querySelectorAll(a)?.length&&!(a.includes("body")||a.includes("head")||a.includes("html"))?n.push({key:"cssSelector by name",value:a}):a="";let r=ye(e,t);r&&r!==l&&a!==r&&r.includes(".")&&1===t.querySelectorAll(r)?.length&&!(r.includes("body")||r.includes("head")||r.includes("html"))?n.push({key:"cssSelector by class",value:r}):r=""}catch(e){console.log(e)}if(!n.length){let l=be(e,t);l&&1===t.querySelectorAll(l)?.length&&!(l.includes("body")||l.includes("head")||l.includes("html"))?n.push({key:"Absolute cssSelector",value:l}):l=""}return n},getIdCssPath:$e,getNameCssPath:ve,getClassCssPath:ye,getAbsoluteCssPath:be},Ee=()=>({xpath:K,referenceXpaths:oe,xpathUtils:D,getElementsFromHTML:ge,cssSelectors:Ne});e.createXPathAPI=Ee,e.default=Ee,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
|
|
1
|
+
!function(e){"use strict";const t=/^[\S]+( [\S]+)*$/gi;const n={};let a,l=new Map,r=[];const o=e=>/\d/.test(e),s=e=>{const t=e?.textContent;return t},i=e=>e?.childNodes[0]?.nodeValue||"",c=(e,t,a,l=!1)=>{try{let r;if(void 0!==n[e])r=n[e];else{r=(9===a.nodeType?a:a.ownerDocument).evaluate(`count(${e})`,a,null,XPathResult.NUMBER_TYPE,null).numberValue,n[e]=r}if(l&&Array.isArray(t)){if(r>1){const n=y(e,a,!0);let l,r=0;if(n instanceof XPathResult)for(;(l=n?.iterateNext())&&(!t.includes(l)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return y(e,a)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},u=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},m=e=>{const t=e.split("");let n=t.length;const a=[];for(;"["!==t[n-2];)a.push(t[n-2]),n--;a.reverse();let l="";for(let e=0;e<a.length;e++)l+=a[e];const r=l.length+2;let o=e.slice(0,e.length-r);return o=o.startsWith("(")&&o.endsWith(")")?o.slice(1,-1):e,o},f=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===c(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===c(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const o=l.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s;for(;s=o.iterateNext();)if(r++,s.isSameNode(t))return 1===c(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===c(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},h=e=>(e=(e=(e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(e)).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim()).split("/")[0].trim(),g=e=>e?e.replace(/\s\s+/g," ").trim():e,d=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},p=(e,t,n)=>!(!e?.value||"boolean"==typeof e?.value||["true","false","on","off","flntooltip"].some(t=>t===e.value)||["type","style","locator-data-tooltip","value"].some(t=>t===e.name)||r?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name)||0===e?.name?.indexOf("on")&&e?.name?.length>3||"function"==typeof e.value||n&&o(e.value)),$=e=>e instanceof SVGElement,v=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,y=(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const l=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?l.evaluate(e,a,null,XPathResult.ANY_TYPE,null):l.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},N=(e,n,a,l,r,s)=>{if(l){const{tagName:i}=e;let m,f="";const h=[];let d;if(l&&(!s||!o(l))&&(d=t.test(l)?`//${i}[${a}=${u(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${u(g(l)).trim()}`,$(e),e.tagName.toLowerCase()),m=c(d,e,n),1===m&&!r))return d;if(l&&s){const o=l.split(" ");if(o?.length)if(1===o.length){const s=[...new Set(o[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&g(s[0].trim())?.length>1&&l.startsWith(s[0])&&(f=t.test(s[0])?`starts-with(${a},${u(s[0]).trim()})`:`starts-with(${a},${u(g(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&g(s[s.length-1].trim())?.length>1&&l.endsWith(s[s.length-1])&&(f=t.test(s[s.length-1])?`ends-with(${a},${u(s[s.length-1]).trim()})`:`ends-with(${a},${u(g(s[s.length-1])).trim()})`),f?.length&&(d=$(e)?`//*[local-name()='${i}' and ${f}]`:`//${i}[${f}]`,m=c(d,e,n),1===m&&!r))return d}else{const s=o.length%2==0?o.length/2:o.length%2,h=o.slice(0,s).join(" ");let p=[...new Set(h.match(/([^0-9]+)/g))];if(p?.length&&p[0]&&g(p[0].trim())?.length&&l.startsWith(p[0])&&(f=t.test(p[0])?`starts-with(${a},${u(p[0]).trim()})`:`starts-with(${a},${u(g(p[0])).trim()})`),f?.length&&(d=$(e)?`//*[local-name()='${i}' and ${f}]`:`//${i}[${f}]`,m=c(d,e,n),1===m&&!r))return d;const v=o.slice(s,o.length-1).join(" ");if(p=[...new Set(v.match(/([^0-9]+)/g))],p?.length&&p[0]&&g(p[0].trim())?.length>3&&l.endsWith(p[0])&&(f=t.test(p[0])?`ends-with(${a},${u(p[0]).trim()})`:`ends-with(${a},${u(g(p[0])).trim()})`),f?.length&&(d=$(e)?`//*[local-name()='${i}' and ${f}]`:`//${i}[${f}]`,m=c(d,e,n),1===m&&!r))return d}}if(l&&s&&o(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let e=0;e<o?.length;e++)o[e]&&g(o[e].trim())?.length>1&&(t.test(o[e])?h.push(`contains(${a},${u(o[e].trim()).trim()})`):h.push(`contains(${a},${u(g(o[e])).trim()})`));if(h?.length&&(d=$(e)?`//*[local-name()='${i}' and ${h.join(" and ")}]`:`//${i}[${h.join(" and ")}]`,m=c(d,e,n),1===m&&!r))return d}if(d=$(e)?`//*[local-name()='${i}' and text()]`:`//${i}[text()]`,m=c(d,e,n),1===m&&!r)return d}},b=(e,t)=>{try{if(!e)return"";let n=$(e)?`/*[local-name()='${e.tagName}']`:`/${e.tagName}`;if(e.parentElement){const t=Array.prototype.slice.call(e.parentElement.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}else if(e instanceof HTMLElement&&e.offsetParent){const t=Array.prototype.slice.call(e.offsetParent.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}return b(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},x=(e,t,n,a=!1,r)=>{try{if(l.has(e))return l.get(e);const s=[];let m=e;for(;m;){let l="",h=!1,d=e===m?r??m.attributes:m.attributes;for(const e of Array.from(d))if(p(e,m,a)){let a=e.nodeValue;a=a?.replace("removePointers","")??"";const r=e.name;l=C(m,r,a);let o=0;if(l&&(o=c(l,m,t),1===o)){s.unshift(v(l)),h=!0;break}if(o>1&&n&&(l=f(l,m,t,o),l)){s.unshift(v(l)),h=!0;break}}if(m.textContent)if(!a||a&&!o(m.textContent)){l=new RegExp(/^[\S]+( [\S]+)*$/gi).test(m.textContent)?$(m)?`//*[local-name()='${m.tagName}' and .=${u(i(m))}]`:`//${m.tagName||"*"}[.=${u(i(m))}]`:$(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${u(i(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${u(i(m))}]`;let e=c(l,m,t);if(1===e)return l;if(e>1&&n)return l=f(l,m,t,e),l}else{let e=[];const a=[...new Set(i(m).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&g(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${u(a[t].trim()).trim()})`):e.push(`contains(.,${u(g(a[t])).trim()})`));if(e?.length){l=$(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`;let a=c(l,m,t);if(1===a)return l;if(a>1&&n)return l=f(l,m,t,a),l}}if(h)break;{let e=$(m)?`/*[local-name()='${m.tagName}']`:`/${m.tagName}`;if(m.parentElement){const t=Array.from(m.parentElement.children).filter(e=>e.tagName===m.tagName);if(t.length>1){e+=`[${t.indexOf(m)+1}]`}}s.unshift(e)}m=m.parentElement}const h=`${s.join("")}`;return l.set(e,h),h}catch(e){return console.log(e),null}},E=(e,n)=>{const a=[];let l="";if(e&&!o(e.value)&&"function"!=typeof e.nodeValue){const r=[...new Set(e.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&g(r[n].trim())?.length>2&&(t.test(r[n])?a.push(`contains(@${e.name},${u(r[n].trim())})`):a.push(`contains(@${e.name},${u(g(r[n])).trim()})`));if(a?.length)return l=$(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},S=(e,n,a,l)=>{try{const r=[];if(a.length>1)for(const o of a)if(p(o,e,l)){const a=o.nodeValue;t.test(a)?"class"===o.nodeName?r.push(`contains(@${o.nodeName},"${a}")`):r.push(`@${o.nodeName}="${a}"`):r.push(`normalize-space(@${o.nodeName})="${a}"`);const l=$(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let s;try{s=c(l,e,n)}catch(e){continue}if(1===s&&!l.includes("and"))return"";if(1===s&&l.includes("and"))return l}}catch(e){console.log(`'${JSON.stringify(e,null,2)}'`)}},k=(e,n,a)=>{let l=$(e),r="";if(p(n,e,a)){let a=n.value;a=a.replace("removePointers","");const o=n.name;r=t.test(a)?l?`*[local-name()='${e.tagName}' and @${o}=${u(a)}]`:`${e.tagName||"*"}[@${o}=${u(a)}]`:l?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${u(a)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${u(a)}]`}return r},w=(e,n)=>{if(!e.textContent)return"";const a=i(e);let l;return l=t.test(a)?$(e)?`//*[local-name()='${e.tagName}' and .=${u(a)}]`:`//${e.tagName||"*"}[.=${u(a)}]`:$(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${u(a)}]`:`//${e.tagName||"*"}[normalize-space(.)=${u(a)}]`,l},R=e=>{const t=s(e)?.trim(),n=t?u(h(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},C=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.test(n)?"class"===t?$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`:$(e)?`//*[local-name()='${e.tagName}' and @${t}=${u(n)}]`:`//${e.tagName||"*"}[@${t}=${u(n)}]`:$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`),l},A=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,P=(e,n,a)=>{let l;const r=[];if(e.textContent&&(!a||a&&!o(e.textContent))&&(t.test(e.textContent)?(l=$(e)?`*[local-name()='${e.tagName}' and .=${u(s(e))}]`:`${e.tagName}[.=${u(s(e))}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})):(l=$(e)?`*[local-name()='${e.tagName}' and ${R(e)})]`:`${e.tagName}[${R(e)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))),e.attributes)for(const t of Array.from(e.attributes))if(p(t,e,a)){let n=t.nodeValue;if(n){n=n.replace("removePointers","");const a=t.name;l="class"===a?$(e)?`*[local-name()='${e.tagName}' and contains(@${a},${u(n)})]`:`${e.tagName}[contains(@${a},${u(n)})]`:$(e)?`*[local-name()='${e.tagName}' and @${a}=${u(n)}]`:`${e.tagName}[@${a}=${u(n)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})}}if(!r?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=S(e,n,Array.prototype.slice.call(e.attributes),a);t&&r.push({key:"getReferenceElementsXpath",value:t})}}if(!r?.length){const n=[];let l;const s=$(e);if(e.textContent&&a&&o(e.textContent)){const a=[...new Set(e.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let e=0;e<a?.length;e++)a[e]&&g(a[e].trim())?.length>1&&(t.test(a[e])?n.push(`contains(.,${u(a[e]).trim()})`):n.push(`contains(.,${u(g(a[e])).trim()})`));n?.length&&(l=s?`//*[local-name()='${s}' and ${n.join(" and ")}]`:`//${s}[${n.join(" and ")}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))}}if(!r?.length){const t=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(p(e,t,a)){const n=E(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(e.attributes,e,0,a);t?.length&&r.concat(t)}return r},D=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1"),T=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function X(e){const t=function(e){return e.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e),n=function(e){const t=e.toLowerCase(),n=t.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=n?.[1]??"none",l=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:l?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function O(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function j(e,t,n){try{switch(t){case"id":return null!==e.getElementById(n)&&1===e.querySelectorAll(`#${n}`).length;case"name":return 1===e.querySelectorAll(`[name="${O(n)}"]`).length;case"className":return 1===e.getElementsByClassName(n).length;case"tagName":return 1===e.getElementsByTagName(n).length;case"linkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const L={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:P,getAbsoluteXPath:b,getRelativeXPath:x,getCombinationXpath:E,getAttributeCombinationXpath:S,getElementFromXpath:y,isSvg:$,findXpathWithIndex:f,isNumberExist:o,getTextContent:s,getCountOfXPath:c,normalizeXPath:D,getShadowRoot:d,escapeCharacters:u,removeParenthesis:m,checkBlockedAttributes:p,getRelationship:(e,t)=>{let n=e.compareDocumentPosition(t);return 2===n?"preceding":4===n?"following":8===n?"ancestor":16===n?"descendant":32===n?"self":""},findMatchingParenthesis:T,deleteGarbageFromInnerText:h,replaceTempAttributes:v,createObserver:e=>{a=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&($(t.target)&&t.oldValue?.trim()===t.target.classList.value?.trim()||"marked-element-temp"===t.target.classList?.value?.replace(t.oldValue,"").trim()||"marked-element-temp"===t?.oldValue?.replace(t.target.classList?.value,"").trim())||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||r.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{a?.observe(e,t)},stopObserver:()=>{a?.disconnect()},modifiedElementAttributes:r,cspEnabled:!1,getXPathPattern:X,escapeAttrValue:O,isUniqueInDOM:j};let V=[],Y=[],_=new Map,q=new Map;const I=new Map,z=(e,t,n,a,l,r)=>{if(e){let o;o="parent"===r?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of o){_?.get(e)||_.set(e,c(e,n,a));const t=_?.get(e);if(1===t)return e;if(t>1&&(Y.length?t<Y[0].count&&(Y.pop(),Y.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):Y.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!V.length){const r=f(e,n,a,t);r&&1===c(r,n,a)&&V.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},M=(e,n,a,l,r,s)=>{try{if(I.has(e))return I.get(e);const m=[];let f=e;for(;f&&1===f.nodeType;){const e=!1;for(const e of Array.from(f.attributes))if(p(e,f,l)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const l=e.name,o=C(f,l,t);let i;try{i=z(o,r,a,n,s,"parent")}catch(e){continue}if(i)return i}if(f.textContent&&!f.textContent)if(!l||l&&!o(f.textContent)){let e;e=t.test(f.textContent)?$(f)?`//*[local-name()='${f.tagName}' and .=${u(i(f))}]`:`//${f.tagName||"*"}[.=${u(i(f))}]`:$(f)?`//*[local-name()='${f.tagName}' and normalize-space(.)=${u(i(f))}]`:`//${f.tagName||"*"}[normalize-space(.)=${u(i(f))}]`;const l=z(e,r,a,n,s,"parent");if(l)return l}else{const e=[],t=[...new Set(i(f).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&g(t[n].trim())&&(l.test(t[n])?e.push(`contains(.,${u(t[n].trim()).trim()})`):e.push(`contains(.,${u(g(t[n])).trim()})`));if(e?.length){const t=$(f)?`//*[local-name()='${f.tagName}' and ${e.join(" and ")}]`:`//${f.tagName||"*"}[${e.join(" and ")}]`,l=z(t,r,a,n,s,"parent");if(l)return l}}if(!e){const e=$(f)?`/*[local-name()='${f.tagName}']`:`/${f.tagName}`;m.unshift(e)}f=f.parentElement}const h=m.join("")+r;if(1===c(h,e,n))return I.set(e,h),h}catch(e){return console.error(e),null}},W=(e,t,n,a)=>{const l=new Map;if(l.has(e))return l.get(e);const r=[];let o=e;try{for(;o&&1===o.nodeType;){if(!o.tagName)return"";let e=!1;for(const n of Array.from(o.attributes))if(p(n,o,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,s=C(o,l,a);let i;try{i=c(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=w(o);if(n){if(1===c(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=$(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}const s=r.join("");return l.set(e,s),s}catch(e){return console.log(e),null}},H=(e,t,n)=>{const a=[];let l;const r=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?r.unshift(e.firstElementChild):null!=e.nextElementSibling&&r.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&r.unshift(t.nextElementSibling);try{do{let e=!1;for(l=r.pop();null!==l;){for(const n of Array.from(l.attributes))if(p(n,l,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=C(l,o,r);let i;try{i=c(s,l,t)}catch(e){continue}if(1===i){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=w(l);if(n){if(1===c(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=$(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;a.push(e),null!=l.firstElementChild?(r.push(l.nextElementSibling),l=l.firstElementChild):l=l.nextElementSibling}}}while(r.length>0);const o=a.join("");return q.set(e,o),o}catch(e){return console.log(e),null}},F=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)U(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)U(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},U=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=k(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=c(o,e,n);if(1===t)return void V.push({key:`xpath by ${l}`,value:o});t>1&&(Y.length?t<Y[0].count&&(Y.pop(),Y.push({key:`relative xpath by ${l}`,value:o,count:t})):Y.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=k(e,{name:"text",value:e.textContent},r),t){const a=c(t,e,n);if(1===a)return void V.push({key:`xpath by ${l}`,value:t});a>1&&(Y.length?a<Y[0].count&&(Y.pop(),Y.push({key:`relative xpath by ${l}`,value:t,count:a})):Y.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};function B(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();for(const o of e)if(p(o,t,a)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==c(a,t,n))return a}}}const G=(e,t,n,a,l)=>{try{let r,o,s=[];if(V=[],console.log(l),l)for(const t of l){let n=k(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=k(e,{name:"text",value:e.textContent},a);console.log(t),t&&s.push(t)}if(s.push(e.tagName),s?.length)for(let l=0;l<s.length;l++)if(!V.length){if(F(e,t,a,s[l]),!V.length&&(r||(r=W(e.parentElement,t,e,a)),console.log(r),r&&(r.includes("@")||r.includes("text()")||r.includes(".="))&&r.match(/\//g)?.length-2<5)){const a=r+`/${s[l]}`,o=c(a,e,t);if(1===o)V.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=f(a,e,t,o);l&&1===c(l,e,t)&&V.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!V.length&&(o||(o=H(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=c(a,e,t);if(1===r)V.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=f(a,e,t,r);l&&1===c(l,e,t)&&V.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===V?.length&&V?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=K(e,t,n,!1);a&&V.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!V.length){let r=M(e.parentElement,t,e,a,s[l],n);r&&V.push({key:"xpath by unique parent",value:r})}}return V}catch(e){console.log(e)}},J=(e,t,n,a,l)=>{let r;return r=e.name,N(t,n,`@${r}`,e.value,a,l)},Z=(e,t,n,a)=>{let l=e.className;if("string"!=typeof l&&(l=""),l=l?.replace("flndisabled","disabled"),l=l?.replace("removePointers",""),l=l?.trim(),l)return N(e,t,"@class",l,n,a)},K=(e,t,n,a)=>{if(""!=e.textContent){const l=s(e);if(l)return N(e,t,".",l,n,a)}},Q=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&p(e,t,l)){const r=J(e,t,n,a,l);r&&V.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=K(t,n,a,l);if(o&&V.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&p(r?.find(e=>"className"===e.name),t,l)){let e=Z(t,n,a,l);e&&V.push({key:"xpath by class",value:e})}if(!V.length){const a=B(e,t,n,l);a&&V.push({key:"xpath by textAttribute",value:a})}if(!V.length&&r.length>1){const e=S(t,n,r,l);e&&V.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},ee=(e,t,n,a,l=[])=>{V=[],console.log(e);const r=e,o=r?.ownerDocument||t,s=r.tagName,{attributes:i}=r,u=l.length>0?l:Array.from(i);if(Q(u,r,o,n,a),V.length){const t=V.length;for(let n=0;n<t;n++){let t=V[n].value;t="//*"+t.substring(t.indexOf("//")+2+s.length);1===c(t,e,o)&&V.push({key:`${V[n].key} regex`,value:t})}}return V.length||G(r,o,n,a,Array.from(r.attributes)),V},te={parseDOM:ee,getTextXPath:K,getUniqueClassName:Z,attributesBasedXPath:J,addAllXPathAttributes:Q,addRelativeXpaths:G,getXPathUsingAttributeAndText:B,getSiblingRelativeXPath:F,getChildRelativeXpath:H,getParentRelativeXpath:W,getUniqueParentXpath:M,checkRelativeXpathRelation:z};let ne=[],ae=[];const le=/^[\S]+( [\S]+)*$/gi,re=(e,t,n,a,l,r,o,s=0,i=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)c.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const m=ie(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,l,i);if(m)return m}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${A(t,e[e.length-1])}`;let r=c(u,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:v(u)}];if(r>1&&l&&(u=f(u,e[e.length-1],a,r),u&&(r=c(u,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:v(u)}]}},oe=(e,t,n,a,l,r=!1,o=!1)=>{const i=e[e.length-2],c=e[e.length-1],m=d(c)??c.ownerDocument,f=n.find(e=>e?.key?.includes("absolute"))?.value||b(i,i.ownerDocument),h=[],g=[];f.split("/").map(e=>h.push(e)),h.map(e=>g.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=a.find(e=>e?.key?.includes("absolute"))?.value||b(c,c.ownerDocument),y=[],N=[];v.split("/").map(e=>y.push(e)),y.map(e=>N.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var x=0;x<h.length&&h[x]==y[x];x++);const S=[];for(let e=x-1;e<h.length;e++)h[e]&&S.push(g[e]);const k=[];for(let e="descendant"===l?x:x-1;e<y.length;e++)y[e]&&(k.length?k.push(N[e]):k.push(N[e].replace(/\[([0-9]+)\]/gm,"")));let w;if(ae=a,e[e.length-2].textContent){w=le.test(e[e.length-2].textContent)?$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${u(s(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${u(s(e[e.length-2]))}]`:$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${R(e[e.length-2])})]`:`${e[e.length-2].tagName}[${R(e[e.length-2])}]`,S[S.length-1]=w;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;if(s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,s)return re(e,s,l,m||t,r,k,i,a,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=n.name;w=$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${u(a)}]`:`${e[e.length-2].tagName}[@${s}=${u(a)}]`,S[S.length-1]=w;const i=S.join("["),c=S.length-1,f=i;for(let n=0;n<ae.length;n++){let a;return a=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,a,l,m||t,r,k,f,c,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=E(n,e[e.length-2]);if(s){w=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,S[S.length-1]=w;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;return s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,s,l,m||t,r,k,i,a,o)}}}}}const C=S.join("["),A=S.length-1,P=ie(`${C+(A?"]".repeat(A):"")}`,k,e[e.length-1],e,t,l,r,o);if(P)return P},se=(e,t,n,a,l,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const u=[];try{s=a.filter(e=>!e?.key?.includes("absolute")),i=l.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let a=0;a<i.length;a++){let l=`//${0!==s[e].value.indexOf("//")?A(s[e].value):A(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[a].value.indexOf("//")?A(i[a].value):A(i[a].value.substring(i[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=c(l,t,t.ownerDocument);if(o>1)if(r){if(l=f(l,t,t.ownerDocument,o),l)return u.push({key:`dynamic ${n}${r?" index":""}`,value:v(l)}),u}else o>1&&(ne.length?o<ne[0].count&&(ne.pop(),ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:v(l)}),u}if(!u.length)for(let a=0;a<s.length;a++)for(let l=0;l<i.length;l++){const c=`${0!==i[l].value.indexOf("//")?i[l].value:i[l].value.substring(i[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(c.length>1){const l=ie(`${0!==s[a].value.indexOf("//")?A(s[a].value):A(s[a].value.substring(s[a].value.indexOf("//")+2))}`,c,t,[e,t],t.ownerDocument,n,r,o);if(console.log("getXpathRelationExpression traverseXpath",l),l)return u.concat(l),u}}}catch(e){console.log(e)}return u},ie=(e,t,n,a,l,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${A(s)}`;const u=c(i,n,l);if(1===u)return[{key:`dynamic ${r}`,value:v(i)}];if(u>1&&o&&(i=f(i,a[a.length-1],l,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${A(u)}`;const m=c(i,n,l);if(1===m)return[{key:`dynamic ${r}`,value:v(i)}];if(m>1&&o&&(i=f(i,a[a.length-1],l,m),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}},ce={findRelativeXpath:(e,t,n,a,l,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],m=[];if(r&&ne.length){const e=f(ne[0].value,t,t.ownerDocument,ne[0].count);e&&(m=m.concat({key:`${ne[0]?.key?ne[0]?.key:"xpath with "} index`,value:e}),ne.pop())}if(!m.length){for(e.isSameNode(t)&&(u=se(e,t,"self",a,l,r,o),u&&(m=m.concat(u))),c=e.parentElement,c===t&&(u=se(e,t,"parent",a,l,r,o),u&&(m=m.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=se(e,t,"ancestor",a,l,r,o),u)){m=m.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=se(e,t,"ancestor-or-self",a,l,r,o),u)){m=m.concat(u);break}c=c.parentNode}while(null!==c);if(s?.isSameNode(i)){for(let n=e.nextElementSibling;null!=n;n=n.nextElementSibling)if(null!=n&&n.isSameNode(t)&&(u=se(e,t,"following-sibling",a,l,r,o),u)){m=m.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=se(e,t,"preceding-sibling",a,l,r,o),u)){m=m.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=se(e,t,"child",a,l,r,o),u)){m=m.concat(u);break}const f=e.compareDocumentPosition(t);2===f&&(u=se(e,t,"preceding",a,l,r,o)),4===f&&(u=se(e,t,"following",a,l,r,o)),u&&(m=m.concat(u));const h=oe([e,t],n,a,l,"descendant",r,o);h&&(m=m.concat(h));const g=oe([e,t],n,a,l,"descendant-or-self",r,o);g&&(m=m.concat(g))}if(m.length)return m.length>1&&m.sort(function(e,t){return e.value.length-t.value.length}),m.filter(e=>!e.key?.includes("index"))?.length?[m.filter(e=>!e.key?.includes("index"))[0]]:[m[0]]},getDescendantXpath:oe,getXpathRelationExpression:se,getTraverseXpathExpression:ie,getReferenceElementXpath:e=>{let t=[];if(t=ee(e,e.ownerDocument,!1,!1),t?.length){let n=ee(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&T(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=ee(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&T(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:x(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:x(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&T(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:m(e.value)}:{key:"",value:e.value})),t?.length){const n=P(e,e.ownerDocument,!1);n?.length&&(t=t.concat(n))}else t=P(e,e.ownerDocument,!1);const n=b(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}},ue=(e,t,n)=>$e(t,D(e))===n,me=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:a}=n[e];if(a&&(me(a,t),a&&!t.includes("dynamic")))return a.querySelector(t)}}catch(e){console.log(e)}return null},fe=e=>e?.id||null,he=e=>e.className||null,ge=e=>e.textContent?.trim()||null,de=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},pe=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function $e(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function ve(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),l=n.defaultView;if(!l)return null;if(!e.includes("dynamic")){const t=new l.XPathEvaluator;if(t.evaluate(a,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(a=e,a):(console.error("Complete Locator is Invalid:",e),a=e,a)}console.error("Source Locator Not Found:",a)}}return null}const ye=(e,t)=>{const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const a=new Set;let l=[];function r(e,t={}){const n=e?.value,r=t.value??e?.value,o={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;o.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(o.name,n,r),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(o)}const s=(e,t,n)=>{if(!e)return null;let a=e.trim();return a&&"null"!==a.toLowerCase()?(a=a.replace(/\\"/g,'"').replace(/\\'/g,"'"),a=a.replace(/^['"](.+?)['"]$/,"$1"),a=a.replace(/''/g,"'"),a=a.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(a=a.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!a||/^['"]{2}$/.test(a)?null:a:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const i=e.locators.filter(e=>"N"===e.isRecorded);if(i.length>0)for(const e of i)r(e);const c=String(n.value||n.type||"");if(c.includes("dynamic")||c.match("dynamic")||c.includes("{")||c.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let i=null;if(n.value.startsWith("iframe")){const e=t.querySelector(n.value);if(e){const t=e.contentDocument||e.contentWindow?.document;t&&(i=t.querySelector(n.value.slice(6)))}}else{const e=n.value.split(">>>");for(const a of e){if(!t){console.error("Element not found at:",a);break}{const e=a.trim();if(n.name.includes("id")||e.startsWith("#"))i=t.querySelector("#"+e);else if(n.name.includes("className")||e.startsWith("."))i=t.querySelector("."+e);else if("name"===n.name){const n=O(e);i=t.querySelector(`[name="${n}"]`)}else if("tagName"===n.name)i=t.querySelector(e);else if("linkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.trim()===e)||null;else if("partialLinkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.includes(e))||null;else if(!n.name.includes("xpath")&&!e.startsWith("//")||n.type.match("dynamic"))i=t.querySelector(e),i||(i=me(t.body,e));else{const a=D(e);i=$e(t,a),i&&r(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const c=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(i){const n=e.locators.filter(e=>"xpath"===e.name&&e.value);for(const e of n)ue(e.value,t,i)&&r(e,{isSelfHealed:null});const a=l.filter(e=>"xpath"===e.name&&e.value),u=new Set(a.map(e=>X(e.value))),m=[],f=fe(i);if(f&&!c("id",f)&&!o(f)){const n=e.locators.find(e=>"id"===e.name);j(t,"id",f)&&(m.push("id"),r(n,{name:"id",type:"static",isRecorded:"Y",value:f}))}const h=i.tagName;if(h&&!c("tagName",h)){const n=e.locators.find(e=>"tagName"===e.name);j(t,"tagName",h)&&(m.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:h}))}const g=ge(i);if(g&&!o(g)){const n=e.locators.find(e=>"linkText"===e.name);j(t,"linkText",g)&&(m.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const d=de(i);if(d&&!c("name",d)&&!o(d)){const n=e.locators.find(e=>"name"===e.name);j(t,"name",d)&&(m.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:d}))}const p=he(i);if(p&&""!==p.trim()&&!c("className",p)&&!o(p)){const n=e.locators.find(e=>"className"===e.name);j(t,"className",p)&&(m.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:p}))}const $=Array.from(i.attributes).filter(e=>!m.includes(e.name)),v=ee(i,t,!1,!0,$);if(0!==v?.length){const e=n.filter(e=>!ue(e.value,t,i));let a=0;for(const t of e){if(a>=e.length)break;const n=X(t.value);if(u.has(n))continue;const l=v.find(e=>e.value&&X(e.value)===n);l?.value&&(r(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),a++)}if(a<e.length)for(const t of v){if(a>=e.length)break;if(!t.value)continue;const n=X(t.value);u.has(n)||(r(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of pe)if(a.value.includes(e)){const l=ve(a.value,e,t);if(l){r(a,{name:"xpath",value:l,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(l.length<5){const e=[{name:"id",value:fe(i)},{name:"name",value:de(i)},{name:"className",value:he(i)},{name:"tagName",value:i.tagName},{name:"linkText",value:ge(i)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(o(a)||c(e,a)||j(t,e,a)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}}const y=l.map(e=>({...e,value:s(e.value,e.name,e.isRecorded)})),N=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:y.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return N}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};let Ne=[];const be=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},xe=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!o(e.id)){t+=`#${CSS.escape(e.id)}`,a.unshift(t);break}{let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}a.unshift(t),e=e.parentElement}return a.join(" > ")},Ee=new Set(["id","class","style"]);const Se=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.getRootNode(),a=e.tagName.toLowerCase();if("style"===a||"script"===a)return;const l=function(e){return Array.from(e.attributes).filter(e=>!Ee.has(e?.name?.toLowerCase())&&e.value&&!o(e.value)).map(e=>`[${e.name}="${CSS.escape(e.value)}"]`)}(e);for(const t of l){const l=`${a}${t}`;if(be(l,e,n))return l}},ke=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||o(e.className)||Ne?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,a.unshift(t);break}a.unshift(t),e=e.parentElement}return a.join(" > ")},we=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=[];for(;e&&e.nodeType===Node.ELEMENT_NODE;){const t=e.tagName.toLowerCase();if("style"===t||"script"===t)return;let a=t;const l=e.parentNode;if(l){const t=Array.from(l.children).filter(t=>t.tagName===e.tagName);t.length>1&&(a+=`:nth-of-type(${t.indexOf(e)+1})`)}n.unshift(a),e=e.parentElement}return n.join(" > ")},Re={parseCssSelectors:e=>{const t=[],n=e.getRootNode();try{const a=xe(e);if(a&&be(a,e,n))return t.push({key:"cssSelector by id",value:a}),t;const l=ke(e);l&&be(l,e,n)&&t.push({key:"cssSelector by class",value:l});const r=Se(e);r&&t.push({key:"cssSelector by name",value:r});const o=we(e);o&&be(o,e,n)&&t.push({key:"Absolute cssSelector",value:o})}catch(e){console.error(e)}return t},getIdCssPath:xe,getAttributeCssPath:Se,getClassCssPath:ke,getAbsoluteCssPath:we},Ce=()=>({xpath:te,referenceXpaths:ce,xpathUtils:L,getElementsFromHTML:ye,cssSelectors:Re});e.createXPathAPI=Ce,e.default=Ce,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const createXPathAPI: () => {
|
|
2
2
|
xpath: {
|
|
3
|
-
parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean) => {
|
|
3
|
+
parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean, includedAttributes?: Attr[]) => {
|
|
4
4
|
key: string;
|
|
5
5
|
value: string;
|
|
6
6
|
}[];
|
|
@@ -82,6 +82,9 @@ export declare const createXPathAPI: () => {
|
|
|
82
82
|
doc: Document;
|
|
83
83
|
}[];
|
|
84
84
|
cspEnabled: boolean;
|
|
85
|
+
getXPathPattern: typeof import("../utils/xpathHelpers.ts").getXPathPattern;
|
|
86
|
+
escapeAttrValue: typeof import("../utils/xpathHelpers.ts").escapeAttrValue;
|
|
87
|
+
isUniqueInDOM: typeof import("../utils/xpathHelpers.ts").isUniqueInDOM;
|
|
85
88
|
};
|
|
86
89
|
getElementsFromHTML: (record: import("../types/locator.ts").ElementRecord, docmt: Document) => {
|
|
87
90
|
[key: string]: any;
|
|
@@ -98,14 +101,14 @@ export declare const createXPathAPI: () => {
|
|
|
98
101
|
relativeXpath?: string | null;
|
|
99
102
|
} | null;
|
|
100
103
|
cssSelectors: {
|
|
101
|
-
parseCssSelectors: (el:
|
|
104
|
+
parseCssSelectors: (el: Element) => {
|
|
102
105
|
key: string;
|
|
103
106
|
value: string;
|
|
104
107
|
}[];
|
|
105
|
-
getIdCssPath: (el: HTMLElement | Element
|
|
106
|
-
|
|
107
|
-
getClassCssPath: (el: HTMLElement | Element
|
|
108
|
-
getAbsoluteCssPath: (el:
|
|
108
|
+
getIdCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
109
|
+
getAttributeCssPath: (el: Element) => string | undefined;
|
|
110
|
+
getClassCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
111
|
+
getAbsoluteCssPath: (el: Element) => string | undefined;
|
|
109
112
|
};
|
|
110
113
|
};
|
|
111
114
|
export default createXPathAPI;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export declare const parseCssSelectors: (el:
|
|
1
|
+
export declare const parseCssSelectors: (el: Element) => {
|
|
2
2
|
key: string;
|
|
3
3
|
value: string;
|
|
4
4
|
}[];
|
|
5
|
-
export declare const getIdCssPath: (el: HTMLElement | Element
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const getClassCssPath: (el: HTMLElement | Element
|
|
8
|
-
export declare const getAbsoluteCssPath: (el:
|
|
5
|
+
export declare const getIdCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
6
|
+
export declare const getAttributeCssPath: (el: Element) => string | undefined;
|
|
7
|
+
export declare const getClassCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
8
|
+
export declare const getAbsoluteCssPath: (el: Element) => string | undefined;
|
|
9
9
|
export declare const cssSelectors: {
|
|
10
|
-
parseCssSelectors: (el:
|
|
10
|
+
parseCssSelectors: (el: Element) => {
|
|
11
11
|
key: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}[];
|
|
14
|
-
getIdCssPath: (el: HTMLElement | Element
|
|
15
|
-
|
|
16
|
-
getClassCssPath: (el: HTMLElement | Element
|
|
17
|
-
getAbsoluteCssPath: (el:
|
|
14
|
+
getIdCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
15
|
+
getAttributeCssPath: (el: Element) => string | undefined;
|
|
16
|
+
getClassCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
17
|
+
getAbsoluteCssPath: (el: Element) => string | undefined;
|
|
18
18
|
};
|
|
@@ -2,12 +2,12 @@ declare function getXPathUsingAttributeAndText(attributes: Attr[], targetElemt:
|
|
|
2
2
|
export declare const attributesBasedXPath: (attr: Attr, targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
3
3
|
export declare const getUniqueClassName: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
4
4
|
export declare const getTextXPath: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
5
|
-
export declare const parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean) => {
|
|
5
|
+
export declare const parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean, includedAttributes?: Attr[]) => {
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
}[];
|
|
9
9
|
declare const xpath: {
|
|
10
|
-
parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean) => {
|
|
10
|
+
parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean, includedAttributes?: Attr[]) => {
|
|
11
11
|
key: string;
|
|
12
12
|
value: string;
|
|
13
13
|
}[];
|
|
@@ -48,6 +48,15 @@ export declare const getReferenceElementsXpath: (domNode: HTMLElement | Element,
|
|
|
48
48
|
export declare const parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
49
49
|
export declare const normalizeXPath: (xpath: string) => string;
|
|
50
50
|
export declare const findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
51
|
+
export declare function canonicalizeXPath(xpath: string): string;
|
|
52
|
+
export declare function extractXPathSignatureParts(xpath: string): {
|
|
53
|
+
axis: string;
|
|
54
|
+
attribute: string;
|
|
55
|
+
usesNormalize: boolean;
|
|
56
|
+
};
|
|
57
|
+
export declare function getXPathPattern(xpath: string): string;
|
|
58
|
+
export declare function escapeAttrValue(value: string): string;
|
|
59
|
+
export declare function isUniqueInDOM(docmt: Document, name: string, value: string): boolean;
|
|
51
60
|
export declare const xpathUtils: {
|
|
52
61
|
parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
53
62
|
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
@@ -86,4 +95,7 @@ export declare const xpathUtils: {
|
|
|
86
95
|
doc: Document;
|
|
87
96
|
}[];
|
|
88
97
|
cspEnabled: boolean;
|
|
98
|
+
getXPathPattern: typeof getXPathPattern;
|
|
99
|
+
escapeAttrValue: typeof escapeAttrValue;
|
|
100
|
+
isUniqueInDOM: typeof isUniqueInDOM;
|
|
89
101
|
};
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { ElementRecord } from "../types/locator";
|
|
2
2
|
declare function createXPathAPI(): Promise<{
|
|
3
3
|
fromHTML: (html: string) => Promise<{
|
|
4
|
-
autoHeal: (data: ElementRecord
|
|
4
|
+
autoHeal: (data: ElementRecord) => Promise<{
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
id?: string | null;
|
|
7
|
+
className?: string | null;
|
|
8
|
+
xpathByText?: string | null;
|
|
9
|
+
xpathById?: string | null;
|
|
10
|
+
xpathByClass?: string | null;
|
|
11
|
+
xpathAbsolute?: string | null;
|
|
12
|
+
xpathByName?: string | null;
|
|
13
|
+
xpathByPlaceholder?: string | null;
|
|
14
|
+
xpathByType?: string | null;
|
|
15
|
+
visibleText?: string | null;
|
|
16
|
+
relativeXpath?: string | null;
|
|
17
|
+
} | null>;
|
|
5
18
|
}>;
|
|
6
|
-
browser: any;
|
|
7
19
|
}>;
|
|
8
20
|
export default createXPathAPI;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ElementRecord } from "../types/locator.ts";
|
|
2
|
+
type ElementDetails = {
|
|
3
|
+
id?: string | null;
|
|
4
|
+
className?: string | null;
|
|
5
|
+
xpathByText?: string | null;
|
|
6
|
+
xpathById?: string | null;
|
|
7
|
+
xpathByClass?: string | null;
|
|
8
|
+
xpathAbsolute?: string | null;
|
|
9
|
+
xpathByName?: string | null;
|
|
10
|
+
xpathByPlaceholder?: string | null;
|
|
11
|
+
xpathByType?: string | null;
|
|
12
|
+
visibleText?: string | null;
|
|
13
|
+
relativeXpath?: string | null;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
};
|
|
16
|
+
declare const getElementsFromHTML: (record: ElementRecord, docmt: Document) => ElementDetails | null;
|
|
17
|
+
export { getElementsFromHTML };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare function getXPathUsingAttributeAndText(attributes: Attr[], targetElemt: HTMLElement | Element, docmt: Document, isTarget: boolean): string | undefined;
|
|
2
|
+
export declare const attributesBasedXPath: (attr: Attr, targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
3
|
+
export declare const getUniqueClassName: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
4
|
+
export declare const getTextXPath: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
5
|
+
export declare const parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean, includedAttributes?: Attr[]) => {
|
|
6
|
+
key: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}[];
|
|
9
|
+
declare const xpath: {
|
|
10
|
+
parseDOM: (element: HTMLElement | Element, doc: Document, isIndex: boolean, isTarget: boolean, includedAttributes?: Attr[]) => {
|
|
11
|
+
key: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
getTextXPath: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
15
|
+
getUniqueClassName: (element: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
16
|
+
attributesBasedXPath: (attr: Attr, targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
17
|
+
addAllXPathAttributes: (attributes: Attr[], targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean) => void;
|
|
18
|
+
addRelativeXpaths: (targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean, attribute: Attr[]) => {
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[] | undefined;
|
|
22
|
+
getXPathUsingAttributeAndText: typeof getXPathUsingAttributeAndText;
|
|
23
|
+
getSiblingRelativeXPath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean, nodeXpath: string) => null | undefined;
|
|
24
|
+
getChildRelativeXpath: (domNode: HTMLElement | Element, docmt: Document, node: HTMLElement | Element) => string | null;
|
|
25
|
+
getParentRelativeXpath: (domNode: HTMLElement, docmt: Document, node: HTMLElement | Element, isTarget: boolean) => any;
|
|
26
|
+
getUniqueParentXpath: (domNode: HTMLElement, docmt: Document, node: HTMLElement | Element, isTarget: boolean, nodeXpath: string, isIndex: boolean) => any;
|
|
27
|
+
checkRelativeXpathRelation: (nodeXpath1: string, nodeXpath2: string, targetElemt: HTMLElement | Element, docmt: Document, isIndex: boolean, relationType: string) => string | null;
|
|
28
|
+
};
|
|
29
|
+
export default xpath;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export declare const reWhiteSpace: RegExp;
|
|
2
|
+
export declare let cspEnabled: boolean;
|
|
3
|
+
export declare let modifiedElementAttributes: {
|
|
4
|
+
url: string | null;
|
|
5
|
+
attributeName: string | null;
|
|
6
|
+
element: HTMLElement | Element;
|
|
7
|
+
doc: Document;
|
|
8
|
+
}[];
|
|
9
|
+
export declare const createObserver: (addedNodeCallBack: Function) => void;
|
|
10
|
+
export declare const startObserver: (target: Node, options: MutationObserverInit | undefined) => void;
|
|
11
|
+
export declare const stopObserver: () => void;
|
|
12
|
+
export declare const isNumberExist: (str: string) => boolean;
|
|
13
|
+
export declare const buildPattern: (pattern: string, isSvg: boolean, tagName: string) => string;
|
|
14
|
+
export declare const getTextContent: (targetElement: HTMLElement | Element) => string;
|
|
15
|
+
export declare const getFilteredText: (element: Node) => string;
|
|
16
|
+
export declare const getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node, multiElementReferenceMode?: boolean) => number;
|
|
17
|
+
export declare const escapeCharacters: (text: string) => string;
|
|
18
|
+
export declare const removeParenthesis: (xpath: string) => string;
|
|
19
|
+
export declare const findXpathWithIndex: (val: string, node: HTMLElement | Element, docmt: Node, count: number) => string | undefined;
|
|
20
|
+
export declare const replaceWhiteSpaces: (str: string) => string;
|
|
21
|
+
export declare const getShadowRoot: (el: HTMLElement | Element) => Element | null;
|
|
22
|
+
export declare const checkBlockedAttributes: (attribute: {
|
|
23
|
+
name: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}, targetElement: HTMLElement | Element, isTarget: boolean) => boolean;
|
|
26
|
+
export declare const getRelationship: (a: HTMLElement, b: HTMLElement) => string;
|
|
27
|
+
export declare const isSvg: (element: HTMLElement | Element) => element is SVGElement;
|
|
28
|
+
export declare const replaceTempAttributes: (str: string) => string;
|
|
29
|
+
export declare const getPropertyXPath: (element: HTMLElement | Element, docmt: Document, prop: string, value: string, isIndex: boolean, isTarget: boolean) => string | undefined;
|
|
30
|
+
export declare const getAbsoluteXPath: (domNode: HTMLElement | Element | null, docmt: Document) => string;
|
|
31
|
+
export declare const getRelativeXPath: (domNode: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean | undefined, attributesArray: Attr[]) => any;
|
|
32
|
+
export declare const getCombinationXpath: (attribute: Attr, domNode: HTMLElement | Element) => string | undefined;
|
|
33
|
+
export declare const getAttributeCombinationXpath: (domNode: HTMLElement | Element, docmt: Document, uniqueAttributes: Attr[], isTarget: boolean) => string | undefined;
|
|
34
|
+
export declare const intermediateXpathStep: (targetElemt: HTMLElement | Element, attr: {
|
|
35
|
+
name: string;
|
|
36
|
+
value: string;
|
|
37
|
+
}, isTarget: boolean) => string;
|
|
38
|
+
export declare const getFilteredTextXPath: (node: HTMLElement | Element, docmt: Document) => string;
|
|
39
|
+
export declare const getTextXpathFunction: (domNode: HTMLElement | Element) => string | undefined;
|
|
40
|
+
export declare const getXpathString: (node: HTMLElement | Element, attrName: string, attrValue: string) => string;
|
|
41
|
+
export declare const replaceActualAttributes: (str: string, element: {
|
|
42
|
+
attributes: any;
|
|
43
|
+
}) => string;
|
|
44
|
+
export declare const getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
45
|
+
key: string;
|
|
46
|
+
value: string;
|
|
47
|
+
}[];
|
|
48
|
+
export declare const parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
49
|
+
export declare const normalizeXPath: (xpath: string) => string;
|
|
50
|
+
export declare const findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
51
|
+
export declare function canonicalizeXPath(xpath: string): string;
|
|
52
|
+
export declare function extractXPathSignatureParts(xpath: string): {
|
|
53
|
+
axis: string;
|
|
54
|
+
attribute: string;
|
|
55
|
+
usesNormalize: boolean;
|
|
56
|
+
};
|
|
57
|
+
export declare function getXPathPattern(xpath: string): string;
|
|
58
|
+
export declare function escapeAttrValue(value: string): string;
|
|
59
|
+
export declare function isUniqueInDOM(docmt: Document, name: string, value: string): boolean;
|
|
60
|
+
export declare const xpathUtils: {
|
|
61
|
+
parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
62
|
+
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
63
|
+
key: string;
|
|
64
|
+
value: string;
|
|
65
|
+
}[];
|
|
66
|
+
getAbsoluteXPath: (domNode: HTMLElement | Element | null, docmt: Document) => string;
|
|
67
|
+
getRelativeXPath: (domNode: HTMLElement | Element, docmt: Document, isIndex: boolean, isTarget: boolean | undefined, attributesArray: Attr[]) => any;
|
|
68
|
+
getCombinationXpath: (attribute: Attr, domNode: HTMLElement | Element) => string | undefined;
|
|
69
|
+
getAttributeCombinationXpath: (domNode: HTMLElement | Element, docmt: Document, uniqueAttributes: Attr[], isTarget: boolean) => string | undefined;
|
|
70
|
+
getElementFromXpath: (xpath: string, docmt: Node, multi?: boolean) => Node | XPathResult | null;
|
|
71
|
+
isSvg: (element: HTMLElement | Element) => element is SVGElement;
|
|
72
|
+
findXpathWithIndex: (val: string, node: HTMLElement | Element, docmt: Node, count: number) => string | undefined;
|
|
73
|
+
isNumberExist: (str: string) => boolean;
|
|
74
|
+
getTextContent: (targetElement: HTMLElement | Element) => string;
|
|
75
|
+
getCountOfXPath: (xpath: string, element: HTMLElement | Element, docmt: Node, multiElementReferenceMode?: boolean) => number;
|
|
76
|
+
normalizeXPath: (xpath: string) => string;
|
|
77
|
+
getShadowRoot: (el: HTMLElement | Element) => Element | null;
|
|
78
|
+
escapeCharacters: (text: string) => string;
|
|
79
|
+
removeParenthesis: (xpath: string) => string;
|
|
80
|
+
checkBlockedAttributes: (attribute: {
|
|
81
|
+
name: string;
|
|
82
|
+
value: string;
|
|
83
|
+
}, targetElement: HTMLElement | Element, isTarget: boolean) => boolean;
|
|
84
|
+
getRelationship: (a: HTMLElement, b: HTMLElement) => string;
|
|
85
|
+
findMatchingParenthesis: (text: string, openPos: number) => number;
|
|
86
|
+
deleteGarbageFromInnerText: (a: string) => string;
|
|
87
|
+
replaceTempAttributes: (str: string) => string;
|
|
88
|
+
createObserver: (addedNodeCallBack: Function) => void;
|
|
89
|
+
startObserver: (target: Node, options: MutationObserverInit | undefined) => void;
|
|
90
|
+
stopObserver: () => void;
|
|
91
|
+
modifiedElementAttributes: {
|
|
92
|
+
url: string | null;
|
|
93
|
+
attributeName: string | null;
|
|
94
|
+
element: HTMLElement | Element;
|
|
95
|
+
doc: Document;
|
|
96
|
+
}[];
|
|
97
|
+
cspEnabled: boolean;
|
|
98
|
+
getXPathPattern: typeof getXPathPattern;
|
|
99
|
+
escapeAttrValue: typeof escapeAttrValue;
|
|
100
|
+
isUniqueInDOM: typeof isUniqueInDOM;
|
|
101
|
+
};
|
package/dist/xpath.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{fileURLToPath as e}from"url";import o,{join as t}from"path";import{readFileSync as a}from"fs";const r=e(import.meta.url);let n;const l=a(t(o.dirname(r),"index.cdn.js"),"utf-8");async function c(){n=await import("puppeteer");let e=await n.launch({headless:!0}),o=await e.newPage();return{fromHTML:async e=>(await(o?.setContent(e.replace(/\\n/g,"").replaceAll(/\\t/g,"").replace(/\\"/g,'"'),{waitUntil:"domcontentloaded"})),await(o?.addScriptTag({content:l})),o?.on("console",async e=>{const o=e.type(),t=e.text(),a=e.args();if(a&&0!==a.length)for(let e=0;e<a.length;e++)try{const r=a[e],n=r.remoteObject();if(console.log(n),void 0!==n.value)console.log(`[Browser:${o}]`,n.value);else{const e=await r.jsonValue().catch(()=>t);console.log(`[Browser:${o}]`,e)}}catch(e){console.log(`[Browser:${o}]`,t)}else console.log(`[Browser:${o}]`,t)}),o?.on("pageerror",e=>{console.log("error",e)}),{autoHeal:async(e,t)=>await(o?.evaluate(e=>window.XpathLib.createXPathAPI().getElementsFromHTML(e,document),e))}),browser:e}}export{c as default};
|
|
1
|
+
import{VirtualConsole as e,JSDOM as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/gi,a={};let l=[];const o=e=>/\d/.test(e),r=e=>e?.childNodes[0]?.nodeValue||"",s=(e,t,n,l=!1)=>{try{let o;if(void 0!==a[e])o=a[e];else{o=(9===n.nodeType?n:n.ownerDocument).evaluate(`count(${e})`,n,null,XPathResult.NUMBER_TYPE,null).numberValue,a[e]=o}if(l&&Array.isArray(t)){if(o>1){const a=d(e,n,!0);let l,o=0;if(a instanceof XPathResult)for(;(l=a?.iterateNext())&&(!t.includes(l)||(o+=1,2!==o)););if(2!==o)return 0}}else if(1===o){return d(e,n)===t?o:0}return o}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},i=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},c=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===s(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===s(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const r=l.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let i;for(;i=r.iterateNext();)if(o++,i.isSameNode(t))return 1===s(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===s(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},u=e=>e?e.replace(/\s\s+/g," ").trim():e,m=(e,t,n)=>!(!e?.value||"boolean"==typeof e?.value||["true","false","on","off","flntooltip"].some(t=>t===e.value)||["type","style","locator-data-tooltip","value"].some(t=>t===e.name)||l?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name)||0===e?.name?.indexOf("on")&&e?.name?.length>3||"function"==typeof e.value||n&&o(e.value)),f=e=>e instanceof SVGElement,d=(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const l=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?l.evaluate(e,a,null,XPathResult.ANY_TYPE,null):l.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},h=(e,t,a,l,r,c)=>{if(l){const{tagName:m}=e;let d,h="";const g=[];let p;if(l&&(!c||!o(l))&&(p=n.test(l)?`//${m}[${a}=${i(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${i(u(l)).trim()}`,f(e),e.tagName.toLowerCase()),d=s(p,e,t),1===d&&!r))return p;if(l&&c){const o=l.split(" ");if(o?.length)if(1===o.length){const c=[...new Set(o[0].match(/([^0-9]+)/g))];if(c?.length>=1&&c[0]&&u(c[0].trim())?.length>1&&l.startsWith(c[0])&&(h=n.test(c[0])?`starts-with(${a},${i(c[0]).trim()})`:`starts-with(${a},${i(u(c[0])).trim()})`),c?.length>1&&c[c.length-1]&&u(c[c.length-1].trim())?.length>1&&l.endsWith(c[c.length-1])&&(h=n.test(c[c.length-1])?`ends-with(${a},${i(c[c.length-1]).trim()})`:`ends-with(${a},${i(u(c[c.length-1])).trim()})`),h?.length&&(p=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(p,e,t),1===d&&!r))return p}else{const c=o.length%2==0?o.length/2:o.length%2,g=o.slice(0,c).join(" ");let $=[...new Set(g.match(/([^0-9]+)/g))];if($?.length&&$[0]&&u($[0].trim())?.length&&l.startsWith($[0])&&(h=n.test($[0])?`starts-with(${a},${i($[0]).trim()})`:`starts-with(${a},${i(u($[0])).trim()})`),h?.length&&(p=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(p,e,t),1===d&&!r))return p;const y=o.slice(c,o.length-1).join(" ");if($=[...new Set(y.match(/([^0-9]+)/g))],$?.length&&$[0]&&u($[0].trim())?.length>3&&l.endsWith($[0])&&(h=n.test($[0])?`ends-with(${a},${i($[0]).trim()})`:`ends-with(${a},${i(u($[0])).trim()})`),h?.length&&(p=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(p,e,t),1===d&&!r))return p}}if(l&&c&&o(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let e=0;e<o?.length;e++)o[e]&&u(o[e].trim())?.length>1&&(n.test(o[e])?g.push(`contains(${a},${i(o[e].trim()).trim()})`):g.push(`contains(${a},${i(u(o[e])).trim()})`));if(g?.length&&(p=f(e)?`//*[local-name()='${m}' and ${g.join(" and ")}]`:`//${m}[${g.join(" and ")}]`,d=s(p,e,t),1===d&&!r))return p}if(p=f(e)?`//*[local-name()='${m}' and text()]`:`//${m}[text()]`,d=s(p,e,t),1===d&&!r)return p}},g=(e,t,a)=>{let l=f(e),o="";if(m(t,e,a)){let a=t.value;a=a.replace("removePointers","");const r=t.name;o=n.test(a)?l?`*[local-name()='${e.tagName}' and @${r}=${i(a)}]`:`${e.tagName||"*"}[@${r}=${i(a)}]`:l?`*[local-name()='${e.tagName}' and normalize-space(@${r})=${i(a)}]`:`${e.tagName||"*"}[normalize-space(@${r})=${i(a)}]`}return o},p=(e,t)=>{if(!e.textContent)return"";const a=r(e);let l;return l=n.test(a)?f(e)?`//*[local-name()='${e.tagName}' and .=${i(a)}]`:`//${e.tagName||"*"}[.=${i(a)}]`:f(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${i(a)}]`:`//${e.tagName||"*"}[normalize-space(.)=${i(a)}]`,l},$=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.test(n)?"class"===t?f(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`:f(e)?`//*[local-name()='${e.tagName}' and @${t}=${i(n)}]`:`//${e.tagName||"*"}[@${t}=${i(n)}]`:f(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`),l},y=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function v(e){const t=function(e){return e.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e),n=function(e){const t=e.toLowerCase(),n=t.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=n?.[1]??"none",l=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:l?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function x(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function N(e,t,n){try{switch(t){case"id":return null!==e.getElementById(n)&&1===e.querySelectorAll(`#${n}`).length;case"name":return 1===e.querySelectorAll(`[name="${x(n)}"]`).length;case"className":return 1===e.getElementsByClassName(n).length;case"tagName":return 1===e.getElementsByTagName(n).length;case"linkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}let b=[],E=[],S=new Map,w=new Map;const R=new Map,k=(e,t,n,a,l,o)=>{if(e){let r;r="parent"===o?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of r){S?.get(e)||S.set(e,s(e,n,a));const t=S?.get(e);if(1===t)return e;if(t>1&&(E.length?t<E[0].count&&(E.pop(),E.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):E.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!b.length){const o=c(e,n,a,t);o&&1===s(o,n,a)&&b.push({key:"relative xpath by unique parent "+(l?"index":""),value:o})}}}return null},T=(e,t,a,l,c,d)=>{try{if(R.has(e))return R.get(e);const h=[];let g=e;for(;g&&1===g.nodeType;){const e=!1;for(const e of Array.from(g.attributes))if(m(e,g,l)){let n=e.nodeValue;n=n?.replace("removePointers","")??"";const l=e.name,o=$(g,l,n);let r;try{r=k(o,c,a,t,d,"parent")}catch(e){continue}if(r)return r}if(g.textContent&&!g.textContent)if(!l||l&&!o(g.textContent)){let e;e=n.test(g.textContent)?f(g)?`//*[local-name()='${g.tagName}' and .=${i(r(g))}]`:`//${g.tagName||"*"}[.=${i(r(g))}]`:f(g)?`//*[local-name()='${g.tagName}' and normalize-space(.)=${i(r(g))}]`:`//${g.tagName||"*"}[normalize-space(.)=${i(r(g))}]`;const l=k(e,c,a,t,d,"parent");if(l)return l}else{const e=[],n=[...new Set(r(g).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(n?.length)for(let t=0;t<n?.length;t++)n[t]&&u(n[t].trim())&&(l.test(n[t])?e.push(`contains(.,${i(n[t].trim()).trim()})`):e.push(`contains(.,${i(u(n[t])).trim()})`));if(e?.length){const n=f(g)?`//*[local-name()='${g.tagName}' and ${e.join(" and ")}]`:`//${g.tagName||"*"}[${e.join(" and ")}]`,l=k(n,c,a,t,d,"parent");if(l)return l}}if(!e){const e=f(g)?`/*[local-name()='${g.tagName}']`:`/${g.tagName}`;h.unshift(e)}g=g.parentElement}const p=h.join("")+c;if(1===s(p,e,t))return R.set(e,p),p}catch(e){return console.error(e),null}},C=(e,t,n,a)=>{const l=new Map;if(l.has(e))return l.get(e);const o=[];let r=e;try{for(;r&&1===r.nodeType;){if(!r.tagName)return"";let e=!1;for(const n of Array.from(r.attributes))if(m(n,r,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,i=$(r,l,a);let c;try{c=s(i,r,t)}catch(e){continue}if(1===c){o.unshift(i),e=!0;break}}if(!e&&r.textContent&&!n.textContent){const n=p(r);if(n){if(1===s(n,r,t)){e=!0,o.unshift(n);break}}}if(e)break;{const e=f(r)?`/*[local-name()='${r.tagName}']`:`/${r.tagName}`;o.unshift(e)}r=r.parentElement}const i=o.join("");return l.set(e,i),i}catch(e){return console.log(e),null}},A=(e,t,n)=>{const a=[];let l;const o=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?o.unshift(e.firstElementChild):null!=e.nextElementSibling&&o.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&o.unshift(t.nextElementSibling);try{do{let e=!1;for(l=o.pop();null!==l;){for(const n of Array.from(l.attributes))if(m(n,l,!0)){let o=n.nodeValue;o=o?.replace("removePointers","")??"";const r=n.name,i=$(l,r,o);let c;try{c=s(i,l,t)}catch(e){continue}if(1===c){e=!0,a.push(i);break}}if(!e&&l.textContent&&!n.textContent){const n=p(l);if(n){if(1===s(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=f(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;a.push(e),null!=l.firstElementChild?(o.push(l.nextElementSibling),l=l.firstElementChild):l=l.nextElementSibling}}}while(o.length>0);const r=a.join("");return w.set(e,r),r}catch(e){return console.log(e),null}},P=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==l;o=o.nextElementSibling)Y(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==l;o=o.previousElementSibling)Y(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},Y=(e,t,n,a,l,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let r=g(e,{name:t.name,value:t.value},o);if(r){r+=`/${l}::${a}`;const t=s(r,e,n);if(1===t)return void b.push({key:`xpath by ${l}`,value:r});t>1&&(E.length?t<E[0].count&&(E.pop(),E.push({key:`relative xpath by ${l}`,value:r,count:t})):E.push({key:`relative xpath by ${l}`,value:r,count:t}))}}if(!o){let t;if(t=g(e,{name:"text",value:e.textContent},o),t){const a=s(t,e,n);if(1===a)return void b.push({key:`xpath by ${l}`,value:t});a>1&&(E.length?a<E[0].count&&(E.pop(),E.push({key:`relative xpath by ${l}`,value:t,count:a})):E.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};const D=(e,t,n,a)=>{if(""!=e.textContent){const l=(e=>{const t=e?.textContent;return t})(e);if(l)return h(e,t,".",l,n,a)}},q=(e,t,a,l,o)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&m(e,t,o)){const n=((e,t,n,a,l)=>{let o;return o=e.name,h(t,n,`@${o}`,e.value,a,l)})(e,t,a,l,o);n&&b.push({key:`xpath by ${e.name}${l?" index":""}`,value:n})}});const i=D(t,a,l,o);if(i&&b.push({key:"xpath by text"+(l?" index":""),value:i}),r.find(e=>"className"===e.name)&&m(r?.find(e=>"className"===e.name),t,o)){let e=((e,t,n,a)=>{let l=e.className;if("string"!=typeof l&&(l=""),l=l?.replace("flndisabled","disabled"),l=l?.replace("removePointers",""),l=l?.trim(),l)return h(e,t,"@class",l,n,a)})(t,a,l,o);e&&b.push({key:"xpath by class",value:e})}if(!b.length){const n=function(e,t,n,a){const{tagName:l}=t,o=t.textContent.trim();for(const r of e)if(m(r,t,a)){let e=r.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${r.name}='${e}' and text()='${o}']`;if(a&&1==s(a,t,n))return a}}(e,t,a,o);n&&b.push({key:"xpath by textAttribute",value:n})}if(!b.length&&r.length>1){const e=((e,t,a,l)=>{try{const o=[];if(a.length>1)for(const r of a)if(m(r,e,l)){const a=r.nodeValue;n.test(a)?"class"===r.nodeName?o.push(`contains(@${r.nodeName},"${a}")`):o.push(`@${r.nodeName}="${a}"`):o.push(`normalize-space(@${r.nodeName})="${a}"`);const l=f(e)?`//*[local-name()='${e.tagName}' and ${o.join(" and ")}]`:`//${e.tagName}[${o.join(" and ")}]`;let i;try{i=s(l,e,t)}catch(e){continue}if(1===i&&!l.includes("and"))return"";if(1===i&&l.includes("and"))return l}}catch(e){console.log(`'${JSON.stringify(e,null,2)}'`)}})(t,a,r,o);e&&b.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},_=(e,t,n,a,l=[])=>{b=[],console.log(e);const o=e,r=o?.ownerDocument||t,i=o.tagName,{attributes:u}=o,m=l.length>0?l:Array.from(u);if(q(m,o,r,n,a),b.length){const t=b.length;for(let n=0;n<t;n++){let t=b[n].value;t="//*"+t.substring(t.indexOf("//")+2+i.length);1===s(t,e,r)&&b.push({key:`${b[n].key} regex`,value:t})}}return b.length||((e,t,n,a,l)=>{try{let o,r,i=[];if(b=[],console.log(l),l)for(const t of l){let n=g(e,{name:t.name,value:t.value},a);console.log(n),n&&i.push(n)}if(e.textContent){let t=g(e,{name:"text",value:e.textContent},a);console.log(t),t&&i.push(t)}if(i.push(e.tagName),i?.length)for(let l=0;l<i.length;l++)if(!b.length){if(P(e,t,a,i[l]),!b.length&&(o||(o=C(e.parentElement,t,e,a)),console.log(o),o&&(o.includes("@")||o.includes("text()")||o.includes(".="))&&o.match(/\//g)?.length-2<5)){const a=o+`/${i[l]}`,r=s(a,e,t);if(1===r)b.push({key:"relative xpath by relative parent",value:a});else if(r>1&&n){const l=c(a,e,t,r);l&&1===s(l,e,t)&&b.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!b.length&&(r||(r=A(e,t,e)),r&&(r.includes("@")||r.includes("text()")||r.includes(".=")))){const a=`/${i[l]+r.substring(1)}`,o=s(a,e,t);if(1===o)b.push({key:"relative xpath by relative child",value:a});else if(o>1&&n){const l=c(a,e,t,o);l&&1===s(l,e,t)&&b.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===b?.length&&b?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=D(e,t,n,!1);a&&b.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!b.length){let o=T(e.parentElement,t,e,a,i[l],n);o&&b.push({key:"xpath by unique parent",value:o})}}return b}catch(e){console.log(e)}})(o,r,n,a,Array.from(o.attributes)),b},j=(e,t,n)=>L(t,y(e))===n,O=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:a}=n[e];if(a&&(O(a,t),a&&!t.includes("dynamic")))return a.querySelector(t)}}catch(e){console.log(e)}return null},z=e=>e?.id||null,V=e=>e.className||null,X=e=>e.textContent?.trim()||null,I=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},H=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function L(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function M(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),l=n.defaultView;if(!l)return null;if(!e.includes("dynamic")){const t=new l.XPathEvaluator;if(t.evaluate(a,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(a=e,a):(console.error("Complete Locator is Invalid:",e),a=e,a)}console.error("Source Locator Not Found:",a)}}return null}const W=(e,t)=>{const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const a=new Set;let l=[];function r(e,t={}){const n=e?.value,o=t.value??e?.value,r={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;r.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(r.name,n,o),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(r)}const s=(e,t,n)=>{if(!e)return null;let a=e.trim();return a&&"null"!==a.toLowerCase()?(a=a.replace(/\\"/g,'"').replace(/\\'/g,"'"),a=a.replace(/^['"](.+?)['"]$/,"$1"),a=a.replace(/''/g,"'"),a=a.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(a=a.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!a||/^['"]{2}$/.test(a)?null:a:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const i=e.locators.filter(e=>"N"===e.isRecorded);if(i.length>0)for(const e of i)r(e);const c=String(n.value||n.type||"");if(c.includes("dynamic")||c.match("dynamic")||c.includes("{")||c.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let i=null;if(n.value.startsWith("iframe")){const e=t.querySelector(n.value);if(e){const t=e.contentDocument||e.contentWindow?.document;t&&(i=t.querySelector(n.value.slice(6)))}}else{const e=n.value.split(">>>");for(const a of e){if(!t){console.error("Element not found at:",a);break}{const e=a.trim();if(n.name.includes("id")||e.startsWith("#"))i=t.querySelector("#"+e);else if(n.name.includes("className")||e.startsWith("."))i=t.querySelector("."+e);else if("name"===n.name){const n=x(e);i=t.querySelector(`[name="${n}"]`)}else if("tagName"===n.name)i=t.querySelector(e);else if("linkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.trim()===e)||null;else if("partialLinkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.includes(e))||null;else if(!n.name.includes("xpath")&&!e.startsWith("//")||n.type.match("dynamic"))i=t.querySelector(e),i||(i=O(t.body,e));else{const a=y(e);i=L(t,a),i&&r(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const c=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(i){const n=e.locators.filter(e=>"xpath"===e.name&&e.value);for(const e of n)j(e.value,t,i)&&r(e,{isSelfHealed:null});const a=l.filter(e=>"xpath"===e.name&&e.value),u=new Set(a.map(e=>v(e.value))),m=[],f=z(i);if(f&&!c("id",f)&&!o(f)){const n=e.locators.find(e=>"id"===e.name);N(t,"id",f)&&(m.push("id"),r(n,{name:"id",type:"static",isRecorded:"Y",value:f}))}const d=i.tagName;if(d&&!c("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);N(t,"tagName",d)&&(m.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const h=X(i);if(h&&!o(h)){const n=e.locators.find(e=>"linkText"===e.name);N(t,"linkText",h)&&(m.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:h}))}const g=I(i);if(g&&!c("name",g)&&!o(g)){const n=e.locators.find(e=>"name"===e.name);N(t,"name",g)&&(m.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:g}))}const p=V(i);if(p&&""!==p.trim()&&!c("className",p)&&!o(p)){const n=e.locators.find(e=>"className"===e.name);N(t,"className",p)&&(m.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:p}))}const $=Array.from(i.attributes).filter(e=>!m.includes(e.name)),y=_(i,t,!1,!0,$);if(0!==y?.length){const e=n.filter(e=>!j(e.value,t,i));let a=0;for(const t of e){if(a>=e.length)break;const n=v(t.value);if(u.has(n))continue;const l=y.find(e=>e.value&&v(e.value)===n);l?.value&&(r(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),a++)}if(a<e.length)for(const t of y){if(a>=e.length)break;if(!t.value)continue;const n=v(t.value);u.has(n)||(r(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of H)if(a.value.includes(e)){const l=M(a.value,e,t);if(l){r(a,{name:"xpath",value:l,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(l.length<5){const e=[{name:"id",value:z(i)},{name:"name",value:I(i)},{name:"className",value:V(i)},{name:"tagName",value:i.tagName},{name:"linkText",value:X(i)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(o(a)||c(e,a)||N(t,e,a)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}}const x=l.map(e=>({...e,value:s(e.value,e.name,e.isRecorded)})),b=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:x.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return b}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};async function F(){return{fromHTML:async n=>{const a=new e,l=new t(n.replace(/\n/g,"").replace(/\t/g,"").replace(/\\"/g,'"').replace(/\\n/g,"").replace(/\\t/g,"").replace(/\\\\/g,'"'),{pretendToBeVisual:!0,runScripts:"outside-only",virtualConsole:a}),{window:o}=l;return global.document=o.document,global.Node=o.Node,global.Element=o.Element,global.HTMLElement=o.HTMLElement,global.SVGElement=o.SVGElement,global.XPathResult=o.XPathResult,global.XPathEvaluator=o.XPathEvaluator,{autoHeal:async e=>W(e,o.document)}}}}export{F as default};
|
|
2
2
|
//# sourceMappingURL=xpath.mjs.map
|