ff-dom 2.0.9 → 3.0.0-beta.1

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/i;const t={};let n,a=new Map,l=[];const r=e=>/\d/.test(e),o=e=>{const t=e?.textContent;return t},s=e=>e?.childNodes[0]?.nodeValue||"",i=(e,n,a,l=!1)=>{try{let r;if(void 0!==t[e])r=t[e];else{r=(9===a.nodeType?a:a.ownerDocument).evaluate(`count(${e})`,a,null,XPathResult.NUMBER_TYPE,null).numberValue,t[e]=r}if(l&&Array.isArray(n)){if(r>1){const t=v(e,a,!0);let l,r=0;if(t instanceof XPathResult)for(;(l=t?.iterateNext())&&(!n.includes(l)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return v(e,a)===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 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===i(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===i(`(${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===i(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===i(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},m=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,g=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},d=(e,t,n)=>{if(!e?.value||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(t=>t===e.value))return!1;if(["type","style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const a=l?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!a&&(!(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 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},y=(t,n,a,l,o,s)=>{if(l){const{tagName:u}=t;let f,m="";const g=[];let d;if(l&&(!s||!r(l))&&(d=e.test(l)?`//${u}[${a}=${c(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${c(h(l)).trim()}`,p(t),t.tagName.toLowerCase()),f=i(d,t,n),1===f&&!o))return d;if(l&&s){const r=l.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&&l.startsWith(s[0])&&(m=e.test(s[0])?`starts-with(${a},${c(s[0]).trim()})`:`starts-with(${a},${c(h(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&h(s[s.length-1].trim())?.length>1&&l.endsWith(s[s.length-1])&&(m=e.test(s[s.length-1])?`ends-with(${a},${c(s[s.length-1]).trim()})`:`ends-with(${a},${c(h(s[s.length-1])).trim()})`),m?.length&&(d=p(t)?`//*[local-name()='${u}' and ${m}]`:`//${u}[${m}]`,f=i(d,t,n),1===f&&!o))return d}else{const s=r.length%2==0?r.length/2:r.length%2,g=r.slice(0,s).join(" ");let $=[...new Set(g.match(/([^0-9]+)/g))];if($?.length&&$[0]&&h($[0].trim())?.length&&l.startsWith($[0])&&(m=e.test($[0])?`starts-with(${a},${c($[0]).trim()})`:`starts-with(${a},${c(h($[0])).trim()})`),m?.length&&(d=p(t)?`//*[local-name()='${u}' and ${m}]`:`//${u}[${m}]`,f=i(d,t,n),1===f&&!o))return d;const v=r.slice(s,r.length-1).join(" ");if($=[...new Set(v.match(/([^0-9]+)/g))],$?.length&&$[0]&&h($[0].trim())?.length>3&&l.endsWith($[0])&&(m=e.test($[0])?`ends-with(${a},${c($[0]).trim()})`:`ends-with(${a},${c(h($[0])).trim()})`),m?.length&&(d=p(t)?`//*[local-name()='${u}' and ${m}]`:`//${u}[${m}]`,f=i(d,t,n),1===f&&!o))return d}}if(l&&s&&r(l)){const r=[...new Set(l.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])?g.push(`contains(${a},${c(r[t].trim()).trim()})`):g.push(`contains(${a},${c(h(r[t])).trim()})`));if(g?.length&&(d=p(t)?`//*[local-name()='${u}' and ${g.join(" and ")}]`:`//${u}[${g.join(" and ")}]`,f=i(d,t,n),1===f&&!o))return d}if(d=p(t)?`//*[local-name()='${u}' and text()]`:`//${u}[text()]`,f=i(d,t,n),1===f&&!o)return d}},N=(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 N(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},b=(e,t,n,l=!1,o)=>{try{if(a.has(e))return a.get(e);const u=[];let m=e;for(;m;){let a="",g=!1,v=e===m?o??m.attributes:m.attributes;for(const e of Array.from(v))if(d(e,m,l)){let l=e.nodeValue;l=l?.replace("removePointers","")??"";const r=e.name;a=R(m,r,l);let o=0;if(a&&(o=i(a,m,t),1===o)){u.unshift($(a)),g=!0;break}if(o>1&&n&&(a=f(a,m,t,o),a)){u.unshift($(a)),g=!0;break}}if(m.textContent)if(!l||l&&!r(m.textContent)){a=new RegExp(/^[\S]+( [\S]+)*$/gi).test(m.textContent)?p(m)?`//*[local-name()='${m.tagName}' and .=${c(s(m))}]`:`//${m.tagName||"*"}[.=${c(s(m))}]`:p(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${c(s(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${c(s(m))}]`;let e=i(a,m,t);if(1===e)return a;if(e>1&&n)return a=f(a,m,t,e),a}else{let e=[];const l=[...new Set(s(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]&&h(l[t].trim())&&(r.test(l[t])?e.push(`contains(.,${c(l[t].trim()).trim()})`):e.push(`contains(.,${c(h(l[t])).trim()})`));if(e?.length){a=p(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`;let l=i(a,m,t);if(1===l)return a;if(l>1&&n)return a=f(a,m,t,l),a}}if(g)break;{let e=p(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}]`}}u.unshift(e)}m=m.parentElement}const g=`${u.join("")}`;return a.set(e,g),g}catch(e){return console.log(e),null}},x=(t,n)=>{const a=[];let l="";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])?a.push(`contains(@${t.name},${c(r[n].trim())})`):a.push(`contains(@${t.name},${c(h(r[n])).trim()})`));if(a?.length)return l=p(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},E=(t,n,a,l)=>{try{const r=[];if(a.length>1)for(const o of a)if(d(o,t,l)){const a=o.nodeValue;e.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=p(t)?`//*[local-name()='${t.tagName}' and ${r.join(" and ")}]`:`//${t.tagName}[${r.join(" and ")}]`;let s;try{s=i(l,t,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)}'`)}},S=(t,n,a)=>{let l=p(t),r="";if(d(n,t,a)){let a=n.value;a=a.replace("removePointers","");const o=n.name;r=e.test(a)?l?`*[local-name()='${t.tagName}' and @${o}=${c(a)}]`:`${t.tagName||"*"}[@${o}=${c(a)}]`:l?`*[local-name()='${t.tagName}' and normalize-space(@${o})=${c(a)}]`:`${t.tagName||"*"}[normalize-space(@${o})=${c(a)}]`}return r},k=(t,n)=>{if(!t.textContent)return"";const a=s(t);let l;return l=e.test(a)?p(t)?`//*[local-name()='${t.tagName}' and .=${c(a)}]`:`//${t.tagName||"*"}[.=${c(a)}]`:p(t)?`//*[local-name()='${t.tagName}' and normalize-space(.)=${c(a)}]`:`//${t.tagName||"*"}[normalize-space(.)=${c(a)}]`,l},w=e=>{const t=o(e)?.trim(),n=t?c(m(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},R=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.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)})]`),l},C=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,P=(t,n,a)=>{let l;const s=[];if(t.textContent&&(!a||a&&!r(t.textContent))&&(e.test(t.textContent)?(l=p(t)?`*[local-name()='${t.tagName}' and .=${c(o(t))}]`:`${t.tagName}[.=${c(o(t))}]`,l&&s.push({key:"getReferenceElementsXpath",value:l})):(l=p(t)?`*[local-name()='${t.tagName}' and ${w(t)})]`:`${t.tagName}[${w(t)}]`,l&&s.push({key:"getReferenceElementsXpath",value:l}))),t.attributes)for(const e of Array.from(t.attributes))if(d(e,t,a)){let n=e.nodeValue;if(n){n=n.replace("removePointers","");const a=e.name;l="class"===a?p(t)?`*[local-name()='${t.tagName}' and contains(@${a},${c(n)})]`:`${t.tagName}[contains(@${a},${c(n)})]`:p(t)?`*[local-name()='${t.tagName}' and @${a}=${c(n)}]`:`${t.tagName}[@${a}=${c(n)}]`,l&&s.push({key:"getReferenceElementsXpath",value:l})}}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),a);e&&s.push({key:"getReferenceElementsXpath",value:e})}}if(!s?.length){const n=[];let l;const o=p(t);if(t.textContent&&a&&r(t.textContent)){const a=[...new Set(t.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&h(a[t].trim())?.length>1&&(e.test(a[t])?n.push(`contains(.,${c(a[t]).trim()})`):n.push(`contains(.,${c(h(a[t])).trim()})`));n?.length&&(l=o?`//*[local-name()='${o}' and ${n.join(" and ")}]`:`//${o}[${n.join(" and ")}]`,l&&s.push({key:"getReferenceElementsXpath",value:l}))}}if(!s?.length){const e=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(d(e,t,a)){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,a);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"),D=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}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)::/),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 T(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function X(e,t,n,a){const l=a?.getRootNode?.()??e,r=e=>{try{return Array.from(l.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===r(`#${T(n)}`).length;case"name":return 1===r(`[name="${T(n)}"]`).length;case"className":return 1===r(`.${n}`).length;case"tagName":case"cssSelector":return 1===r(n).length;case"linkText":return 1===r("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===r("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:P,getAbsoluteXPath:N,getRelativeXPath:b,getCombinationXpath:x,getAttributeCombinationXpath:E,getElementFromXpath:v,isSvg:p,findXpathWithIndex:f,isNumberExist:r,getTextContent:o,getCountOfXPath:i,normalizeXPath:A,getShadowRoot:g,escapeCharacters:c,removeParenthesis:u,checkBlockedAttributes:d,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:D,deleteGarbageFromInnerText:m,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)||l.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:l,cspEnabled:!1,getXPathPattern:O,escapeAttrValue:T,isUniqueInDOM:X};let L=[],Y=[],_=new Map,V=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,i(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&&!L.length){const r=f(e,n,a,t);r&&1===i(r,n,a)&&L.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},q=(t,n,a,l,o,u)=>{try{if(I.has(t))return I.get(t);const f=[];let m=t;for(;m&&1===m.nodeType;){const t=!1;for(const e of Array.from(m.attributes))if(d(e,m,l)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const l=e.name,r=R(m,l,t);let s;try{s=z(r,o,a,n,u,"parent")}catch(e){continue}if(s)return s}if(m.textContent&&!m.textContent)if(!l||l&&!r(m.textContent)){let t;t=e.test(m.textContent)?p(m)?`//*[local-name()='${m.tagName}' and .=${c(s(m))}]`:`//${m.tagName||"*"}[.=${c(s(m))}]`:p(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${c(s(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${c(s(m))}]`;const l=z(t,o,a,n,u,"parent");if(l)return l}else{const e=[],t=[...new Set(s(m).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&h(t[n].trim())&&(l.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(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`,l=z(t,o,a,n,u,"parent");if(l)return l}}if(!t){const e=p(m)?`/*[local-name()='${m.tagName}']`:`/${m.tagName}`;f.unshift(e)}m=m.parentElement}const g=f.join("")+o;if(1===i(g,t,n))return I.set(t,g),g}catch(e){return console.error(e),null}},M=(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(d(n,o,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,s=R(o,l,a);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 l.set(e,s),s}catch(e){return console.log(e),null}},W=(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(d(n,l,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=R(l,o,r);let c;try{c=i(s,l,t)}catch(e){continue}if(1===c){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=k(l);if(n){if(1===i(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=p(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 V.set(e,o),o}catch(e){return console.log(e),null}},H=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)F(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)F(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},F=(e,t,n,a,l,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+=`/${l}::${a}`;const t=i(o,e,n);if(1===t)return void L.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=S(e,{name:"text",value:e.textContent},r),t){const a=i(t,e,n);if(1===a)return void L.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 U(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();for(const o of e)if(d(o,t,a)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==i(a,t,n))return a}}}const B=(e,t,n,a,l)=>{try{let r,o,s=[];if(L=[],console.log(l),l)for(const t of l){let n=S(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=S(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(!L.length){if(H(e,t,a,s[l]),!L.length&&(r||(r=M(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=i(a,e,t);if(1===o)L.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=f(a,e,t,o);l&&1===i(l,e,t)&&L.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!L.length&&(o||(o=W(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=i(a,e,t);if(1===r)L.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=f(a,e,t,r);l&&1===i(l,e,t)&&L.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===L?.length&&L?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=Z(e,t,n,!1);a&&L.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!L.length){let r=q(e.parentElement,t,e,a,s[l],n);r&&L.push({key:"xpath by unique parent",value:r})}}return L}catch(e){console.log(e)}},G=(e,t,n,a,l)=>{let r;return r=e.name,y(t,n,`@${r}`,e.value,a,l)},J=(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 y(e,t,"@class",l,n,a)},Z=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const l=o(e);if(l)return y(e,t,".",l,n,a)}},K=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&d(e,t,l)){const r=G(e,t,n,a,l);r&&L.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=Z(t,n,a,l);if(o&&L.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&d(r?.find(e=>"className"===e.name),t,l)){let e=J(t,n,a,l);e&&L.push({key:"xpath by class",value:e})}if(!L.length){const a=U(e,t,n,l);a&&L.push({key:"xpath by textAttribute",value:a})}if(!L.length&&r.length>1){const e=E(t,n,r,l);e&&L.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},Q=(e,t,n,a,l=[])=>{L=[],console.log(e);const r=e,o=r?.ownerDocument||t,s=r.tagName,{attributes:c}=r,u=l.length>0?l:Array.from(c);if(K(u,r,o,n,a),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 L.length||B(r,o,n,a,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:M,getUniqueParentXpath:q,checkRelativeXpathRelation:z};let te=[],ne=[];const ae=/^[\S]+( [\S]+)*$/gi,le=(e,t,n,a,l,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 f=se(`${o+(s?"]".repeat(s):"")}`,i,e[e.length-1],e,a,n,l,c);if(f)return f}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${C(t,e[e.length-1])}`;let r=i(u,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:$(u)}];if(r>1&&l&&(u=f(u,e[e.length-1],a,r),u&&(r=i(u,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:$(u)}]}},re=(e,t,n,a,l,r=!1,s=!1)=>{const i=e[e.length-2],u=e[e.length-1],f=g(u)??u.ownerDocument,m=n.find(e=>e?.key?.includes("absolute"))?.value||N(i,i.ownerDocument),h=[],$=[];m.split("/").map(e=>h.push(e)),h.map(e=>$.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=a.find(e=>e?.key?.includes("absolute"))?.value||N(u,u.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<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"===l?E:E-1;e<y.length;e++)y[e]&&(k.length?k.push(b[e]):k.push(b[e].replace(/\[([0-9]+)\]/gm,"")));let R;if(ne=a,e[e.length-2].textContent){R=ae.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]=R;const n=S.join("["),a=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 le(e,o,l,f||t,r,k,i,a,s)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(d(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const o=n.name;R=p(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${o}=${c(a)}]`:`${e[e.length-2].tagName}[@${o}=${c(a)}]`,S[S.length-1]=R;const i=S.join("["),u=S.length-1,m=i;for(let n=0;n<ne.length;n++){let a;return a=ne[n].value.startsWith("//")?ne[n].value.substring(ne[n].value.indexOf("//")+2):ne[n].value,le(e,a,l,f||t,r,k,m,u,s)}}}for(const n of Array.from(e[e.length-2].attributes))if(d(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.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("["),a=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,le(e,o,l,f||t,r,k,i,a,s)}}}}}const C=S.join("["),P=S.length-1,A=se(`${C+(P?"]".repeat(P):"")}`,k,e[e.length-1],e,t,l,r,s);if(A)return A},oe=(e,t,n,a,l,r,o)=>{let s,c;console.log("getXpathRelationExpression",n);const u=[];try{s=a.filter(e=>!e?.key?.includes("absolute")),c=l.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let a=0;a<c.length;a++){let l=`//${0!==s[e].value.indexOf("//")?C(s[e].value):C(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==c[a].value.indexOf("//")?C(c[a].value):C(c[a].value.substring(c[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=i(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:$(l)}),u}else o>1&&(te.length?o<te[0].count&&(te.pop(),te.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):te.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:$(l)}),u}if(!u.length)for(let a=0;a<s.length;a++)for(let l=0;l<c.length;l++){const i=`${0!==c[l].value.indexOf("//")?c[l].value:c[l].value.substring(c[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(i.length>1){const l=se(`${0!==s[a].value.indexOf("//")?C(s[a].value):C(s[a].value.substring(s[a].value.indexOf("//")+2))}`,i,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},se=(e,t,n,a,l,r,o,s)=>{let c;if(s){const s=t.join("/");c=`//${e}/${r}::${C(s)}`;const u=i(c,n,l);if(1===u)return[{key:`dynamic ${r}`,value:$(c)}];if(u>1&&o&&(c=f(c,a[a.length-1],l,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 m=i(c,n,l);if(1===m)return[{key:`dynamic ${r}`,value:$(c)}];if(m>1&&o&&(c=f(c,a[a.length-1],l,m),c))return[{key:`dynamic ${r}${o?" index":""}`,value:$(c)}]}},ie={findRelativeXpath:(e,t,n,a,l,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],m=[];if(r&&te.length){const e=f(te[0].value,t,t.ownerDocument,te[0].count);e&&(m=m.concat({key:`${te[0]?.key?te[0]?.key:"xpath with "} index`,value:e}),te.pop())}if(!m.length){for(e.isSameNode(t)&&(u=oe(e,t,"self",a,l,r,o),u&&(m=m.concat(u))),c=e.parentElement,c===t&&(u=oe(e,t,"parent",a,l,r,o),u&&(m=m.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=oe(e,t,"ancestor",a,l,r,o),u)){m=m.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=oe(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=oe(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=oe(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=oe(e,t,"child",a,l,r,o),u)){m=m.concat(u);break}const f=e.compareDocumentPosition(t);2===f&&(u=oe(e,t,"preceding",a,l,r,o)),4===f&&(u=oe(e,t,"following",a,l,r,o)),u&&(m=m.concat(u));const h=re([e,t],n,a,l,"descendant",r,o);h&&(m=m.concat(h));const g=re([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: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)&&D(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)&&D(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:u(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:b(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:b(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&D(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=N(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}};let ce=[];const ue=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},fe=(e,t="single")=>{const n=[],a=e.getRootNode();try{const l=me(e);if(l&&ue(l,e,a)&&(n.push({key:"cssSelector by id",value:l}),"single"===t))return n;const r=pe(e);r&&ue(r,e,a)&&n.push({key:"cssSelector by class",value:r});const o=de(e);o&&n.push({key:"cssSelector by name",value:o});const s=$e(e);s&&ue(s,e,a)&&n.push({key:"Absolute cssSelector",value:s})}catch(e){console.error(e)}return n},me=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&&!r(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(" > ")},he=new Set(["id","class","style"]);function ge(e){return Array.from(e.attributes).filter(e=>!he.has(e?.name?.toLowerCase())&&e.value&&!r(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const de=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=ge(e);for(const t of l){const l=`${a}${t}`;if(ue(l,e,n))return l}},pe=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||r(e.className)||ce?.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(" > ")},$e=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(" > ")},ve={parseCssSelectors:fe,getIdCssPath:me,getAttributeCssPath:de,getClassCssPath:pe,getAbsoluteCssPath:$e},ye=(e,t,n)=>{const a=A(e);if(Pe(t,a)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(a)){const e=t.evaluate(a,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},Ne=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Ee(e.body,t)},be=(e,t,n)=>Ne(t,e)===n,xe=e=>e.name?.toLowerCase().includes("cssselector")??!1,Ee=(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){const e=Ee(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},Se=e=>e?.id||null,ke=e=>e.className||null,we=e=>e.textContent?.trim()||null,Re=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Ce=["/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 Ae(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 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 a=new Set;let l=[];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}`;a.has(t)||(a.add(t),l.push(e))}(o)}function s(e,t,n){if(xe(t))return Ne(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+T(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=T(n);return e.querySelector(`[name="${t}"]`)}if("tagName"===t.name)return e.querySelector(n);if("linkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null;if("partialLinkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null;if(!t.name.includes("xpath")&&!n.startsWith("//")||t.type.match("dynamic"))return e.querySelector(n);{const a=Pe(e,A(n));return a&&o(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),a}}function i(e,t,n){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const l=s(a,t,n);if(l)return l}catch{continue}return null}const c=(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 u=e.locators.filter(e=>"N"===e.isRecorded);if(u.length>0)for(const e of u)o(e);const f=String(n.value||n.type||"");if(f.includes("dynamic")||f.match("dynamic")||f.includes("{")||f.includes("}")){o(n);continue}if(e.isShared.includes("Y"))break e;try{let u=null;const f=n.value.split(">>>");for(const e of f){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(u=s(t,n,a),u||(u=i(t,n,a)),u||(u=Ee(t.body,a)),!u){console.error("Element not found at:",a);break}}const m=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(u){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),a=e.locators.filter(e=>xe(e)&&e.value);for(const e of n)ye(e.value,t,u)&&o(e,{isSelfHealed:null});for(const e of a)be(e.value,t,u)&&o(e,{isSelfHealed:null});const s=l.filter(e=>"xpath"===e.name&&e.value),i=new Set(s.map(e=>O(e.value))),f=[],h=Se(u);if(h&&!m("id",h)&&!r(h)){const n=e.locators.find(e=>"id"===e.name);X(t,"id",h,u)&&(f.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:h}))}const g=u.tagName;if(g&&!m("tagName",g)){const n=e.locators.find(e=>"tagName"===e.name);X(t,"tagName",g,u)&&(f.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:g}))}const d=we(u);if(d&&!r(d)){const n=e.locators.find(e=>"linkText"===e.name);X(t,"linkText",d,u)&&(f.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:d}))}const p=Re(u);if(p&&!m("name",p)&&!r(p)){const n=e.locators.find(e=>"name"===e.name);X(t,"name",p,u)&&(f.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=ke(u);if($&&""!==$.trim()&&!$.includes(" ")&&!m("className",$)&&!r($)){const n=e.locators.find(e=>"className"===e.name);X(t,"className",$,u)&&(f.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}fe(u,"single").forEach(e=>{e.value&&!m("cssSelector",e.value)&&o(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const v=Array.from(u.attributes).filter(e=>!f.includes(e.name));let y=[];try{y=Q(u,t,!1,!0,v)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==y?.length){const e=n.filter(e=>!ye(e.value,t,u));let a=0;for(const t of e){if(a>=e.length)break;const n=O(t.value);if(i.has(n))continue;const l=y.find(e=>e.value&&O(e.value)===n);l?.value&&(o(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),i.add(n),a++)}if(a<e.length)for(const t of y){if(a>=e.length)break;if(!t.value)continue;const n=O(t.value);i.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),i.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of Ce)if(a.value.includes(e)){const l=Ae(a.value,e,t);if(l){o(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:Se(u)},{name:"name",value:Re(u)},{name:"className",value:ke(u)},{name:"tagName",value:u.tagName},{name:"linkText",value:we(u)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(r(a)||m(e,a)||"className"===e&&a.includes(" ")||X(t,e,a,u)&&o(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&fe(u,"multiple").forEach(e=>{l.length>4||e.value&&(m("cssSelector",e.value)||X(t,"cssSelector",e.value,u)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=l.map(e=>({...e,value:c(e.value,e.name,e.isRecorded)})),b=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:N.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},Oe=()=>({xpath:ee,referenceXpaths:ie,xpathUtils:j,getElementsFromHTML:De,cssSelectors:ve});exports.createXPathAPI=Oe,exports.default=Oe;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/i;let t=new WeakMap;const n=e=>{e?(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const a=e.getRootNode?.();return(a instanceof Document||a instanceof ShadowRoot)&&n(a),n(e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument),t})(e).forEach(e=>{t.delete(e)}):t=new WeakMap},a=(e,n)=>{const{owner:a,contextNode:l}=(e=>{const t=9===e.nodeType?e:e.ownerDocument||document;return{owner:t,contextNode:1===e.nodeType||9===e.nodeType||11===e.nodeType?e:t}})(n);let r=t.get(l);r||(r=new Map,t.set(l,r));const o=r.get(e);if(o)return o;const s=a.evaluate(e,l,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return r.set(e,i),i};let l,r=new Map,o=[];const s=new Set(["marked-element-temp","removePointers"]),i=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!s.has(e)).sort(),c=(e,t)=>t?"class"===e||"className"===e?i(t).join(" "):t.replace("removePointers","").trim():"",u=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(w(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=i(e.oldValue),n=i(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},f=e=>/\d/.test(e),m=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,h=e=>{const t=e?.textContent;return t},d=e=>e?.childNodes[0]?.nodeValue||"",g=(e,t,n,l=!1)=>{try{const{first:r,second:o}=a(e,n);if(!r)return 0;if(!o)return r===t?1:0;if(l&&Array.isArray(t)){let a=0;if(t.includes(r)&&a++,t.includes(o)&&a++,2===a)return 2;const l=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=l.iterateNext();)if(t.includes(s)&&(a++,2===a))return 2;return 0}return 2}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},p=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},$=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},y=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===g(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===g(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const o=l.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=o.iterateNext();)if(r++,s.isSameNode(t))return 1===g(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===g(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},v=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(),N=e=>e?e.replace(/\s\s+/g," ").trim():e,x=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},b=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),a=n.createElement("div");a.innerHTML=e.innerHTML,n.body.appendChild(a);const l=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let a=t;for(;a&&a.parentElement;){const e=a.parentElement;n.unshift(Array.from(e.children).indexOf(a)),a=e}return a&&a.parentNode===e?(n.unshift(Array.from(e.children).indexOf(a)),n):null})(e,t);return n?((e,t)=>{let n=e;for(const e of t){const t=n.children.item(e);if(!t)return null;n=t}return n})(a,n):null},r=Array.isArray(t)?t.map(e=>l(e)).filter(Boolean):[],o=Array.isArray(t)?null:l(null);return{owner:n,contextNode:a,cloneElement:o,cloneElements:r}},E=(e,t,n)=>{const a=c(e.name,e.value);if(!a||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(e=>e===a))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const l=o?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!l&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(!n||!f(a))))},w=e=>e instanceof SVGElement,S=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,k=(t,n,a,l,r,o)=>{if(l){const{tagName:s}=t;let i,c="";const u=[];let h;if(l&&(!o||!f(l))&&(h=e.test(l)?`//${s}[${a}=${p(l)}]`:m(`normalize-space(${a})=${p(N(l)).trim()}`,w(t),t.tagName.toLowerCase()),i=g(h,t,n),1===i&&!r))return h;if(l&&o){const o=l.split(" ");if(o?.length)if(1===o.length){const u=[...new Set(o[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&N(u[0].trim())?.length>1&&l.startsWith(u[0])&&(c=e.test(u[0])?`starts-with(${a},${p(u[0]).trim()})`:`starts-with(${a},${p(N(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&N(u[u.length-1].trim())?.length>1&&l.endsWith(u[u.length-1])&&(c=e.test(u[u.length-1])?`ends-with(${a},${p(u[u.length-1]).trim()})`:`ends-with(${a},${p(N(u[u.length-1])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h}else{const u=o.length%2==0?o.length/2:o.length%2,f=o.slice(0,u).join(" ");let m=[...new Set(f.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&N(m[0].trim())?.length&&l.startsWith(m[0])&&(c=e.test(m[0])?`starts-with(${a},${p(m[0]).trim()})`:`starts-with(${a},${p(N(m[0])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h;const d=o.slice(u,o.length-1).join(" ");if(m=[...new Set(d.match(/([^0-9]+)/g))],m?.length&&m[0]&&N(m[0].trim())?.length>3&&l.endsWith(m[0])&&(c=e.test(m[0])?`ends-with(${a},${p(m[0]).trim()})`:`ends-with(${a},${p(N(m[0])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h}}if(l&&o&&f(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let t=0;t<o?.length;t++)o[t]&&N(o[t].trim())?.length>1&&(e.test(o[t])?u.push(`contains(${a},${p(o[t].trim()).trim()})`):u.push(`contains(${a},${p(N(o[t])).trim()})`));if(u?.length&&(h=w(t)?`//*[local-name()='${s}' and ${u.join(" and ")}]`:`//${s}[${u.join(" and ")}]`,i=g(h,t,n),1===i&&!r))return h}if(h=w(t)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=g(h,t,n),1===i&&!r)return h}},C=(e,t)=>{try{if(!e)return"";let n=w(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 C(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},R=(e,t,n,a=!1,l)=>{try{if(r.has(e))return r.get(e);const o=[];let s=e;for(;s;){let r="",i=!1,u=e===s?l??s.attributes:s.attributes;for(const e of Array.from(u))if(E(e,s,a)){const a=c(e.name,e.nodeValue),l=e.name;r=H(s,l,a);let u=0;if(r&&(u=g(r,s,t),1===u)){o.unshift(S(r)),i=!0;break}if(u>1&&n&&(r=y(r,s,t,u),r)){o.unshift(S(r)),i=!0;break}}if(s.textContent)if(!a||a&&!f(s.textContent)){r=new RegExp(/^[\S]+( [\S]+)*$/gi).test(s.textContent)?w(s)?`//*[local-name()='${s.tagName}' and .=${p(d(s))}]`:`//${s.tagName||"*"}[.=${p(d(s))}]`:w(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${p(d(s))}]`:`//${s.tagName||"*"}[normalize-space(.)=${p(d(s))}]`;let e=g(r,s,t);if(1===e)return r;if(e>1&&n)return r=y(r,s,t,e),r}else{let e=[];const a=[...new Set(d(s).match(/([^0-9]+)/g))];let l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&N(a[t].trim())&&(l.test(a[t])?e.push(`contains(.,${p(a[t].trim()).trim()})`):e.push(`contains(.,${p(N(a[t])).trim()})`));if(e?.length){r=w(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=g(r,s,t);if(1===a)return r;if(a>1&&n)return r=y(r,s,t,a),r}}if(i)break;{let e=w(s)?`/*[local-name()='${s.tagName}']`:`/${s.tagName}`;if(s.parentElement){const t=Array.from(s.parentElement.children).filter(e=>e.tagName===s.tagName);if(t.length>1){e+=`[${t.indexOf(s)+1}]`}}o.unshift(e)}s=s.parentElement}const i=`${o.join("")}`;return r.set(e,i),i}catch(e){return console.log(e),null}},O=(t,n)=>{const a=[];let l="";if(t&&!f(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]&&N(r[n].trim())?.length>2&&(e.test(r[n])?a.push(`contains(@${t.name},${p(r[n].trim())})`):a.push(`contains(@${t.name},${p(N(r[n])).trim()})`));if(a?.length)return l=w(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},T=(t,n,a,l)=>{try{const r=a.filter(e=>E(e,t,l)),o=a=>{const l=c(a.name,a.nodeValue);if(!l)return[];if("class"===a.name){const e=l.split(/\s+/).map(e=>e.trim()).filter(Boolean);if(!e.length)return[];const a=e.map(e=>{const a=m(`contains(@class,${p(e)})`,w(t),t.tagName.toLowerCase());return{token:e,count:I(a,t,n)}}).sort((e,t)=>e.count!==t.count?e.count-t.count:t.token.length-e.token.length);return a[0]?.token?[`contains(@class,${p(a[0].token)})`]:[]}return e.test(l)?[`@${a.name}="${l}"`]:[`normalize-space(@${a.name})="${l}"`]},s=()=>{const n=N(h(t)?.trim()||"");if(!n||n.length>80||/^\d+$/.test(n))return[];const a=new Set;return e.test(n)&&n.length<=40&&a.add(`text()=${p(n)}`),n.includes(" ")&&a.add(`normalize-space(text())=${p(N(n))}`),a.add(`contains(text(),${p(n)})`),Array.from(a)},i=(e,t)=>{const n=[],a=(l,r)=>{if(r.length!==t)for(let t=l;t<e.length;t++)r.push(e[t]),a(t+1,r),r.pop();else n.push([...r])};return a(0,[]),n},u=e=>w(t)?`//*[local-name()='${t.tagName}' and ${e.join(" and ")}]`:`//${t.tagName}[${e.join(" and ")}]`,f=()=>{if(!(r.length<2))for(let e=2;e<=r.length;e++){const a=i(r,e);for(const e of a){let a=[];for(const t of e){const e=o(t);e.length&&a.push(...e)}if(a.length<2)continue;const l=u(a);let r;try{r=g(l,t,n)}catch{continue}if(1===r)return l}}},d=f();if(d)return d;const $=s();if(!$.length||!r.length)return;for(let e=1;e<=r.length;e++){const a=i(r,e);for(const e of a){let a=[];for(const t of e)a.push(...o(t));if(a.length)for(const e of $){const l=[...a,e],r=u(l);try{if(1===g(r,t,n))return r}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},A=(t,n,a)=>{let l=w(t),r="";if(E(n,t,a)){let a=c(n.name,n.value);const o=n.name;r=e.test(a)?l?`*[local-name()='${t.tagName}' and @${o}=${p(a)}]`:`${t.tagName||"*"}[@${o}=${p(a)}]`:l?`*[local-name()='${t.tagName}' and normalize-space(@${o})=${p(a)}]`:`${t.tagName||"*"}[normalize-space(@${o})=${p(a)}]`}return r},D=(t,n)=>{if(!t.textContent)return"";const a=d(t);let l;return l=e.test(a)?w(t)?`//*[local-name()='${t.tagName}' and .=${p(a)}]`:`//${t.tagName||"*"}[.=${p(a)}]`:w(t)?`//*[local-name()='${t.tagName}' and normalize-space(.)=${p(a)}]`:`//${t.tagName||"*"}[normalize-space(.)=${p(a)}]`,l},P=(e,t,n)=>m(`normalize-space(${t})=${p(N(n)).trim()}`,w(e),e.tagName.toLowerCase()),X=(e,t,n)=>m(`starts-with(${t},${p(N(n)).trim()})`,w(e),e.tagName.toLowerCase()),_=(e,t,n)=>m(`contains(${t},${p(N(n)).trim()})`,w(e),e.tagName.toLowerCase()),L=(t,n)=>{const a=n.map(n=>(n=>{const a=c(n.name,n.value);if(!a)return null;if("class"===n.name){const e=a.split(/\s+/).map(e=>e.trim()).filter(Boolean),n=t.getRootNode?.()??t.ownerDocument,l=e.map(e=>{const a=m(`contains(@class,${p(e)})`,w(t),t.tagName.toLowerCase());return{token:e,count:I(a,t,n)}}).sort((e,t)=>e.count!==t.count?e.count-t.count:t.token.length-e.token.length)[0]?.token;return l?`contains(@class,${p(l)})`:null}return e.test(a)?`@${n.name}=${p(a)}`:`normalize-space(@${n.name})=${p(a)}`})(n)).filter(Boolean);if(a.length>=2)return m(`${a[0]} or ${a[1]}`,w(t),t.tagName.toLowerCase());const l=(()=>{const n=N(h(t)?.trim()||"");return!n||n.length>80||/^\d+$/.test(n)?null:e.test(n)&&n.length<=40?`text()=${p(n)}`:n.includes(" ")?`normalize-space(text())=${p(n)}`:`contains(text(),${p(n)})`})();return 1===a.length&&l?m(`${a[0]} or ${l}`,w(t),t.tagName.toLowerCase()):""},I=(e,t,n)=>{try{return g(e,t,n)}catch(e){return 0}},M=(e,t)=>{const n=[],a=new Set,l=Array.from(e.attributes||[]),r=["id","data-testid","data-test","data-qa","name","aria-label","role"],o=[...r.map(e=>l.find(t=>t.name===e)).filter(Boolean),...l.filter(e=>!r.includes(e.name))],s=l=>{l&&!a.has(l)&&V(l,e,t)&&(a.add(l),n.push(l))};o.forEach(t=>{if(!E(t,e,!1))return;const n="id"===t.name?`//*[@id=${p(c(t.name,t.value))}]`:H(e,t.name,t.value);n&&s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=D(e);t&&s(t)}if(l.length>1){const n=T(e,t,l,!1);n&&s(n)}return n},j=(e,t)=>{const n=[];let a=t;for(;a&&a!==e;)n.unshift(q(a)),a=a.parentElement;return a===e?n.join("/"):""},Y=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),a=q(e),l=w(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const l=M(t,n);for(const r of l){console.log(`Trying ancestor XPath: ${r}`);const l=`${r}/descendant::${a}`;console.log(`Trying descendant XPath: ${l}`);const o=I(l,e,n);if(console.log(`Match count: ${o}`),1===o&&z(l,n)===e)return console.log(`Selected XPath: ${l}`),l;const s=j(t,e);if(s){const t=`${r}/${s}`;console.log(`Trying descendant XPath: ${t}`);const a=I(t,e,n);if(console.log(`Match count: ${a}`),1===a&&z(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${l}`);const r=I(l,e,n);return console.log(`Match count: ${r}`),1===r&&z(l,n)===e?(console.log(`Selected XPath: ${l}`),l):(console.log("Selected XPath: "),"")},z=(e,t)=>{try{if(n=t,n?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in n){const{owner:n,contextNode:a,cloneElement:l}=b(t);return n.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||l}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}var n},V=(e,t,n)=>{try{const{first:l,second:r}=a(e,n);return!!l&&!r&&l===t}catch{return!1}},q=e=>w(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),W=(e,t,n)=>{if(!(e instanceof Element))return[];const a=new Set,l=[],r=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(a=t.value,!/\d/.test(a))&&E(t,e,n);var a}),o=(e,t)=>{t&&!a.has(t)&&(a.add(t),l.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","aria-label","role"];s.forEach(n=>{const a=r.find(e=>e.name===n);if(!a)return;const l="id"===n?`//*[@id='${a.value}']`:H(e,a.name,a.value);l&&V(l,e,t)&&o(`anchor by ${a.name}`,l)}),r.forEach(n=>{if(s.includes(n.name))return;const a=H(e,n.name,n.value);a&&V(a,e,t)&&o(`anchor by ${n.name}`,a)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=D(e);n&&V(n,e,t)&&o("anchor by text",n)}if(r.length>1){const a=T(e,t,r,n);a&&V(a,e,t)&&o("anchor by combination",a)}const c=Y(e,t);return c&&V(c,e,t)&&o("anchor by tag",c),l},U=e=>{const t=h(e)?.trim(),n=t?p(v(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},H=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return(n=c(t,n))&&(l=a.test(n)?"class"===t?w(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`:w(e)?`//*[local-name()='${e.tagName}' and @${t}=${p(n)}]`:`//${e.tagName||"*"}[@${t}=${p(n)}]`:w(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`),l},F=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,B=(t,n,a)=>{let l;const r=[];if(t.textContent&&(!a||a&&!f(t.textContent))&&(e.test(t.textContent)?(l=w(t)?`*[local-name()='${t.tagName}' and .=${p(h(t))}]`:`${t.tagName}[.=${p(h(t))}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})):(l=w(t)?`*[local-name()='${t.tagName}' and ${U(t)})]`:`${t.tagName}[${U(t)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))),t.attributes)for(const e of Array.from(t.attributes))if(E(e,t,a)){let n=e.nodeValue;if(n){n=c(e.name,n);const a=e.name;l="class"===a?w(t)?`*[local-name()='${t.tagName}' and contains(@${a},${p(n)})]`:`${t.tagName}[contains(@${a},${p(n)})]`:w(t)?`*[local-name()='${t.tagName}' and @${a}=${p(n)}]`:`${t.tagName}[@${a}=${p(n)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})}}if(!r?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=T(t,n,Array.prototype.slice.call(t.attributes),a);e&&r.push({key:"getReferenceElementsXpath",value:e})}}if(!r?.length){const n=[];let l;const o=w(t);if(t.textContent&&a&&f(t.textContent)){const a=[...new Set(t.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&N(a[t].trim())?.length>1&&(e.test(a[t])?n.push(`contains(.,${p(a[t]).trim()})`):n.push(`contains(.,${p(N(a[t])).trim()})`));n?.length&&(l=o?`//*[local-name()='${o}' and ${n.join(" and ")}]`:`//${o}[${n.join(" and ")}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))}}if(!r?.length){const e=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(E(e,t,a)){const n=O(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(t.attributes,t,0,a);e?.length&&r.concat(e)}return r},G=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"),J=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function Z(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 K(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function Q(e,t,n,a){const l=a?.getRootNode?.()??e,r=e=>{try{return Array.from(l.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===r(`#${K(n)}`).length;case"name":return 1===r(`[name="${K(n)}"]`).length;case"className":return 1===r(`.${n}`).length;case"tagName":case"cssSelector":return 1===r(n).length;case"linkText":return 1===r("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===r("a").filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const ee={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:B,getAbsoluteXPath:C,getRelativeXPath:R,getCombinationXpath:O,getAttributeCombinationXpath:T,getElementFromXpath:(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},isSvg:w,findXpathWithIndex:y,isNumberExist:f,getTextContent:h,getCountOfXPath:g,normalizeXPath:G,getShadowRoot:x,escapeCharacters:p,removeParenthesis:$,checkBlockedAttributes:E,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:J,deleteGarbageFromInnerText:v,replaceTempAttributes:S,createObserver:e=>{l=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!u(t))&&n(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(u(t)||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||o.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:o,cspEnabled:!1,getXPathPattern:Z,getNormalizedPropertyXPath:P,getStartsWithPropertyXPath:X,getContainsPropertyXPath:_,getOrAttributesXPath:L,getTagOnlyXPath:Y,getFirstMatchedNode:z,isExactUniqueXpath:V,getAxisNodeTest:q,getUniqueNodeAnchorXpaths:W,escapeAttrValue:K,isUniqueInDOM:Q,sanitizeAttributeValue:c};let te=[],ne=[],ae=new Map,le=new Map;const re=new Map,oe={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},se=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),ie=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ce=e=>{if(!(e&&e instanceof Element))return[];const t=[],n=Array.from(e.children||[]);for(;n.length;){const e=n.shift();e.classList?.contains("flntooltip")||(t.push(e),n.push(...Array.from(e.children||[])))}return t},ue=(e,t)=>{const n=[];let a="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;a;)a.classList?.contains("flntooltip")||n.push(a),a="previous"===t?a.previousElementSibling:a.nextElementSibling;return n},fe=(e,t)=>{const n=[];for(let a=e;a?.parentElement;a=a.parentElement){let e="previous"===t?a.previousElementSibling:a.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>ce(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},me=e=>{if(!(e instanceof Element))return!0;const t=e.textContent?.trim();return!e.id&&!e.className&&0===e.attributes.length&&(!t||t.length>60)&&e.children.length>2},he=(e,t,n,a,l,r,o)=>{const s=q(n),i=[];let c=0;const u=t.includes("descendant")?10:20;for(const f of e){if(c++>u)break;if(i.length>=5)break;const e="node"in f?f.node:f;if(!(e instanceof Element))continue;if(me(e))continue;const m=[()=>W(e,a,l),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&E(t,e,l));for(const a of n){const n=a.value;if(!n)continue;const l=_(e,`@${a.name}`,n);l&&t.push({key:"contains",value:l});const r=X(e,`@${a.name}`,n);r&&t.push({key:"starts-with",value:r})}return t},()=>[{key:"tag",value:Y(e,a)}]];for(let l=0;l<m.length;l++){let c=m[l]();if(!c.length)continue;o||(c=c.filter(e=>!/\[\d+\]/.test(e.value)));const u=new Set;c=c.filter(e=>!u.has(e.value)&&(u.add(e.value),!0)),c=c.slice(0,5);for(const e of c){const l=`${e.value}/${t}::${s}`;if(V(l,n,a)){if(i.push({key:r,value:l}),i.length>=2)return i;if(i.length>=5)return i}}if(o&&l===m.length-1)for(const l of c){const o=g(l.value,e,a);for(let e=1;e<=Math.min(o,3);e++){const o=`(${l.value})[${e}]/${t}::${s}`;if(V(o,n,a)){if(i.push({key:r,value:o}),i.length>=2)return i;if(i.length>=5)return i}}}}if("expand"in f&&f.expand){const e=f.expand();let o=0;for(const c of e){if(o++>15)break;if(i.length>=5)break;if(!(c instanceof Element))continue;if(me(c))continue;const e=W(c,a,l);for(const l of e.slice(0,5)){const e=`${l.value}/${t}::${s}`;if(V(e,n,a)){if(i.push({key:r,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},de=(e,t,n,a)=>{const l=[];for(let t=e.parentElement;t;t=t.parentElement)l.push(t);const r=ce(e),o=ue(e,"previous"),s=ue(e,"next"),i=fe(e,"previous"),c=fe(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(s),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(o),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(l),axis:"child",key:"child"},{nodes:u(r,15),axis:"parent",key:"parent"}],[{nodes:u(l),axis:"descendant",key:"descendant"},{nodes:u(l),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(r,10),axis:"ancestor",key:"ancestor"},{nodes:u(r,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]];for(const l of f)for(const r of l){const l=he(r.nodes,r.axis,e,t,n,r.key,a);if(l.length>0)return l}return[]},ge=(e,t,n,a,l)=>{const r=(e=>oe[e]||e)(a);return"text"===r?se(a,((e,t,n)=>{if(!ie(e))return[];if("text"===n){const n=D(e)||Se(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,r)):["contains","startsWith","normalizeSpace"].includes(r)?se(a,((e,t,n)=>{const a=[],l=Array.from(e.attributes||[]).filter(n=>n?.value&&E(n,e,t)),r=ie(e),o="contains"===n?_:"startsWith"===n?X:"normalizeSpace"===n?P:null;if(!o)return a;if(l.forEach(t=>{const l=o(e,`@${t.name}`,t.value);l&&a.push({key:`xpath by ${n} ${t.name}`,value:l})}),r){const t=o(e,".",r);t&&a.push({key:`xpath by ${n} text`,value:t})}return a})(e,n,r)):["and","or"].includes(r)?se(a,((e,t,n,a)=>{const l=Array.from(e.attributes||[]).filter(t=>t?.value&&E(t,e,n));if("and"===a){const a=T(e,t,l,n);return a?[{key:"xpath by combination",value:a}]:[]}if("or"===a&&l.length>=1){const t=L(e,l);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,n,r)):"axes"===r?se(a,de(e,t,n,!1)):"index"===r?se(a,((e,t)=>{const n=[],a=e.tagName.toLowerCase(),l=Array.from(t.querySelectorAll(a)).indexOf(e)+1;if(l<=0)return[];n.push({key:"xpath by index",value:`(//${a})[${l}]`});let r=e.parentElement;for(;r&&r!==t.body;){if(r.id||r.className){const t=r.className?.toString().split(" ").map(e=>e.trim()).find(Boolean),l=r.id?`//${r.tagName.toLowerCase()}[@id='${r.id}']`:t?`//${r.tagName.toLowerCase()}[contains(@class,'${t}')]`:"";if(!l){r=r.parentElement;continue}const o=Array.from(r.querySelectorAll(a)).indexOf(e)+1;if(o>0){n.push({key:"xpath by index",value:`(${l}//${a})[${o}]`});break}}r=r.parentElement}return n})(e,t)):"tag"===r?se(a,[{key:"xpath till tag",value:Y(e,t)}]):[]},pe=(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){ae?.get(e)||ae.set(e,g(e,n,a));const t=ae?.get(e);if(1===t)return e;if(t>1&&(ne.length?t<ne[0].count&&(ne.pop(),ne.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):ne.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!te.length){const r=y(e,n,a,t);r&&1===g(r,n,a)&&te.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},$e=(t,n,a,l,r,o)=>{try{if(re.has(t))return re.get(t);const s=[];let i=t;for(;i&&1===i.nodeType;){const t=!1;for(const e of Array.from(i.attributes))if(E(e,i,l)){const t=c(e.name,e.nodeValue),l=e.name,s=H(i,l,t);let u;try{u=pe(s,r,a,n,o,"parent")}catch(e){continue}if(u)return u}if(i.textContent&&!i.textContent)if(!l||l&&!f(i.textContent)){let t;t=e.test(i.textContent)?w(i)?`//*[local-name()='${i.tagName}' and .=${p(d(i))}]`:`//${i.tagName||"*"}[.=${p(d(i))}]`:w(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${p(d(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${p(d(i))}]`;const l=pe(t,r,a,n,o,"parent");if(l)return l}else{const e=[],t=[...new Set(d(i).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&N(t[n].trim())&&(l.test(t[n])?e.push(`contains(.,${p(t[n].trim()).trim()})`):e.push(`contains(.,${p(N(t[n])).trim()})`));if(e?.length){const t=w(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,l=pe(t,r,a,n,o,"parent");if(l)return l}}if(!t){const e=w(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const u=s.join("")+r;if(1===g(u,t,n))return re.set(t,u),u}catch(e){return console.error(e),null}},ye=(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(E(n,o,a)){const a=c(n.name,n.nodeValue),l=n.name,s=H(o,l,a);let i;try{i=g(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=D(o);if(n){if(1===g(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=w(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}},ve=(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(E(n,l,!0)){const r=c(n.name,n.nodeValue),o=n.name,s=H(l,o,r);let i;try{i=g(s,l,t)}catch(e){continue}if(1===i){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=D(l);if(n){if(1===g(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=w(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 le.set(e,o),o}catch(e){return console.log(e),null}},Ne=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)xe(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)xe(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},xe=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=A(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=g(o,e,n);if(1===t)return void te.push({key:`xpath by ${l}`,value:o});t>1&&(ne.length?t<ne[0].count&&(ne.pop(),ne.push({key:`relative xpath by ${l}`,value:o,count:t})):ne.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=A(e,{name:"text",value:e.textContent},r),t){const a=g(t,e,n);if(1===a)return void te.push({key:`xpath by ${l}`,value:t});a>1&&(ne.length?a<ne[0].count&&(ne.pop(),ne.push({key:`relative xpath by ${l}`,value:t,count:a})):ne.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};function be(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();if(r)for(const o of e)if(E(o,t,a)){let e=c(o.name,o.nodeValue);const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==g(a,t,n))return a}}}const Ee=(e,t,n,a,l)=>{let r;return r=e.name,k(t,n,`@${r}`,e.value,a,l)},we=(e,t,n,a)=>{let l=e.className;if("string"!=typeof l&&(l=""),l=l?.replace("flndisabled","disabled"),l=c("class",l),l=l?.trim(),l)return k(e,t,"@class",l,n,a)},Se=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const l=h(e);if(l)return k(e,t,".",l,n,a)}},ke=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&E(e,t,l)){const r=Ee(e,t,n,a,l);r&&te.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=Se(t,n,a,l);if(o&&te.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&E(r?.find(e=>"className"===e.name),t,l)){let e=we(t,n,a,l);e&&te.push({key:"xpath by class",value:e})}if(!te.length&&r.length>1){const e=T(t,n,r,l);e&&te.push({key:"xpath by combination",value:e})}if(!te.length){const a=be(e,t,n,l);a&&te.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},Ce=(e,t,n,a,l=[],r=[])=>{te=[],console.log(e);const o=e,s=o?.getRootNode?.(),i=s?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,c=i?s:o?.ownerDocument||t,u=o.tagName,{attributes:f}=o,m=l.length>0?l:Array.from(f);if(ke(m,o,c,n,a),r.length){const e=r.flatMap(e=>ge(o,c,a,e));return te=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(e.filter(e=>1===g(e.value,o,c))),te}if(te.length){const t=te.length;for(let n=0;n<t;n++){let t=te[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===g(t,e,c)&&te.push({key:`${te[n].key} regex`,value:t})}}return te.length||i||(te=de(o,c,a,n)),te},Re={parseDOM:Ce,getTextXPath:Se,getUniqueClassName:we,attributesBasedXPath:Ee,addAllXPathAttributes:ke,addRelativeXpaths:(e,t,n,a,l)=>{try{let r,o,s=[];if(te=[],console.log(l),l)for(const t of l){let n=A(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=A(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(!te.length){if(Ne(e,t,a,s[l]),!te.length&&(r||(r=ye(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=g(a,e,t);if(1===o)te.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=y(a,e,t,o);l&&1===g(l,e,t)&&te.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!te.length&&(o||(o=ve(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=g(a,e,t);if(1===r)te.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=y(a,e,t,r);l&&1===g(l,e,t)&&te.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===te?.length&&te?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=Se(e,t,n,!1);a&&te.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!te.length){let r=$e(e.parentElement,t,e,a,s[l],n);r&&te.push({key:"xpath by unique parent",value:r})}}return te}catch(e){console.log(e)}},getXPathUsingAttributeAndText:be,getSiblingRelativeXPath:Ne,getChildRelativeXpath:ve,getParentRelativeXpath:ye,getUniqueParentXpath:$e,checkRelativeXpathRelation:pe,buildAxesStrategyXpaths:de};let Oe=[],Te=[];const Ae=/^[\S]+( [\S]+)*$/gi,De=(e,t,n,a,l,r,o,s=0,i=!1)=>{let c="";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 f=je(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,l,i);if(f)return f}else{c=`//${o+(s?"]".repeat(s):"")}/${n}::${F(t,e[e.length-1])}`;let r=g(c,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:S(c)}];if(r>1&&l&&(c=y(c,e[e.length-1],a,r),c&&(r=g(c,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:S(c)}]}},Pe=(e,t,n,a,l,r=!1,o=!1)=>{const s=e[e.length-2],i=e[e.length-1],u=x(i)??i.ownerDocument,f=n.find(e=>e?.key?.includes("absolute"))?.value||C(s,s.ownerDocument),m=[],d=[];f.split("/").map(e=>m.push(e)),m.map(e=>d.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||C(i,i.ownerDocument),$=[],y=[];g.split("/").map(e=>$.push(e)),$.map(e=>y.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var v=0;v<m.length&&m[v]==$[v];v++);const N=[];for(let e=v-1;e<m.length;e++)m[e]&&N.push(d[e]);const b=[];for(let e="descendant"===l?v:v-1;e<$.length;e++)$[e]&&(b.length?b.push(y[e]):b.push(y[e].replace(/\[([0-9]+)\]/gm,"")));let S;if(Te=a,e[e.length-2].textContent){S=Ae.test(e[e.length-2].textContent)?w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${p(h(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${p(h(e[e.length-2]))}]`:w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${U(e[e.length-2])})]`:`${e[e.length-2].tagName}[${U(e[e.length-2])}]`,N[N.length-1]=S;const n=N.join("["),a=N.length-1,s=n;for(let n=0;n<Te.length;n++){let i;if(i=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,i)return De(e,i,l,u||t,r,b,s,a,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(E(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=c(n.name,a);const s=n.name;S=w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${p(a)}]`:`${e[e.length-2].tagName}[@${s}=${p(a)}]`,N[N.length-1]=S;const i=N.join("["),f=N.length-1,m=i;for(let n=0;n<Te.length;n++){let a;return a=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,De(e,a,l,u||t,r,b,m,f,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(E(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=c(n.name,a);const s=O(n,e[e.length-2]);if(s){S=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,N[N.length-1]=S;const n=N.join("["),a=N.length-1,i=n;for(let n=0;n<Te.length;n++){let s;return s=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,De(e,s,l,u||t,r,b,i,a,o)}}}}}const k=N.join("["),R=N.length-1,T=je(`${k+(R?"]".repeat(R):"")}`,b,e[e.length-1],e,t,l,r,o);if(T)return T},Xe=(e,t,n,a,l,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const c=[];try{if(s=a.filter(e=>!e?.key?.includes("absolute")),i=l.filter(e=>!e?.key?.includes("absolute")),"ancestor"===n||"ancestor-or-self"===n){const a=Me(e,t,n,s,i,r);if(a.length)return a}for(let e=0;e<s.length;e++)for(let a=0;a<i.length;a++){let l=`//${0!==s[e].value.indexOf("//")?F(s[e].value):F(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[a].value.indexOf("//")?F(i[a].value):F(i[a].value.substring(i[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=g(l,t,t.ownerDocument);if(o>1)if(r){if(l=y(l,t,t.ownerDocument,o),l)return c.push({key:`dynamic ${n}${r?" index":""}`,value:S(l)}),c}else o>1&&(Oe.length?o<Oe[0].count&&(Oe.pop(),Oe.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):Oe.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return c.push({key:`dynamic ${n}`,value:S(l)}),c}if(!c.length)for(let a=0;a<s.length;a++)for(let l=0;l<i.length;l++){const u=`${0!==i[l].value.indexOf("//")?i[l].value:i[l].value.substring(i[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(u.length>1){const l=je(`${0!==s[a].value.indexOf("//")?F(s[a].value):F(s[a].value.substring(s[a].value.indexOf("//")+2))}`,u,t,[e,t],t.ownerDocument,n,r,o);if(console.log("getXpathRelationExpression traverseXpath",l),l)return c.push(...l),c}}}catch(e){console.log(e)}return c},_e=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,Le=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,Ie=(e,t)=>{for(const e of t){const t=Le(e.value);if(t&&1===t.split(_e).length)return F(t)}if(e.textContent){const t=U(e);if(t)return w(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`}if(e.attributes)for(const t of Array.from(e.attributes))if(E(t,e,!1)&&t.nodeValue)return w(e)?`*[local-name()='${e.tagName}' and @${t.name}=${p(c(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${p(c(t.name,t.nodeValue))}]`;return w(e)?`*[local-name()='${e.tagName}']`:e.tagName},Me=(e,t,n,a,l,r)=>{const o=[],s=((e,t)=>{let n=e;for(;n;){if(n.contains(t))return n;n=n.parentElement}return null})(e,t);if(!s||s===t)return o;const i=w(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let l=t;for(;l&&l!==e;){const e=l===t?Ie(t,n):w(l)?`*[local-name()='${l.tagName}']`:l.tagName;a.unshift(e),l=l.parentElement}return l===e?a.join("/"):""})(s,t,l);if(!c)return o;for(const e of a){const a=Le(e.value);if(!a)continue;let l=`//${F(a)}/${n}::${i}/${c}`,s=g(l,t,t.ownerDocument);if(1===s)return o.push({key:`dynamic ${n} bridge`,value:S(l)}),o;if(s>1&&r&&(l=y(l,t,t.ownerDocument,s),s=l?g(l,t,t.ownerDocument):0,l&&1===s))return o.push({key:`dynamic ${n} bridge index`,value:S(l)}),o}return o},je=(e,t,n,a,l,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${F(s)}`;const c=g(i,n,l);if(1===c)return[{key:`dynamic ${r}`,value:S(i)}];if(c>1&&o&&(i=y(i,a[a.length-1],l,c),i))return[{key:`dynamic ${r}${o?" index":""}`,value:S(i)}]}else for(let s=1;s<=t.length;s++){const c=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${F(c)}`;const u=g(i,n,l);if(1===u)return[{key:`dynamic ${r}`,value:S(i)}];if(u>1&&o&&(i=y(i,a[a.length-1],l,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:S(i)}]}},Ye={findRelativeXpath:(e,t,n,a,l,r,o=!1,s=null)=>{let i=[];const c=s||[],u=(r,s)=>{let c=[];c="descendant"===r||"descendant-or-self"===r?Pe([e,t],n,a,l,r,s,o)||[]:Xe(e,t,r,a,l,s,o)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,r);return i},getDescendantXpath:Pe,getAncestorBridgeXpath:Me,getXpathRelationExpression:Xe,getTraverseXpathExpression:je,getReferenceElementXpath:e=>{let t=[];if(t=Ce(e,e.ownerDocument,!1,!1),t?.length){let n=Ce(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Ce(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:R(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:R(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value})),t?.length){const n=B(e,e.ownerDocument,!1);n?.length&&(t=t.concat(n))}else t=B(e,e.ownerDocument,!1);const n=C(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t},getSmartRelations:(e,t)=>{const n=e.compareDocumentPosition(t),a=[],l=[],r=[];n&Node.DOCUMENT_POSITION_CONTAINS&&a.push("ancestor","ancestor-or-self","parent"),n&Node.DOCUMENT_POSITION_CONTAINED_BY&&a.push("child"),e.parentElement===t.parentElement&&a.push("following-sibling","preceding-sibling"),n&Node.DOCUMENT_POSITION_FOLLOWING&&l.push("following"),n&Node.DOCUMENT_POSITION_PRECEDING&&l.push("preceding"),r.push("descendant","descendant-or-self");const o=[...a,...l,...r];return[...new Set(o)]}};let ze=[];const Ve=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},qe=(e,t="single")=>{const n=[],a=e.getRootNode();try{const l=We(e);if(l&&Ve(l,e,a)&&(n.push({key:"cssSelector by id",value:l}),"single"===t))return n;const r=Be(e);r&&Ve(r,e,a)&&n.push({key:"cssSelector by class",value:r});const o=Fe(e);o&&n.push({key:"cssSelector by name",value:o})}catch(e){console.error(e)}return n},We=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&&!f(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(" > ")},Ue=new Set(["id","class","style"]);function He(e){return Array.from(e.attributes).filter(e=>!Ue.has(e?.name?.toLowerCase())&&e.value&&!f(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Fe=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=He(e);for(const t of l){const l=`${a}${t}`;if(Ve(l,e,n))return l}},Be=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||f(e.className)||ze?.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(" > ")},Ge={parseCssSelectors:qe,getIdCssPath:We,getAttributeCssPath:Fe,getClassCssPath:Be,getAbsoluteCssPath: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(" > ")}},Je=(e,t,n)=>{const a=G(e);if(ot(t,a)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(a)){const e=t.evaluate(a,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},Ze=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return et(e.body,t)},Ke=(e,t,n)=>Ze(t,e)===n,Qe=e=>e.name?.toLowerCase().includes("cssselector")??!1,et=(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){const e=et(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},tt=e=>e?.id||null,nt=e=>e.className||null,at=e=>e.textContent?.trim()||null,lt=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},rt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function ot(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 st(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 it=(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)}function o(e,t,n){if(Qe(t))return Ze(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+K(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=K(n);return e.querySelector(`[name="${t}"]`)}if("tagName"===t.name)return e.querySelector(n);if("linkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null;if("partialLinkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null;if(!t.name.includes("xpath")&&!n.startsWith("//")||t.type.match("dynamic"))return e.querySelector(n);{const a=ot(e,G(n));return a&&r(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),a}}function s(e,t,n){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const l=o(a,t,n);if(l)return l}catch{continue}return null}const i=(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 c=e.locators.filter(e=>"N"===e.isRecorded);if(c.length>0)for(const e of c)r(e);const u=String(n.value||n.type||"");if(u.includes("dynamic")||u.match("dynamic")||u.includes("{")||u.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let c=null;const u=n.value.split(">>>");for(const e of u){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(c=o(t,n,a),c||(c=s(t,n,a)),c||(c=et(t.body,a)),!c){console.error("Element not found at:",a);break}}const m=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(c){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),a=e.locators.filter(e=>Qe(e)&&e.value);for(const e of n)Je(e.value,t,c)&&r(e,{isSelfHealed:null});for(const e of a)Ke(e.value,t,c)&&r(e,{isSelfHealed:null});const o=l.filter(e=>"xpath"===e.name&&e.value),s=new Set(o.map(e=>Z(e.value))),u=[],h=tt(c);if(h&&!m("id",h)&&!f(h)){const n=e.locators.find(e=>"id"===e.name);Q(t,"id",h,c)&&(u.push("id"),r(n,{name:"id",type:"static",isRecorded:"Y",value:h}))}const d=c.tagName;if(d&&!m("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);Q(t,"tagName",d,c)&&(u.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const g=at(c);if(g&&!f(g)){const n=e.locators.find(e=>"linkText"===e.name);Q(t,"linkText",g,c)&&(u.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const p=lt(c);if(p&&!m("name",p)&&!f(p)){const n=e.locators.find(e=>"name"===e.name);Q(t,"name",p,c)&&(u.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=nt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!m("className",$)&&!f($)){const n=e.locators.find(e=>"className"===e.name);Q(t,"className",$,c)&&(u.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}qe(c,"single").forEach(e=>{e.value&&!m("cssSelector",e.value)&&r(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const y=Array.from(c.attributes).filter(e=>!u.includes(e.name));let v=[];try{v=Ce(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Je(e.value,t,c));let a=0;for(const t of e){if(a>=e.length)break;const n=Z(t.value);if(s.has(n))continue;const l=v.find(e=>e.value&&Z(e.value)===n);l?.value&&(r(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}if(a<e.length)for(const t of v){if(a>=e.length)break;if(!t.value)continue;const n=Z(t.value);s.has(n)||(r(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of rt)if(a.value.includes(e)){const l=st(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:tt(c)},{name:"name",value:lt(c)},{name:"className",value:nt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:at(c)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(f(a)||m(e,a)||"className"===e&&a.includes(" ")||Q(t,e,a,c)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&qe(c,"multiple").forEach(e=>{l.length>4||e.value&&(m("cssSelector",e.value)||Q(t,"cssSelector",e.value,c)&&r(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=l.map(e=>({...e,value:i(e.value,e.name,e.isRecorded)})),x=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:N.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 x}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};const ct={getOptimalClassChain:function e(t,n,a){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const l=n.tagName,r=["name","label","value"];for(const e of r){const r=a.find(t=>t.name===e);if(!r)continue;let o=r.value;if(!o)continue;if(o=o.trim().replace(/\s+/g," "),f(o))continue;const s=`//${l}[@${e}="${o}"]`;let i=0;try{i=g(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(o);if(1===i)return c?`/${l}[\`${e} CONTAINS "${o}"\`]`:`/${l}[\`${e} == "${o}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===l).indexOf(n)+1;return c?`/${l}[\`${e} CONTAINS "${o}"\`][${t}]`:`/${l}[\`${e} == "${o}"\`][${t}]`}}let o=`/${l}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===l);if(e.length>1){o+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,a)+o}catch(e){return console.log(`Unable to generate optimal -ios class chain : ${JSON.stringify(e)}`),null}},getOptimalPredicateString:function(e,t,n){try{if(!t?.tagName||1!==t?.nodeType||"XCUIElementTypeApplication"===t?.tagName)return"";let a=[],l=[];for(let r of n){const n=r.value,o=r.name;if(0!==n.length&&(n&&!f(n))){a.push(`@${o}="${n}"`);const r=`//*[${a.join(" and ")}]`;let s;l.push(`${o} == "${n}"`);try{s=g(r,t,e)}catch(e){console.log(e);continue}if(1===s)return l.join(" AND ")}}}catch(e){console.log(`The most optimal '-ios predicate string' could not be determined because an error was thrown: '${JSON.stringify(e,null,2)}'`)}return null}},ut=()=>({xpath:Re,referenceXpaths:Ye,xpathUtils:ee,getElementsFromHTML:it,cssSelectors:Ge,iosSelectors:ct});exports.createXPathAPI=ut,exports.default=ut;
2
2
  //# sourceMappingURL=index.browser.cjs.map