ff-dom 2.0.2 → 2.0.4
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 +5 -2
- package/dist/types/browser/utils/referenceXpath.d.ts +1 -1
- 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/dist/index.browser.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/gi;const t={};let n,l=new Map,a=[];const r=e=>/\d/.test(e),o=e=>{const t=e?.textContent;return t},s=e=>e?.childNodes[0]?.nodeValue||"",i=(e,n,l,a=!1)=>{try{let r;if(void 0!==t[e])r=t[e];else{r=(9===l.nodeType?l:l.ownerDocument).evaluate(`count(${e})`,l,null,XPathResult.NUMBER_TYPE,null).numberValue,t[e]=r}if(a&&Array.isArray(n)){if(r>1){const t=v(e,l,!0);let a,r=0;if(t instanceof XPathResult)for(;(a=t?.iterateNext())&&(!n.includes(a)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return v(e,l)===n?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},c=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},u=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},m=(e,t,n,l)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let r=0;if(l){if(1===i(`${e}[${l}]`,t,n))return`${e}[${l}]`;if(1===i(`(${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===i(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===i(`(${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(),f=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},g=(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)||a?.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&&r(e.value)),p=e=>e instanceof SVGElement,$=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,v=(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},y=(t,n,l,a,o,s)=>{if(a){const{tagName:u}=t;let m,h="";const d=[];let g;if(a&&(!s||!r(a))&&(g=e.test(a)?`//${u}[${l}=${c(a)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${l})=${c(f(a)).trim()}`,p(t),t.tagName.toLowerCase()),m=i(g,t,n),1===m&&!o))return g;if(a&&s){const r=a.split(" ");if(r?.length)if(1===r.length){const s=[...new Set(r[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&f(s[0].trim())?.length>1&&a.startsWith(s[0])&&(h=e.test(s[0])?`starts-with(${l},${c(s[0]).trim()})`:`starts-with(${l},${c(f(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&f(s[s.length-1].trim())?.length>1&&a.endsWith(s[s.length-1])&&(h=e.test(s[s.length-1])?`ends-with(${l},${c(s[s.length-1]).trim()})`:`ends-with(${l},${c(f(s[s.length-1])).trim()})`),h?.length&&(g=p(t)?`//*[local-name()='${u}' and ${h}]`:`//${u}[${h}]`,m=i(g,t,n),1===m&&!o))return g}else{const s=r.length%2==0?r.length/2:r.length%2,d=r.slice(0,s).join(" ");let $=[...new Set(d.match(/([^0-9]+)/g))];if($?.length&&$[0]&&f($[0].trim())?.length&&a.startsWith($[0])&&(h=e.test($[0])?`starts-with(${l},${c($[0]).trim()})`:`starts-with(${l},${c(f($[0])).trim()})`),h?.length&&(g=p(t)?`//*[local-name()='${u}' and ${h}]`:`//${u}[${h}]`,m=i(g,t,n),1===m&&!o))return g;const v=r.slice(s,r.length-1).join(" ");if($=[...new Set(v.match(/([^0-9]+)/g))],$?.length&&$[0]&&f($[0].trim())?.length>3&&a.endsWith($[0])&&(h=e.test($[0])?`ends-with(${l},${c($[0]).trim()})`:`ends-with(${l},${c(f($[0])).trim()})`),h?.length&&(g=p(t)?`//*[local-name()='${u}' and ${h}]`:`//${u}[${h}]`,m=i(g,t,n),1===m&&!o))return g}}if(a&&s&&r(a)){const r=[...new Set(a.match(/([^0-9]+)/g))];if(r?.length)for(let t=0;t<r?.length;t++)r[t]&&f(r[t].trim())?.length>1&&(e.test(r[t])?d.push(`contains(${l},${c(r[t].trim()).trim()})`):d.push(`contains(${l},${c(f(r[t])).trim()})`));if(d?.length&&(g=p(t)?`//*[local-name()='${u}' and ${d.join(" and ")}]`:`//${u}[${d.join(" and ")}]`,m=i(g,t,n),1===m&&!o))return g}if(g=p(t)?`//*[local-name()='${u}' and text()]`:`//${u}[text()]`,m=i(g,t,n),1===m&&!o)return g}},b=(e,t)=>{try{if(!e)return"";let n=p(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),""}},N=(e,t,n,a=!1,o)=>{try{if(l.has(e))return l.get(e);const u=[];let h=e;for(;h;){let l="",d=!1,v=e===h?o??h.attributes:h.attributes;for(const e of Array.from(v))if(g(e,h,a)){let a=e.nodeValue;a=a?.replace("removePointers","")??"";const r=e.name;l=R(h,r,a);let o=0;if(l&&(o=i(l,h,t),1===o)){u.unshift($(l)),d=!0;break}if(o>1&&n&&(l=m(l,h,t,o),l)){u.unshift($(l)),d=!0;break}}if(h.textContent)if(!a||a&&!r(h.textContent)){l=new RegExp(/^[\S]+( [\S]+)*$/gi).test(h.textContent)?p(h)?`//*[local-name()='${h.tagName}' and .=${c(s(h))}]`:`//${h.tagName||"*"}[.=${c(s(h))}]`:p(h)?`//*[local-name()='${h.tagName}' and normalize-space(.)=${c(s(h))}]`:`//${h.tagName||"*"}[normalize-space(.)=${c(s(h))}]`;let e=i(l,h,t);if(1===e)return l;if(e>1&&n)return l=m(l,h,t,e),l}else{let e=[];const a=[...new Set(s(h).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&f(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${c(a[t].trim()).trim()})`):e.push(`contains(.,${c(f(a[t])).trim()})`));if(e?.length){l=p(h)?`//*[local-name()='${h.tagName}' and ${e.join(" and ")}]`:`//${h.tagName||"*"}[${e.join(" and ")}]`;let a=i(l,h,t);if(1===a)return l;if(a>1&&n)return l=m(l,h,t,a),l}}if(d)break;{let e=p(h)?`/*[local-name()='${h.tagName}']`:`/${h.tagName}`;if(h.parentElement){const t=Array.from(h.parentElement.children).filter(e=>e.tagName===h.tagName);if(t.length>1){e+=`[${t.indexOf(h)+1}]`}}u.unshift(e)}h=h.parentElement}const d=`${u.join("")}`;return l.set(e,d),d}catch(e){return console.log(e),null}},x=(t,n)=>{const l=[];let a="";if(t&&!r(t.value)&&"function"!=typeof t.nodeValue){const r=[...new Set(t.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&f(r[n].trim())?.length>2&&(e.test(r[n])?l.push(`contains(@${t.name},${c(r[n].trim())})`):l.push(`contains(@${t.name},${c(f(r[n])).trim()})`));if(l?.length)return a=p(n)?`//*[local-name()='${n.tagName}' and ${l.join(" and ")}]`:`//${n.tagName}[${l.join(" and ")}]`,a}},E=(t,n,l,a)=>{try{const r=[];if(l.length>1)for(const o of l)if(g(o,t,a)){const l=o.nodeValue;e.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=p(t)?`//*[local-name()='${t.tagName}' and ${r.join(" and ")}]`:`//${t.tagName}[${r.join(" and ")}]`;let s;try{s=i(a,t,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)}'`)}},S=(t,n,l)=>{let a=p(t),r="";if(g(n,t,l)){let l=n.value;l=l.replace("removePointers","");const o=n.name;r=e.test(l)?a?`*[local-name()='${t.tagName}' and @${o}=${c(l)}]`:`${t.tagName||"*"}[@${o}=${c(l)}]`:a?`*[local-name()='${t.tagName}' and normalize-space(@${o})=${c(l)}]`:`${t.tagName||"*"}[normalize-space(@${o})=${c(l)}]`}return r},w=(t,n)=>{if(!t.textContent)return"";const l=s(t);let a;return a=e.test(l)?p(t)?`//*[local-name()='${t.tagName}' and .=${c(l)}]`:`//${t.tagName||"*"}[.=${c(l)}]`:p(t)?`//*[local-name()='${t.tagName}' and normalize-space(.)=${c(l)}]`:`//${t.tagName||"*"}[normalize-space(.)=${c(l)}]`,a},k=e=>{const t=o(e)?.trim(),n=t?c(h(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},R=(e,t,n)=>{const l=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";return n&&(a=l.test(n)?"class"===t?p(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${c(n)})]`:`//${e.tagName||"*"}[contains(@${t},${c(n)})]`:p(e)?`//*[local-name()='${e.tagName}' and @${t}=${c(n)}]`:`//${e.tagName||"*"}[@${t}=${c(n)}]`:p(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${c(n)})]`:`//${e.tagName||"*"}[contains(@${t},${c(n)})]`),a},C=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,P=(t,n,l)=>{let a;const s=[];if(t.textContent&&(!l||l&&!r(t.textContent))&&(e.test(t.textContent)?(a=p(t)?`*[local-name()='${t.tagName}' and .=${c(o(t))}]`:`${t.tagName}[.=${c(o(t))}]`,a&&s.push({key:"getReferenceElementsXpath",value:a})):(a=p(t)?`*[local-name()='${t.tagName}' and ${k(t)})]`:`${t.tagName}[${k(t)}]`,a&&s.push({key:"getReferenceElementsXpath",value:a}))),t.attributes)for(const e of Array.from(t.attributes))if(g(e,t,l)){let n=e.nodeValue;if(n){n=n.replace("removePointers","");const l=e.name;a="class"===l?p(t)?`*[local-name()='${t.tagName}' and contains(@${l},${c(n)})]`:`${t.tagName}[contains(@${l},${c(n)})]`:p(t)?`*[local-name()='${t.tagName}' and @${l}=${c(n)}]`:`${t.tagName}[@${l}=${c(n)}]`,a&&s.push({key:"getReferenceElementsXpath",value:a})}}if(!s?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=E(t,n,Array.prototype.slice.call(t.attributes),l);e&&s.push({key:"getReferenceElementsXpath",value:e})}}if(!s?.length){const n=[];let a;const o=p(t);if(t.textContent&&l&&r(t.textContent)){const l=[...new Set(t.textContent.match(/([^0-9]+)/g))];if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&f(l[t].trim())?.length>1&&(e.test(l[t])?n.push(`contains(.,${c(l[t]).trim()})`):n.push(`contains(.,${c(f(l[t])).trim()})`));n?.length&&(a=o?`//*[local-name()='${o}' and ${n.join(" and ")}]`:`//${o}[${n.join(" and ")}]`,a&&s.push({key:"getReferenceElementsXpath",value:a}))}}if(!s?.length){const e=((e,t,n,l)=>{const a=Array.prototype.slice.call(e),r=[];try{a.map(e=>{if(g(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})(t.attributes,t,0,l);e?.length&&s.concat(e)}return s},A=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"),O=(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:P,getAbsoluteXPath:b,getRelativeXPath:N,getCombinationXpath:x,getAttributeCombinationXpath:E,getElementFromXpath:v,isSvg:p,findXpathWithIndex:m,isNumberExist:r,getTextContent:o,getCountOfXPath:i,normalizeXPath:A,getShadowRoot:d,escapeCharacters:c,removeParenthesis:u,checkBlockedAttributes:g,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:O,deleteGarbageFromInnerText:h,replaceTempAttributes:$,createObserver:e=>{n=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&(p(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)||a.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{n?.observe(e,t)},stopObserver:()=>{n?.disconnect()},modifiedElementAttributes:a,cspEnabled:!1};let X=[],T=[],j=new Map,V=new Map;const L=new Map,_=(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){j?.get(e)||j.set(e,i(e,n,l));const t=j?.get(e);if(1===t)return e;if(t>1&&(T.length?t<T[0].count&&(T.pop(),T.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):T.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!X.length){const r=m(e,n,l,t);r&&1===i(r,n,l)&&X.push({key:"relative xpath by unique parent "+(a?"index":""),value:r})}}}return null},Y=(t,n,l,a,o,u)=>{try{if(L.has(t))return L.get(t);const m=[];let h=t;for(;h&&1===h.nodeType;){const t=!1;for(const e of Array.from(h.attributes))if(g(e,h,a)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const a=e.name,r=R(h,a,t);let s;try{s=_(r,o,l,n,u,"parent")}catch(e){continue}if(s)return s}if(h.textContent&&!h.textContent)if(!a||a&&!r(h.textContent)){let t;t=e.test(h.textContent)?p(h)?`//*[local-name()='${h.tagName}' and .=${c(s(h))}]`:`//${h.tagName||"*"}[.=${c(s(h))}]`:p(h)?`//*[local-name()='${h.tagName}' and normalize-space(.)=${c(s(h))}]`:`//${h.tagName||"*"}[normalize-space(.)=${c(s(h))}]`;const a=_(t,o,l,n,u,"parent");if(a)return a}else{const e=[],t=[...new Set(s(h).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&f(t[n].trim())&&(a.test(t[n])?e.push(`contains(.,${c(t[n].trim()).trim()})`):e.push(`contains(.,${c(f(t[n])).trim()})`));if(e?.length){const t=p(h)?`//*[local-name()='${h.tagName}' and ${e.join(" and ")}]`:`//${h.tagName||"*"}[${e.join(" and ")}]`,a=_(t,o,l,n,u,"parent");if(a)return a}}if(!t){const e=p(h)?`/*[local-name()='${h.tagName}']`:`/${h.tagName}`;m.unshift(e)}h=h.parentElement}const d=m.join("")+o;if(1===i(d,t,n))return L.set(t,d),d}catch(e){return console.error(e),null}},M=(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(g(n,o,l)){let l=n.nodeValue;l=l?.replace("removePointers","")??"";const a=n.name,s=R(o,a,l);let c;try{c=i(s,o,t)}catch(e){continue}if(1===c){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=w(o);if(n){if(1===i(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=p(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}},I=(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(g(n,a,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=R(a,o,r);let c;try{c=i(s,a,t)}catch(e){continue}if(1===c){e=!0,l.push(s);break}}if(!e&&a.textContent&&!n.textContent){const n=w(a);if(n){if(1===i(n,a,t)){e=!0,l.push(n);break}}}if(e)break;{const e=p(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}},q=(e,t,n,l)=>{try{const a=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==a;r=r.nextElementSibling)H(r,e,t,l,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==a;r=r.previousElementSibling)H(r,e,t,l,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},H=(e,t,n,l,a,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=S(e,{name:t.name,value:t.value},r);if(o){o+=`/${a}::${l}`;const t=i(o,e,n);if(1===t)return void X.push({key:`xpath by ${a}`,value:o});t>1&&(T.length?t<T[0].count&&(T.pop(),T.push({key:`relative xpath by ${a}`,value:o,count:t})):T.push({key:`relative xpath by ${a}`,value:o,count:t}))}}if(!r){let t;if(t=S(e,{name:"text",value:e.textContent},r),t){const l=i(t,e,n);if(1===l)return void X.push({key:`xpath by ${a}`,value:t});l>1&&(T.length?l<T[0].count&&(T.pop(),T.push({key:`relative xpath by ${a}`,value:t,count:l})):T.push({key:`relative xpath by ${a}`,value:t,count:l}))}}}catch(e){console.log(`${a} xpath-error`,e)}};function W(e,t,n,l){const{tagName:a}=t,r=t.textContent.trim();for(const o of e)if(g(o,t,l)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const l=`//${a}[@${o.name}='${e}' and text()='${r}']`;if(l){if(1==i(l,t,n))return l}}}const z=(e,t,n,l,a)=>{try{let r,o,s=[];if(X=[],console.log(a),a)for(const t of a){let n=S(e,{name:t.name,value:t.value},l);console.log(n),n&&s.push(n)}if(e.textContent){let t=S(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(!X.length){if(q(e,t,l,s[a]),!X.length&&(r||(r=M(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=i(l,e,t);if(1===o)X.push({key:"relative xpath by relative parent",value:l});else if(o>1&&n){const a=m(l,e,t,o);a&&1===i(a,e,t)&&X.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!X.length&&(o||(o=I(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const l=`/${s[a]+o.substring(1)}`,r=i(l,e,t);if(1===r)X.push({key:"relative xpath by relative child",value:l});else if(r>1&&n){const a=m(l,e,t,r);a&&1===i(a,e,t)&&X.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===X?.length&&X?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const l=B(e,t,n,!1);l&&X.unshift({key:"xpath by text"+(n?"index":""),value:l})}if(!X.length){let r=Y(e.parentElement,t,e,l,s[a],n);r&&X.push({key:"xpath by unique parent",value:r})}}return X}catch(e){console.log(e)}},F=(e,t,n,l,a)=>{let r;return r=e.name,y(t,n,`@${r}`,e.value,l,a)},U=(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 y(e,t,"@class",a,n,l)},B=(e,t,n,l)=>{if(""!=e.textContent){const a=o(e);if(a)return y(e,t,".",a,n,l)}},G=(e,t,n,l,a)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&g(e,t,a)){const r=F(e,t,n,l,a);r&&X.push({key:`xpath by ${e.name}${l?" index":""}`,value:r})}});const o=B(t,n,l,a);if(o&&X.push({key:"xpath by text"+(l?" index":""),value:o}),r.find(e=>"className"===e.name)&&g(r?.find(e=>"className"===e.name),t,a)){let e=U(t,n,l,a);e&&X.push({key:"xpath by class",value:e})}if(!X.length){const l=W(e,t,n,a);l&&X.push({key:"xpath by textAttribute",value:l})}if(!X.length&&r.length>1){const e=E(t,n,r,a);e&&X.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},J=(e,t,n,l)=>{X=[],console.log(e);const a=e,r=a?.ownerDocument||t,o=a.tagName,{attributes:s}=a;if(G(Array.from(s),a,r,n,l),X.length){const t=X.length;for(let n=0;n<t;n++){let t=X[n].value;t="//*"+t.substring(t.indexOf("//")+2+o.length);1===i(t,e,r)&&X.push({key:`${X[n].key} regex`,value:t})}}return console.log(X),X.length||z(a,r,n,l,Array.from(a.attributes)),X},Z={parseDOM:J,getTextXPath:B,getUniqueClassName:U,attributesBasedXPath:F,addAllXPathAttributes:G,addRelativeXpaths:z,getXPathUsingAttributeAndText:W,getSiblingRelativeXPath:q,getChildRelativeXpath:I,getParentRelativeXpath:M,getUniqueParentXpath:Y,checkRelativeXpathRelation:_};let K=[],Q=[];const ee=/^[\S]+( [\S]+)*$/gi,te=(e,t,n,l,a,r,o,s=0,c=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const i=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)i.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const m=ae(`${o+(s?"]".repeat(s):"")}`,i,e[e.length-1],e,l,n,a,c);if(m)return m}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${C(t,e[e.length-1])}`;let r=i(u,e[e.length-1],l);if(1===r)return[{key:`dynamic ${n}`,value:$(u)}];if(r>1&&a&&(u=m(u,e[e.length-1],l,r),u&&(r=i(u,e[e.length-1],l),1===r)))return[{key:`dynamic ${n} ${a?" index":""}`,value:$(u)}]}},ne=(e,t,n,l,a,r=!1,s=!1)=>{const i=e[e.length-2],u=e[e.length-1],m=d(u)??u.ownerDocument,h=n.find(e=>e?.key?.includes("absolute"))?.value||b(i,i.ownerDocument),f=[],$=[];h.split("/").map(e=>f.push(e)),f.map(e=>$.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=l.find(e=>e?.key?.includes("absolute"))?.value||b(u,u.ownerDocument),y=[],N=[];v.split("/").map(e=>y.push(e)),y.map(e=>N.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($[e]);const w=[];for(let e="descendant"===a?E:E-1;e<y.length;e++)y[e]&&(w.length?w.push(N[e]):w.push(N[e].replace(/\[([0-9]+)\]/gm,"")));let R;if(Q=l,e[e.length-2].textContent){R=ee.test(e[e.length-2].textContent)?p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${c(o(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${c(o(e[e.length-2]))}]`:p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${k(e[e.length-2])})]`:`${e[e.length-2].tagName}[${k(e[e.length-2])}]`,S[S.length-1]=R;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<Q.length;n++){let o;if(o=Q[n].value.startsWith("//")?Q[n].value.substring(Q[n].value.indexOf("//")+2):Q[n].value,o)return te(e,o,a,m||t,r,w,i,l,s)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(g(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const o=n.name;R=p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${o}=${c(l)}]`:`${e[e.length-2].tagName}[@${o}=${c(l)}]`,S[S.length-1]=R;const i=S.join("["),u=S.length-1,h=i;for(let n=0;n<Q.length;n++){let l;return l=Q[n].value.startsWith("//")?Q[n].value.substring(Q[n].value.indexOf("//")+2):Q[n].value,te(e,l,a,m||t,r,w,h,u,s)}}}for(const n of Array.from(e[e.length-2].attributes))if(g(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const o=x(n,e[e.length-2]);if(o){R=o.startsWith("//")?o.substring(o.indexOf("//")+2):o,S[S.length-1]=R;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<Q.length;n++){let o;return o=Q[n].value.startsWith("//")?Q[n].value.substring(Q[n].value.indexOf("//")+2):Q[n].value,te(e,o,a,m||t,r,w,i,l,s)}}}}}const C=S.join("["),P=S.length-1,A=ae(`${C+(P?"]".repeat(P):"")}`,w,e[e.length-1],e,t,a,r,s);if(A)return A},le=(e,t,n,l,a,r,o)=>{let s,c;console.log("getXpathRelationExpression",n);const u=[];try{s=l.filter(e=>!e?.key?.includes("absolute")),c=a.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let l=0;l<c.length;l++){let a=`//${0!==s[e].value.indexOf("//")?C(s[e].value):C(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==c[l].value.indexOf("//")?C(c[l].value):C(c[l].value.substring(c[l].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",a);const o=i(a,t,t.ownerDocument);if(o>1)if(r){if(a=m(a,t,t.ownerDocument,o),a)return u.push({key:`dynamic ${n}${r?" index":""}`,value:$(a)}),u}else o>1&&(K.length?o<K[0].count&&(K.pop(),K.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o})):K.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:$(a)}),u}if(!u.length)for(let l=0;l<s.length;l++)for(let a=0;a<c.length;a++){const i=`${0!==c[a].value.indexOf("//")?c[a].value:c[a].value.substring(c[a].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(i.length>1){const a=ae(`${0!==s[l].value.indexOf("//")?C(s[l].value):C(s[l].value.substring(s[l].value.indexOf("//")+2))}`,i,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},ae=(e,t,n,l,a,r,o,s)=>{let c;if(s){const s=t.join("/");c=`//${e}/${r}::${C(s)}`;const u=i(c,n,a);if(1===u)return[{key:`dynamic ${r}`,value:$(c)}];if(u>1&&o&&(c=m(c,l[l.length-1],a,u),c))return[{key:`dynamic ${r}${o?" index":""}`,value:$(c)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");c=`//${e}/${r}::${C(u)}`;const h=i(c,n,a);if(1===h)return[{key:`dynamic ${r}`,value:$(c)}];if(h>1&&o&&(c=m(c,l[l.length-1],a,h),c))return[{key:`dynamic ${r}${o?" index":""}`,value:$(c)}]}},re={findRelativeXpath:(e,t,n,l,a,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],h=[];if(r&&K.length){const e=m(K[0].value,t,t.ownerDocument,K[0].count);e&&(h=h.concat({key:`${K[0]?.key?K[0]?.key:"xpath with "} index`,value:e}),K.pop())}if(!h.length){for(e.isSameNode(t)&&(u=le(e,t,"self",l,a,r,o),u&&(h=h.concat(u))),c=e.parentElement,c===t&&(u=le(e,t,"parent",l,a,r,o),u&&(h=h.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=le(e,t,"ancestor",l,a,r,o),u)){h=h.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=le(e,t,"ancestor-or-self",l,a,r,o),u)){h=h.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=le(e,t,"following-sibling",l,a,r,o),u)){h=h.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=le(e,t,"preceding-sibling",l,a,r,o),u)){h=h.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=le(e,t,"child",l,a,r,o),u)){h=h.concat(u);break}const m=e.compareDocumentPosition(t);2===m&&(u=le(e,t,"preceding",l,a,r,o)),4===m&&(u=le(e,t,"following",l,a,r,o)),u&&(h=h.concat(u));const f=ne([e,t],n,l,a,"descendant",r,o);f&&(h=h.concat(f));const d=ne([e,t],n,l,a,"descedant-or-self",r,o);d&&(h=h.concat(d))}if(h.length)return h.length>1&&h.sort(function(e,t){return e.value.length-t.value.length}),h.filter(e=>!e.key?.includes("index"))?.length?[h.filter(e=>!e.key?.includes("index"))[0]]:[h[0]]},getDescendantXpath:ne,getXpathRelationExpression:le,getTraverseXpathExpression:ae,getReferenceElementXpath:e=>{let t=[];if(t=J(e,e.ownerDocument,!1,!1),t?.length){let n=J(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:u(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=J(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:u(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:N(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:N(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:u(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}},oe=(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&&(oe(l,t),l&&!t.includes("dynamic")))return l.querySelector(t)}}catch(e){console.log(e)}return null},se=e=>e?.id||null,ie=e=>e.className||null,ce=e=>e.textContent?.trim()||null,ue=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},me=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function he(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 fe(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 de=(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=oe(t.body,e));else{s=he(t,A(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=se(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=ce(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=ue(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=ie(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"})});J(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 me)if(l.value.includes(e)){const a=fe(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 ge=[];const pe=(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&&!r(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(" > ")},$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(),n=e.getAttribute("name");if(n&&!r(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(" > ")},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();if("string"!=typeof e.className||!e.className||r(e.className)||ge?.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(" > ")},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(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(" > ")},be={parseCssSelectors:(e,t)=>{let n=[];try{let l=pe(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=$e(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=ve(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=ye(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:pe,getNameCssPath:$e,getClassCssPath:ve,getAbsoluteCssPath:ye},Ne=()=>({xpath:Z,referenceXpaths:re,xpathUtils:D,getElementsFromHTML:de,cssSelectors:be});exports.createXPathAPI=Ne,exports.default=Ne;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/gi;const t={};let n,l=new Map,a=[];const r=e=>/\d/.test(e),o=e=>{const t=e?.textContent;return t},s=e=>e?.childNodes[0]?.nodeValue||"",i=(e,n,l,a=!1)=>{try{let r;if(void 0!==t[e])r=t[e];else{r=(9===l.nodeType?l:l.ownerDocument).evaluate(`count(${e})`,l,null,XPathResult.NUMBER_TYPE,null).numberValue,t[e]=r}if(a&&Array.isArray(n)){if(r>1){const t=v(e,l,!0);let a,r=0;if(t instanceof XPathResult)for(;(a=t?.iterateNext())&&(!n.includes(a)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return v(e,l)===n?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},c=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},u=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},m=(e,t,n,l)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let r=0;if(l){if(1===i(`${e}[${l}]`,t,n))return`${e}[${l}]`;if(1===i(`(${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===i(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===i(`(${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(),h=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},g=(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)||a?.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&&r(e.value)),p=e=>e instanceof SVGElement,$=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,v=(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},y=(t,n,l,a,o,s)=>{if(a){const{tagName:u}=t;let m,f="";const d=[];let g;if(a&&(!s||!r(a))&&(g=e.test(a)?`//${u}[${l}=${c(a)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${l})=${c(h(a)).trim()}`,p(t),t.tagName.toLowerCase()),m=i(g,t,n),1===m&&!o))return g;if(a&&s){const r=a.split(" ");if(r?.length)if(1===r.length){const s=[...new Set(r[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&h(s[0].trim())?.length>1&&a.startsWith(s[0])&&(f=e.test(s[0])?`starts-with(${l},${c(s[0]).trim()})`:`starts-with(${l},${c(h(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&h(s[s.length-1].trim())?.length>1&&a.endsWith(s[s.length-1])&&(f=e.test(s[s.length-1])?`ends-with(${l},${c(s[s.length-1]).trim()})`:`ends-with(${l},${c(h(s[s.length-1])).trim()})`),f?.length&&(g=p(t)?`//*[local-name()='${u}' and ${f}]`:`//${u}[${f}]`,m=i(g,t,n),1===m&&!o))return g}else{const s=r.length%2==0?r.length/2:r.length%2,d=r.slice(0,s).join(" ");let $=[...new Set(d.match(/([^0-9]+)/g))];if($?.length&&$[0]&&h($[0].trim())?.length&&a.startsWith($[0])&&(f=e.test($[0])?`starts-with(${l},${c($[0]).trim()})`:`starts-with(${l},${c(h($[0])).trim()})`),f?.length&&(g=p(t)?`//*[local-name()='${u}' and ${f}]`:`//${u}[${f}]`,m=i(g,t,n),1===m&&!o))return g;const v=r.slice(s,r.length-1).join(" ");if($=[...new Set(v.match(/([^0-9]+)/g))],$?.length&&$[0]&&h($[0].trim())?.length>3&&a.endsWith($[0])&&(f=e.test($[0])?`ends-with(${l},${c($[0]).trim()})`:`ends-with(${l},${c(h($[0])).trim()})`),f?.length&&(g=p(t)?`//*[local-name()='${u}' and ${f}]`:`//${u}[${f}]`,m=i(g,t,n),1===m&&!o))return g}}if(a&&s&&r(a)){const r=[...new Set(a.match(/([^0-9]+)/g))];if(r?.length)for(let t=0;t<r?.length;t++)r[t]&&h(r[t].trim())?.length>1&&(e.test(r[t])?d.push(`contains(${l},${c(r[t].trim()).trim()})`):d.push(`contains(${l},${c(h(r[t])).trim()})`));if(d?.length&&(g=p(t)?`//*[local-name()='${u}' and ${d.join(" and ")}]`:`//${u}[${d.join(" and ")}]`,m=i(g,t,n),1===m&&!o))return g}if(g=p(t)?`//*[local-name()='${u}' and text()]`:`//${u}[text()]`,m=i(g,t,n),1===m&&!o)return g}},b=(e,t)=>{try{if(!e)return"";let n=p(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),""}},N=(e,t,n,a=!1,o)=>{try{if(l.has(e))return l.get(e);const u=[];let f=e;for(;f;){let l="",d=!1,v=e===f?o??f.attributes:f.attributes;for(const e of Array.from(v))if(g(e,f,a)){let a=e.nodeValue;a=a?.replace("removePointers","")??"";const r=e.name;l=C(f,r,a);let o=0;if(l&&(o=i(l,f,t),1===o)){u.unshift($(l)),d=!0;break}if(o>1&&n&&(l=m(l,f,t,o),l)){u.unshift($(l)),d=!0;break}}if(f.textContent)if(!a||a&&!r(f.textContent)){l=new RegExp(/^[\S]+( [\S]+)*$/gi).test(f.textContent)?p(f)?`//*[local-name()='${f.tagName}' and .=${c(s(f))}]`:`//${f.tagName||"*"}[.=${c(s(f))}]`:p(f)?`//*[local-name()='${f.tagName}' and normalize-space(.)=${c(s(f))}]`:`//${f.tagName||"*"}[normalize-space(.)=${c(s(f))}]`;let e=i(l,f,t);if(1===e)return l;if(e>1&&n)return l=m(l,f,t,e),l}else{let e=[];const a=[...new Set(s(f).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&h(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${c(a[t].trim()).trim()})`):e.push(`contains(.,${c(h(a[t])).trim()})`));if(e?.length){l=p(f)?`//*[local-name()='${f.tagName}' and ${e.join(" and ")}]`:`//${f.tagName||"*"}[${e.join(" and ")}]`;let a=i(l,f,t);if(1===a)return l;if(a>1&&n)return l=m(l,f,t,a),l}}if(d)break;{let e=p(f)?`/*[local-name()='${f.tagName}']`:`/${f.tagName}`;if(f.parentElement){const t=Array.from(f.parentElement.children).filter(e=>e.tagName===f.tagName);if(t.length>1){e+=`[${t.indexOf(f)+1}]`}}u.unshift(e)}f=f.parentElement}const d=`${u.join("")}`;return l.set(e,d),d}catch(e){return console.log(e),null}},x=(t,n)=>{const l=[];let a="";if(t&&!r(t.value)&&"function"!=typeof t.nodeValue){const r=[...new Set(t.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&h(r[n].trim())?.length>2&&(e.test(r[n])?l.push(`contains(@${t.name},${c(r[n].trim())})`):l.push(`contains(@${t.name},${c(h(r[n])).trim()})`));if(l?.length)return a=p(n)?`//*[local-name()='${n.tagName}' and ${l.join(" and ")}]`:`//${n.tagName}[${l.join(" and ")}]`,a}},E=(t,n,l,a)=>{try{const r=[];if(l.length>1)for(const o of l)if(g(o,t,a)){const l=o.nodeValue;e.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=p(t)?`//*[local-name()='${t.tagName}' and ${r.join(" and ")}]`:`//${t.tagName}[${r.join(" and ")}]`;let s;try{s=i(a,t,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)}'`)}},S=(t,n,l)=>{let a=p(t),r="";if(g(n,t,l)){let l=n.value;l=l.replace("removePointers","");const o=n.name;r=e.test(l)?a?`*[local-name()='${t.tagName}' and @${o}=${c(l)}]`:`${t.tagName||"*"}[@${o}=${c(l)}]`:a?`*[local-name()='${t.tagName}' and normalize-space(@${o})=${c(l)}]`:`${t.tagName||"*"}[normalize-space(@${o})=${c(l)}]`}return r},k=(t,n)=>{if(!t.textContent)return"";const l=s(t);let a;return a=e.test(l)?p(t)?`//*[local-name()='${t.tagName}' and .=${c(l)}]`:`//${t.tagName||"*"}[.=${c(l)}]`:p(t)?`//*[local-name()='${t.tagName}' and normalize-space(.)=${c(l)}]`:`//${t.tagName||"*"}[normalize-space(.)=${c(l)}]`,a},w=e=>{const t=o(e)?.trim(),n=t?c(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?p(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${c(n)})]`:`//${e.tagName||"*"}[contains(@${t},${c(n)})]`:p(e)?`//*[local-name()='${e.tagName}' and @${t}=${c(n)}]`:`//${e.tagName||"*"}[@${t}=${c(n)}]`:p(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${c(n)})]`:`//${e.tagName||"*"}[contains(@${t},${c(n)})]`),a},R=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,A=(t,n,l)=>{let a;const s=[];if(t.textContent&&(!l||l&&!r(t.textContent))&&(e.test(t.textContent)?(a=p(t)?`*[local-name()='${t.tagName}' and .=${c(o(t))}]`:`${t.tagName}[.=${c(o(t))}]`,a&&s.push({key:"getReferenceElementsXpath",value:a})):(a=p(t)?`*[local-name()='${t.tagName}' and ${w(t)})]`:`${t.tagName}[${w(t)}]`,a&&s.push({key:"getReferenceElementsXpath",value:a}))),t.attributes)for(const e of Array.from(t.attributes))if(g(e,t,l)){let n=e.nodeValue;if(n){n=n.replace("removePointers","");const l=e.name;a="class"===l?p(t)?`*[local-name()='${t.tagName}' and contains(@${l},${c(n)})]`:`${t.tagName}[contains(@${l},${c(n)})]`:p(t)?`*[local-name()='${t.tagName}' and @${l}=${c(n)}]`:`${t.tagName}[@${l}=${c(n)}]`,a&&s.push({key:"getReferenceElementsXpath",value:a})}}if(!s?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=E(t,n,Array.prototype.slice.call(t.attributes),l);e&&s.push({key:"getReferenceElementsXpath",value:e})}}if(!s?.length){const n=[];let a;const o=p(t);if(t.textContent&&l&&r(t.textContent)){const l=[...new Set(t.textContent.match(/([^0-9]+)/g))];if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&h(l[t].trim())?.length>1&&(e.test(l[t])?n.push(`contains(.,${c(l[t]).trim()})`):n.push(`contains(.,${c(h(l[t])).trim()})`));n?.length&&(a=o?`//*[local-name()='${o}' and ${n.join(" and ")}]`:`//${o}[${n.join(" and ")}]`,a&&s.push({key:"getReferenceElementsXpath",value:a}))}}if(!s?.length){const e=((e,t,n,l)=>{const a=Array.prototype.slice.call(e),r=[];try{a.map(e=>{if(g(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})(t.attributes,t,0,l);e?.length&&s.concat(e)}return s},P=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,l=1;for(;l>0;){const t=e[++n];"("==t?l++:")"==t&&l--}return n};function O(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)::/),l=n?.[1]??"none",a=t.match(/@([a-z0-9:-]+)/);return{axis:l,attribute:a?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function D(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function X(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="${D(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 j={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:A,getAbsoluteXPath:b,getRelativeXPath:N,getCombinationXpath:x,getAttributeCombinationXpath:E,getElementFromXpath:v,isSvg:p,findXpathWithIndex:m,isNumberExist:r,getTextContent:o,getCountOfXPath:i,normalizeXPath:P,getShadowRoot:d,escapeCharacters:c,removeParenthesis:u,checkBlockedAttributes:g,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:f,replaceTempAttributes:$,createObserver:e=>{n=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&(p(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)||a.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{n?.observe(e,t)},stopObserver:()=>{n?.disconnect()},modifiedElementAttributes:a,cspEnabled:!1,getXPathPattern:O,escapeAttrValue:D,isUniqueInDOM:X};let L=[],V=[],q=new Map,Y=new Map;const _=new Map,I=(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){q?.get(e)||q.set(e,i(e,n,l));const t=q?.get(e);if(1===t)return e;if(t>1&&(V.length?t<V[0].count&&(V.pop(),V.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):V.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!L.length){const r=m(e,n,l,t);r&&1===i(r,n,l)&&L.push({key:"relative xpath by unique parent "+(a?"index":""),value:r})}}}return null},M=(t,n,l,a,o,u)=>{try{if(_.has(t))return _.get(t);const m=[];let f=t;for(;f&&1===f.nodeType;){const t=!1;for(const e of Array.from(f.attributes))if(g(e,f,a)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const a=e.name,r=C(f,a,t);let s;try{s=I(r,o,l,n,u,"parent")}catch(e){continue}if(s)return s}if(f.textContent&&!f.textContent)if(!a||a&&!r(f.textContent)){let t;t=e.test(f.textContent)?p(f)?`//*[local-name()='${f.tagName}' and .=${c(s(f))}]`:`//${f.tagName||"*"}[.=${c(s(f))}]`:p(f)?`//*[local-name()='${f.tagName}' and normalize-space(.)=${c(s(f))}]`:`//${f.tagName||"*"}[normalize-space(.)=${c(s(f))}]`;const a=I(t,o,l,n,u,"parent");if(a)return a}else{const e=[],t=[...new Set(s(f).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&h(t[n].trim())&&(a.test(t[n])?e.push(`contains(.,${c(t[n].trim()).trim()})`):e.push(`contains(.,${c(h(t[n])).trim()})`));if(e?.length){const t=p(f)?`//*[local-name()='${f.tagName}' and ${e.join(" and ")}]`:`//${f.tagName||"*"}[${e.join(" and ")}]`,a=I(t,o,l,n,u,"parent");if(a)return a}}if(!t){const e=p(f)?`/*[local-name()='${f.tagName}']`:`/${f.tagName}`;m.unshift(e)}f=f.parentElement}const d=m.join("")+o;if(1===i(d,t,n))return _.set(t,d),d}catch(e){return console.error(e),null}},z=(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(g(n,o,l)){let l=n.nodeValue;l=l?.replace("removePointers","")??"";const a=n.name,s=C(o,a,l);let c;try{c=i(s,o,t)}catch(e){continue}if(1===c){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=k(o);if(n){if(1===i(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=p(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}},W=(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(g(n,a,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=C(a,o,r);let c;try{c=i(s,a,t)}catch(e){continue}if(1===c){e=!0,l.push(s);break}}if(!e&&a.textContent&&!n.textContent){const n=k(a);if(n){if(1===i(n,a,t)){e=!0,l.push(n);break}}}if(e)break;{const e=p(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 Y.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)F(r,e,t,l,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==a;r=r.previousElementSibling)F(r,e,t,l,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},F=(e,t,n,l,a,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=S(e,{name:t.name,value:t.value},r);if(o){o+=`/${a}::${l}`;const t=i(o,e,n);if(1===t)return void L.push({key:`xpath by ${a}`,value:o});t>1&&(V.length?t<V[0].count&&(V.pop(),V.push({key:`relative xpath by ${a}`,value:o,count:t})):V.push({key:`relative xpath by ${a}`,value:o,count:t}))}}if(!r){let t;if(t=S(e,{name:"text",value:e.textContent},r),t){const l=i(t,e,n);if(1===l)return void L.push({key:`xpath by ${a}`,value:t});l>1&&(V.length?l<V[0].count&&(V.pop(),V.push({key:`relative xpath by ${a}`,value:t,count:l})):V.push({key:`relative xpath by ${a}`,value:t,count:l}))}}}catch(e){console.log(`${a} xpath-error`,e)}};function U(e,t,n,l){const{tagName:a}=t,r=t.textContent.trim();for(const o of e)if(g(o,t,l)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const l=`//${a}[@${o.name}='${e}' and text()='${r}']`;if(l){if(1==i(l,t,n))return l}}}const B=(e,t,n,l,a)=>{try{let r,o,s=[];if(L=[],console.log(a),a)for(const t of a){let n=S(e,{name:t.name,value:t.value},l);console.log(n),n&&s.push(n)}if(e.textContent){let t=S(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(!L.length){if(H(e,t,l,s[a]),!L.length&&(r||(r=z(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=i(l,e,t);if(1===o)L.push({key:"relative xpath by relative parent",value:l});else if(o>1&&n){const a=m(l,e,t,o);a&&1===i(a,e,t)&&L.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!L.length&&(o||(o=W(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const l=`/${s[a]+o.substring(1)}`,r=i(l,e,t);if(1===r)L.push({key:"relative xpath by relative child",value:l});else if(r>1&&n){const a=m(l,e,t,r);a&&1===i(a,e,t)&&L.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===L?.length&&L?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const l=Z(e,t,n,!1);l&&L.unshift({key:"xpath by text"+(n?"index":""),value:l})}if(!L.length){let r=M(e.parentElement,t,e,l,s[a],n);r&&L.push({key:"xpath by unique parent",value:r})}}return L}catch(e){console.log(e)}},G=(e,t,n,l,a)=>{let r;return r=e.name,y(t,n,`@${r}`,e.value,l,a)},J=(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 y(e,t,"@class",a,n,l)},Z=(e,t,n,l)=>{if(""!=e.textContent){const a=o(e);if(a)return y(e,t,".",a,n,l)}},K=(e,t,n,l,a)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&g(e,t,a)){const r=G(e,t,n,l,a);r&&L.push({key:`xpath by ${e.name}${l?" index":""}`,value:r})}});const o=Z(t,n,l,a);if(o&&L.push({key:"xpath by text"+(l?" index":""),value:o}),r.find(e=>"className"===e.name)&&g(r?.find(e=>"className"===e.name),t,a)){let e=J(t,n,l,a);e&&L.push({key:"xpath by class",value:e})}if(!L.length){const l=U(e,t,n,a);l&&L.push({key:"xpath by textAttribute",value:l})}if(!L.length&&r.length>1){const e=E(t,n,r,a);e&&L.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},Q=(e,t,n,l,a=[])=>{L=[],console.log(e);const r=e,o=r?.ownerDocument||t,s=r.tagName,{attributes:c}=r,u=a.length>0?a:Array.from(c);if(K(u,r,o,n,l),L.length){const t=L.length;for(let n=0;n<t;n++){let t=L[n].value;t="//*"+t.substring(t.indexOf("//")+2+s.length);1===i(t,e,o)&&L.push({key:`${L[n].key} regex`,value:t})}}return console.log(L),L.length||B(r,o,n,l,Array.from(r.attributes)),L},ee={parseDOM:Q,getTextXPath:Z,getUniqueClassName:J,attributesBasedXPath:G,addAllXPathAttributes:K,addRelativeXpaths:B,getXPathUsingAttributeAndText:U,getSiblingRelativeXPath:H,getChildRelativeXpath:W,getParentRelativeXpath:z,getUniqueParentXpath:M,checkRelativeXpathRelation:I};let te=[],ne=[];const le=/^[\S]+( [\S]+)*$/gi,ae=(e,t,n,l,a,r,o,s=0,c=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const i=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)i.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const m=se(`${o+(s?"]".repeat(s):"")}`,i,e[e.length-1],e,l,n,a,c);if(m)return m}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${R(t,e[e.length-1])}`;let r=i(u,e[e.length-1],l);if(1===r)return[{key:`dynamic ${n}`,value:$(u)}];if(r>1&&a&&(u=m(u,e[e.length-1],l,r),u&&(r=i(u,e[e.length-1],l),1===r)))return[{key:`dynamic ${n} ${a?" index":""}`,value:$(u)}]}},re=(e,t,n,l,a,r=!1,s=!1)=>{const i=e[e.length-2],u=e[e.length-1],m=d(u)??u.ownerDocument,f=n.find(e=>e?.key?.includes("absolute"))?.value||b(i,i.ownerDocument),h=[],$=[];f.split("/").map(e=>h.push(e)),h.map(e=>$.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=l.find(e=>e?.key?.includes("absolute"))?.value||b(u,u.ownerDocument),y=[],N=[];v.split("/").map(e=>y.push(e)),y.map(e=>N.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var E=0;E<h.length&&h[E]==y[E];E++);const S=[];for(let e=E-1;e<h.length;e++)h[e]&&S.push($[e]);const k=[];for(let e="descendant"===a?E:E-1;e<y.length;e++)y[e]&&(k.length?k.push(N[e]):k.push(N[e].replace(/\[([0-9]+)\]/gm,"")));let C;if(ne=l,e[e.length-2].textContent){C=le.test(e[e.length-2].textContent)?p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${c(o(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${c(o(e[e.length-2]))}]`:p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${w(e[e.length-2])})]`:`${e[e.length-2].tagName}[${w(e[e.length-2])}]`,S[S.length-1]=C;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<ne.length;n++){let o;if(o=ne[n].value.startsWith("//")?ne[n].value.substring(ne[n].value.indexOf("//")+2):ne[n].value,o)return ae(e,o,a,m||t,r,k,i,l,s)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(g(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const o=n.name;C=p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${o}=${c(l)}]`:`${e[e.length-2].tagName}[@${o}=${c(l)}]`,S[S.length-1]=C;const i=S.join("["),u=S.length-1,f=i;for(let n=0;n<ne.length;n++){let l;return l=ne[n].value.startsWith("//")?ne[n].value.substring(ne[n].value.indexOf("//")+2):ne[n].value,ae(e,l,a,m||t,r,k,f,u,s)}}}for(const n of Array.from(e[e.length-2].attributes))if(g(n,e[e.length-2],!1)){let l=n.nodeValue;if(l){l=l.replace("removePointers","");const o=x(n,e[e.length-2]);if(o){C=o.startsWith("//")?o.substring(o.indexOf("//")+2):o,S[S.length-1]=C;const n=S.join("["),l=S.length-1,i=n;for(let n=0;n<ne.length;n++){let o;return o=ne[n].value.startsWith("//")?ne[n].value.substring(ne[n].value.indexOf("//")+2):ne[n].value,ae(e,o,a,m||t,r,k,i,l,s)}}}}}const R=S.join("["),A=S.length-1,P=se(`${R+(A?"]".repeat(A):"")}`,k,e[e.length-1],e,t,a,r,s);if(P)return P},oe=(e,t,n,l,a,r,o)=>{let s,c;console.log("getXpathRelationExpression",n);const u=[];try{s=l.filter(e=>!e?.key?.includes("absolute")),c=a.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let l=0;l<c.length;l++){let a=`//${0!==s[e].value.indexOf("//")?R(s[e].value):R(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==c[l].value.indexOf("//")?R(c[l].value):R(c[l].value.substring(c[l].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",a);const o=i(a,t,t.ownerDocument);if(o>1)if(r){if(a=m(a,t,t.ownerDocument,o),a)return u.push({key:`dynamic ${n}${r?" index":""}`,value:$(a)}),u}else o>1&&(te.length?o<te[0].count&&(te.pop(),te.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o})):te.push({key:"relative xpath by relative child "+(r?"index":""),value:a,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:$(a)}),u}if(!u.length)for(let l=0;l<s.length;l++)for(let a=0;a<c.length;a++){const i=`${0!==c[a].value.indexOf("//")?c[a].value:c[a].value.substring(c[a].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(i.length>1){const a=se(`${0!==s[l].value.indexOf("//")?R(s[l].value):R(s[l].value.substring(s[l].value.indexOf("//")+2))}`,i,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},se=(e,t,n,l,a,r,o,s)=>{let c;if(s){const s=t.join("/");c=`//${e}/${r}::${R(s)}`;const u=i(c,n,a);if(1===u)return[{key:`dynamic ${r}`,value:$(c)}];if(u>1&&o&&(c=m(c,l[l.length-1],a,u),c))return[{key:`dynamic ${r}${o?" index":""}`,value:$(c)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");c=`//${e}/${r}::${R(u)}`;const f=i(c,n,a);if(1===f)return[{key:`dynamic ${r}`,value:$(c)}];if(f>1&&o&&(c=m(c,l[l.length-1],a,f),c))return[{key:`dynamic ${r}${o?" index":""}`,value:$(c)}]}},ie={findRelativeXpath:(e,t,n,l,a,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],f=[];if(r&&te.length){const e=m(te[0].value,t,t.ownerDocument,te[0].count);e&&(f=f.concat({key:`${te[0]?.key?te[0]?.key:"xpath with "} index`,value:e}),te.pop())}if(!f.length){for(e.isSameNode(t)&&(u=oe(e,t,"self",l,a,r,o),u&&(f=f.concat(u))),c=e.parentElement,c===t&&(u=oe(e,t,"parent",l,a,r,o),u&&(f=f.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=oe(e,t,"ancestor",l,a,r,o),u)){f=f.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=oe(e,t,"ancestor-or-self",l,a,r,o),u)){f=f.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=oe(e,t,"following-sibling",l,a,r,o),u)){f=f.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=oe(e,t,"preceding-sibling",l,a,r,o),u)){f=f.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=oe(e,t,"child",l,a,r,o),u)){f=f.concat(u);break}const m=e.compareDocumentPosition(t);2===m&&(u=oe(e,t,"preceding",l,a,r,o)),4===m&&(u=oe(e,t,"following",l,a,r,o)),u&&(f=f.concat(u));const h=re([e,t],n,l,a,"descendant",r,o);h&&(f=f.concat(h));const d=re([e,t],n,l,a,"descendant-or-self",r,o);d&&(f=f.concat(d))}if(f.length)return f.length>1&&f.sort(function(e,t){return e.value.length-t.value.length}),f.filter(e=>!e.key?.includes("index"))?.length?[f.filter(e=>!e.key?.includes("index"))[0]]:[f[0]]},getDescendantXpath:re,getXpathRelationExpression:oe,getTraverseXpathExpression:se,getReferenceElementXpath:e=>{let t=[];if(t=Q(e,e.ownerDocument,!1,!1),t?.length){let n=Q(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:u(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Q(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&T(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:u(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:N(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:N(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:u(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=b(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}},ce=(e,t,n)=>pe(t,P(e))===n,ue=(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&&(ue(l,t),l&&!t.includes("dynamic")))return l.querySelector(t)}}catch(e){console.log(e)}return null},me=e=>e?.id||null,fe=e=>e.className||null,he=e=>e.textContent?.trim()||null,de=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},ge=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function pe(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 $e(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 ve=(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 o(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}`;l.has(t)||(l.add(t),a.push(e))}(o)}const s=(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 i=e.locators.filter(e=>"N"===e.isRecorded);if(i.length>0)for(const e of i)o(e);const c=String(n.value||n.type||"");if(c.includes("dynamic")||c.match("dynamic")||c.includes("{")||c.includes("}")){o(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 l of e){if(!t){console.error("Element not found at:",l);break}{const e=l.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=D(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=ue(t.body,e));else{const l=P(e);i=pe(t,l),i&&o(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const c=(e,t)=>{const n=`${e}:${t}`;return l.has(n)};if(i){const n=e.locators.filter(e=>"xpath"===e.name&&e.value);for(const e of n)ce(e.value,t,i)&&o(e,{isSelfHealed:null});const l=a.filter(e=>"xpath"===e.name&&e.value),u=new Set(l.map(e=>O(e.value))),m=[],f=me(i);if(f&&!c("id",f)&&!r(f)){const n=e.locators.find(e=>"id"===e.name);X(t,"id",f)&&(m.push("id"),o(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);X(t,"tagName",h)&&(m.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:h}))}const d=he(i);if(d&&!r(d)){const n=e.locators.find(e=>"linkText"===e.name);X(t,"linkText",d)&&(m.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:d}))}const g=de(i);if(g&&!c("name",g)&&!r(g)){const n=e.locators.find(e=>"name"===e.name);X(t,"name",g)&&(m.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:g}))}const p=fe(i);if(p&&""!==p.trim()&&!c("className",p)&&!r(p)){const n=e.locators.find(e=>"className"===e.name);X(t,"className",p)&&(m.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:p}))}const $=Array.from(i.attributes).filter(e=>!m.includes(e.name)),v=Q(i,t,!1,!0,$);if(0!==v?.length){const e=n.filter(e=>!ce(e.value,t,i));let l=0;for(const t of e){if(l>=e.length)break;const n=O(t.value);if(u.has(n))continue;const a=v.find(e=>e.value&&O(e.value)===n);a?.value&&(o(t,{name:"xpath",value:a.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),l++)}if(l<e.length)for(const t of v){if(l>=e.length)break;if(!t.value)continue;const n=O(t.value);u.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),u.add(n),l++)}}for(const n of e.locators)try{for(const l of e.locators)if(l.value)for(const e of ge)if(l.value.includes(e)){const a=$e(l.value,e,t);if(a){o(l,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(a.length<5){const e=[{name:"id",value:me(i)},{name:"name",value:de(i)},{name:"className",value:fe(i)},{name:"tagName",value:i.tagName},{name:"linkText",value:he(i)}];for(const n of e){if(a.length>4)break;const{name:e,value:l}=n;l&&(r(l)||c(e,l)||X(t,e,l)&&o(void 0,{name:e,type:"static",value:l,isRecorded:"Y",isSelfHealed:"Y"}))}}const y=a.map(e=>({...e,value:s(e.value,e.name,e.isRecorded)})),b=[{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 b}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};let ye=[];const 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(e.id&&!r(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(" > ")},Ne=(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&&!r(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(" > ")},xe=(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||r(e.className)||ye?.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(" > ")},Ee=(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(" > ")},Se={parseCssSelectors:(e,t)=>{let n=[];try{let l=be(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=Ne(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=xe(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=Ee(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:be,getNameCssPath:Ne,getClassCssPath:xe,getAbsoluteCssPath:Ee},ke=()=>({xpath:ee,referenceXpaths:ie,xpathUtils:j,getElementsFromHTML:ve,cssSelectors:Se});exports.createXPathAPI=ke,exports.default=ke;
|
|
2
2
|
//# sourceMappingURL=index.browser.cjs.map
|