ff-dom 3.0.0-beta.3 → 3.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1 @@
1
- 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:r}=(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 o=t.get(r);o||(o=new Map,t.set(r,o));const l=o.get(e);if(l)return l;const s=a.evaluate(e,r,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let r,o=new Map,l=[];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=>/\d/.test(e||""),u=(e,t,n,a=!1)=>{const r=i(t),o=r.filter(e=>!!a||!c(e));return o.length?1===r.length&&1===o.length?[`@class=${v(o[0])}`]:o.map(t=>{const a=h(`contains(@class,${v(t)})`,O(e),e.tagName.toLowerCase());return{token:t,count:U(a,e,n)}}).sort((e,t)=>e.token.length!==t.token.length?e.token.length-t.token.length:e.count-t.count).map(({token:e})=>`contains(@class,${v(e)})`):[]},f=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),m=(e,t)=>t?"class"===e||"className"===e?i(t).join(" "):t.replace("removePointers","").trim():"",d=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(O(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(" ")},g=e=>/\d/.test(e),h=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,p=e=>{const t=e?.textContent;return t},$=e=>e?.childNodes[0]?.nodeValue||"",y=(e,t,n,r=!1)=>{try{if(C(n)){const{owner:a,contextNode:o,cloneElement:l,cloneElements:s}=R(n,t),i=a.evaluate(e,o,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),c=i.iterateNext(),u=i.iterateNext();if(!c)return 0;if(!u)return c===l?1:0;if(r&&Array.isArray(t)){let e,t=0;if(s.includes(c)&&t++,s.includes(u)&&t++,2===t)return 2;for(;e=i.iterateNext();)if(s.includes(e)&&(t++,2===t))return 2;return 0}return 2}const{first:o,second:l}=a(e,n);if(!o)return 0;if(!l)return o===t?1:0;if(r&&Array.isArray(t)){let a=0;if(t.includes(o)&&a++,t.includes(l)&&a++,2===a)return 2;const r=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=r.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}},v=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},N=e=>{const t=e.split("");let n=t.length;const a=[];for(;"["!==t[n-2];)a.push(t[n-2]),n--;a.reverse();let r="";for(let e=0;e<a.length;e++)r+=a[e];const o=r.length+2;let l=e.slice(0,e.length-o);return l=l.startsWith("(")&&l.endsWith(")")?l.slice(1,-1):e,l},b=(e,t,n,a)=>{try{const r=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===y(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===y(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const l=r.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=l.iterateNext();)if(o++,s.isSameNode(t))return 1===y(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===y(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},E=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(),x=e=>e?e.replace(/\s\s+/g," ").trim():e,w=(e,t)=>{const n=x((t||"").trim());if(!e.children.length||n.length<=50)return"";const a=n.split(/\s+/).slice(0,3).join(" ");return a.length>2?`contains(normalize-space(.),${v(a)})`:""},k=e=>{const t=x((e||"").trim());if(!t||!c(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),a=n.split(/[^a-zA-Z]+/).map(e=>x(e).trim()).filter(e=>e.length>2&&/[a-zA-Z]/.test(e)).join(" ").trim();return{prefix:n.length>2&&/[a-zA-Z]/.test(n)?n:"",fragment:a.length>2?a:""}},S=e=>k(e).fragment,A=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},C=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,R=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),a=n.createElement("div");a.innerHTML=e.innerHTML,n.body.appendChild(a);const r=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},o=Array.isArray(t)?t.map(e=>r(e)).filter(Boolean):[],l=Array.isArray(t)?null:r(t??null);return{owner:n,contextNode:a,cloneElement:l,cloneElements:o}},D=(e,t,n)=>{const a=m(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 r=l?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!r&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(o=e.name,s=a,(!f.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(s))&&("class"===e.name||!c(a)))));var o,s},O=e=>e instanceof SVGElement,T=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,P=(t,n,a,r,o,l)=>{if(r){const{tagName:s}=t;let i,f="";const m=[];let d;const p=a.startsWith("@"),$="."===a||"text()"===a,N=$?".":a,b=$&&/\s/.test(r.trim()),E=$?S(r):r,k=$&&c(r)?E:r,A=$?w(t,k):"";if("@class"===a){for(const e of u(t,r,n))if(d=h(e,O(t),t.tagName.toLowerCase()),i=y(d,t,n),1===i&&!o)return d;return}if($&&c(r)&&!E)return;if(r&&(!p||!g(r))&&(d=A?h(A,O(t),t.tagName.toLowerCase()):b?h(`normalize-space(${N})=${v(x(k)).trim()}`,O(t),t.tagName.toLowerCase()):e.test(r)?`//${s}[${a}=${v(k)}]`:h(`normalize-space(${a})=${v(x(k)).trim()}`,O(t),t.tagName.toLowerCase()),i=y(d,t,n),1===i&&!o))return d;if(p&&c(r))return;if(r&&l){const l=r.split(" ");if(l?.length)if(1===l.length){const c=[...new Set(l[0].match(/([^0-9]+)/g))];if(c?.length>=1&&c[0]&&x(c[0].trim())?.length>1&&r.startsWith(c[0])&&(f=e.test(c[0])?`starts-with(${a},${v(c[0]).trim()})`:`starts-with(${a},${v(x(c[0])).trim()})`),c?.length>1&&c[c.length-1]&&x(c[c.length-1].trim())?.length>1&&r.endsWith(c[c.length-1])&&(f=e.test(c[c.length-1])?`ends-with(${a},${v(c[c.length-1]).trim()})`:`ends-with(${a},${v(x(c[c.length-1])).trim()})`),f?.length&&(d=O(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d}else{const c=l.length%2==0?l.length/2:l.length%2,u=l.slice(0,c).join(" ");let m=[...new Set(u.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&x(m[0].trim())?.length&&r.startsWith(m[0])&&(f=e.test(m[0])?`starts-with(${a},${v(m[0]).trim()})`:`starts-with(${a},${v(x(m[0])).trim()})`),f?.length&&(d=O(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d;const g=l.slice(c,l.length-1).join(" ");if(m=[...new Set(g.match(/([^0-9]+)/g))],m?.length&&m[0]&&x(m[0].trim())?.length>3&&r.endsWith(m[0])&&(f=e.test(m[0])?`ends-with(${a},${v(m[0]).trim()})`:`ends-with(${a},${v(x(m[0])).trim()})`),f?.length&&(d=O(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d}}if(r&&l&&g(r)){const l=[...new Set(r.match(/([^0-9]+)/g))];if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&x(l[t].trim())?.length>1&&(e.test(l[t])?m.push(`contains(${a},${v(l[t].trim()).trim()})`):m.push(`contains(${a},${v(x(l[t])).trim()})`));if(m?.length&&(d=O(t)?`//*[local-name()='${s}' and ${m.join(" and ")}]`:`//${s}[${m.join(" and ")}]`,i=y(d,t,n),1===i&&!o))return d}if(d=O(t)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=y(d,t,n),1===i&&!o)return d}},X=(e,t)=>{try{if(!e)return"";let n=O(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 X(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},_=(e,t,n,a=!1,r)=>{try{if(o.has(e))return o.get(e);const l=[];let s=e;for(;s;){let o="",i=!1,c=e===s?r??s.attributes:s.attributes;for(const e of Array.from(c))if(D(e,s)){const a=m(e.name,e.nodeValue),r=e.name;for(const e of ee(s,r,a)){o=e;let a=0;if(a=y(o,s,t),1===a){l.unshift(T(o)),i=!0;break}if(a>1&&n&&(o=b(o,s,t,a),o)){l.unshift(T(o)),i=!0;break}}}if(s.textContent)if(!a||a&&!g(s.textContent)){let e=new RegExp(/^[\S]+( [\S]+)*$/gi);const a=$(s),r=w(s,a);o=r?h(r,O(s),s.tagName||"*"):e.test(s.textContent)?O(s)?`//*[local-name()='${s.tagName}' and .=${v(a)}]`:`//${s.tagName||"*"}[.=${v(a)}]`:O(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${v(a)}]`:`//${s.tagName||"*"}[normalize-space(.)=${v(a)}]`;let l=y(o,s,t);if(1===l)return o;if(l>1&&n)return o=b(o,s,t,l),o}else{let e=[];const a=[...new Set($(s).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&x(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${v(a[t].trim()).trim()})`):e.push(`contains(.,${v(x(a[t])).trim()})`));if(e?.length){o=O(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=y(o,s,t);if(1===a)return o;if(a>1&&n)return o=b(o,s,t,a),o}}if(i)break;{let e=O(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}]`}}l.unshift(e)}s=s.parentElement}const i=`${l.join("")}`;return o.set(e,i),i}catch(e){return console.log(e),null}},L=(t,n)=>{const a=[];let r="";if(t&&"function"!=typeof t.nodeValue){if("class"===t.name){const e=n.getRootNode?.()??n.ownerDocument,a=u(n,t.value,e);for(const e of a)if(r=O(n)?`//*[local-name()='${n.tagName}' and ${e}]`:`//${n.tagName}[${e}]`,r)return r;return}if(g(t.value))return;const o=[...new Set(t.value.match(/([^0-9]+)/g))];if(o?.length)for(let n=0;n<o?.length;n++)o[n]&&x(o[n].trim())?.length>2&&(e.test(o[n])?a.push(`contains(@${t.name},${v(o[n].trim())})`):a.push(`contains(@${t.name},${v(x(o[n])).trim()})`));if(a?.length)return r=O(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,r}},I=(t,n,a,r)=>{try{const r=a.filter(e=>D(e,t)),o=a=>{const r=m(a.name,a.nodeValue);return r?"class"===a.name?u(t,r,n):c(r)?[]:e.test(r)?[`@${a.name}="${r}"`]:[`normalize-space(@${a.name})="${r}"`]:[]},l=e=>{const t=o(e);return"class"===e.name?t.map(e=>[e]):t.length?[t]:[]},s=e=>e.reduce((e,t)=>{const n=l(t);return n.length?e.flatMap(e=>n.map(t=>[...e,...t])):[]},[[]]),i=()=>{const n=x(p(t)?.trim()||""),a=S(n);if(c(n))return a?[`contains(normalize-space(.),${v(a)})`]:[];if(!n||n.length>80||/^\d+$/.test(n)){const e=w(t,n);return e?[e]:[]}const r=new Set,o=w(t,n);return o?(r.add(o),Array.from(r)):(e.test(n)&&n.length<=40&&!n.includes(" ")&&r.add(`text()=${v(n)}`),n.includes(" ")&&r.add(`normalize-space(.)=${v(x(n))}`),r.add(`contains(text(),${v(n)})`),Array.from(r))},f=(e,t)=>{const n=[],a=(r,o)=>{if(o.length!==t)for(let t=r;t<e.length;t++)o.push(e[t]),a(t+1,o),o.pop();else n.push([...o])};return a(0,[]),n},d=e=>O(t)?`//*[local-name()='${t.tagName}' and ${e.join(" and ")}]`:`//${t.tagName}[${e.join(" and ")}]`,g=()=>{if(!(r.length<2))for(let e=2;e<=r.length;e++){const a=f(r,e);for(const e of a){const a=s(e);for(const e of a){if(e.length<2)continue;const a=d(e);let r;try{r=y(a,t,n)}catch{continue}if(1===r)return a}}}},h=g();if(h)return h;const $=i();if(!$.length||!r.length)return;for(let e=1;e<=r.length;e++){const a=f(r,e);for(const e of a){const a=s(e);for(const e of a)if(e.length)for(const a of $){const r=[...e,a],o=d(r);try{if(1===y(o,t,n))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},z=(e,t,n)=>M(e,t)[0]||"",M=(t,n,a)=>{let r=O(t),o="";if(D(n,t)){let a=m(n.name,n.value);const l=n.name;if("class"===l){const e=t.getRootNode?.()??t.ownerDocument;return u(t,a,e).map(e=>r?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName||"*"}[${e}]`)}if(c(a))return[];o=e.test(a)?r?`*[local-name()='${t.tagName}' and @${l}=${v(a)}]`:`${t.tagName||"*"}[@${l}=${v(a)}]`:r?`*[local-name()='${t.tagName}' and normalize-space(@${l})=${v(a)}]`:`${t.tagName||"*"}[normalize-space(@${l})=${v(a)}]`}return o?[o]:[]},j=(t,n)=>{if(!t.textContent)return"";const a=$(t),r=S(a);if(c(a)&&!r)return"";const o=c(a)?r:a,l=w(t,o);let s;return s=l?h(l,O(t),t.tagName||"*"):c(a)?h(`contains(normalize-space(.),${v(o)})`,O(t),t.tagName||"*"):!e.test(a)||/\s/.test(a.trim())?h(`normalize-space(.)=${v(o)}`,O(t),t.tagName||"*"):O(t)?`//*[local-name()='${t.tagName}' and .=${v(o)}]`:`//${t.tagName||"*"}[.=${v(o)}]`,s},Y=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{fragment:t}=k(n);return t?h(`contains(normalize-space(.),${v(t)})`,O(e),e.tagName.toLowerCase()):""}return h(`normalize-space(${t})=${v(x(n)).trim()}`,O(e),e.tagName.toLowerCase())},V=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{prefix:t,fragment:a}=k(n),r=t||a;return r?h(`starts-with(normalize-space(.),${v(r)})`,O(e),e.tagName.toLowerCase()):""}return h(`starts-with(${t},${v(x(n)).trim()})`,O(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{fragment:t}=k(n);return t?h(`contains(normalize-space(.),${v(t)})`,O(e),e.tagName.toLowerCase()):""}return h(`contains(${t},${v(x(n)).trim()})`,O(e),e.tagName.toLowerCase())},W=(t,n)=>{const a=n.flatMap(n=>(n=>{const a=m(n.name,n.value);if(!a)return[];if("class"===n.name){const e=t.getRootNode?.()??t.ownerDocument;return u(t,a,e)}return c(a)?[]:e.test(a)?[`@${n.name}=${v(a)}`]:[`normalize-space(@${n.name})=${v(a)}`]})(n)).filter(Boolean);if(a.length>=2)return h(`${a[0]} or ${a[1]}`,O(t),t.tagName.toLowerCase());const r=(()=>{const n=x(p(t)?.trim()||""),a=S(n);if(c(n))return a?`contains(normalize-space(.),${v(a)})`:null;const r=w(t,n);return r||(!n||n.length>80||/^\d+$/.test(n)?null:e.test(n)&&n.length<=40&&!n.includes(" ")?`text()=${v(n)}`:n.includes(" ")?`normalize-space(.)=${v(n)}`:`contains(text(),${v(n)})`)})();return 1===a.length&&r?h(`${a[0]} or ${r}`,O(t),t.tagName.toLowerCase()):""},U=(e,t,n)=>{try{return y(e,t,n)}catch(e){return 0}},F=(e,t)=>{const n=[],a=new Set,r=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","aria-label","role"],l=[...o.map(e=>r.find(t=>t.name===e)).filter(Boolean),...r.filter(e=>!o.includes(e.name))],s=r=>{r&&!a.has(r)&&Z(r,e,t)&&(a.add(r),n.push(r))};l.forEach(t=>{if(D(t,e))for(const n of ee(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=j(e);t&&s(t)}if(r.length>1){const n=I(e,t,r);n&&s(n)}return n},H=(e,t)=>{const n=[];let a=t;for(;a&&a!==e;)n.unshift(J(a)),a=a.parentElement;return a===e?n.join("/"):""},G=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),a=J(e),r=O(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const r=F(t,n);for(const o of r){console.log(`Trying ancestor XPath: ${o}`);const r=`${o}/descendant::${a}`;console.log(`Trying descendant XPath: ${r}`);const l=U(r,e,n);if(console.log(`Match count: ${l}`),1===l&&B(r,n)===e)return console.log(`Selected XPath: ${r}`),r;const s=H(t,e);if(s){const t=`${o}/${s}`;console.log(`Trying descendant XPath: ${t}`);const a=U(t,e,n);if(console.log(`Match count: ${a}`),1===a&&B(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${r}`);const o=U(r,e,n);return console.log(`Match count: ${o}`),1===o&&B(r,n)===e?(console.log(`Selected XPath: ${r}`),r):(console.log("Selected XPath: "),"")},B=(e,t)=>{try{if(C(t)){const{owner:n,contextNode:a,cloneElement:r}=R(t);return n.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||r}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},Z=(e,t,n)=>{try{const{first:r,second:o}=a(e,n);return!!r&&!o&&r===t}catch{return!1}},J=e=>O(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),K=(e,t,n)=>{if(!(e instanceof Element))return[];const a=new Set,r=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(n=t.value,!/\d/.test(n))&&D(t,e);var n}),l=(e,t)=>{t&&!a.has(t)&&(a.add(t),r.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","aria-label","role"];s.forEach(n=>{const a=o.find(e=>e.name===n);if(a)for(const n of ee(e,a.name,a.value))n&&Z(n,e,t)&&l(`anchor by ${a.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const a of ee(e,n.name,n.value))a&&Z(a,e,t)&&l(`anchor by ${n.name}`,a)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=j(e);n&&Z(n,e,t)&&l("anchor by text",n)}if(o.length>1){const n=I(e,t,o);n&&Z(n,e,t)&&l("anchor by combination",n)}const c=G(e,t);return c&&Z(c,e,t)&&l("anchor by tag",c),r},Q=e=>{const t=p(e)?.trim(),n=S(t);if(t&&c(t))return n?`contains(normalize-space(.),${v(n)})`:void 0;const a=w(e,t);if(a)return a;const r=t?v(E(t)):t;return r?r!==`'${t}'`?`contains(.,${r})`:/\s/.test(t)?`normalize-space(.)='${x(t)}'`:`normalize-space(.)='${t}'`:void 0},ee=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let r="";if(n=m(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return u(e,n,t).map(t=>O(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(c(n))return[];r=a.test(n)?O(e)?`//*[local-name()='${e.tagName}' and @${t}=${v(n)}]`:`//${e.tagName||"*"}[@${t}=${v(n)}]`:O(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${v(n)})]`:`//${e.tagName||"*"}[contains(@${t},${v(n)})]`}return r?[r]:[]},te=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,ne=(t,n,a)=>{let r;const o=[];if(t.textContent&&a&&g(t.textContent)){const{prefix:e,fragment:n}=k(p(t)),a=[e?`starts-with(normalize-space(.),${v(e)})`:"",n?`contains(normalize-space(.),${v(n)})`:""].filter((e,t,n)=>e&&n.indexOf(e)===t);for(const e of a)r=O(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r})}if(t.textContent&&(!a||a&&!g(t.textContent)))if(e.test(t.textContent)){const e=p(t),n=w(t,e),a=n||(/\s/.test(e.trim())?`normalize-space(.)=${v(x(e))}`:`.=${v(e)}`);r=O(t)?`*[local-name()='${t.tagName}' and ${a}]`:`${t.tagName}[${a}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}else{const e=Q(t);e&&(r=O(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r}))}if(t.attributes){const e="IMG"===t.tagName?Array.from(t.attributes).sort((e,t)=>"alt"===e.name?-1:"alt"===t.name?1:0):Array.from(t.attributes);for(const a of e)if(D(a,t)){let e=a.nodeValue;if(e){e=m(a.name,e);const l=a.name;if("class"!==l&&c(e))continue;if("class"===l){const a=u(t,e,n);if(!a.length)continue;for(const e of a)r=O(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r});continue}r=O(t)?`*[local-name()='${t.tagName}' and @${l}=${v(e)}]`:`${t.tagName}[@${l}=${v(e)}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}}}if(!o?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=I(t,n,Array.prototype.slice.call(t.attributes));e&&o.push({key:"getReferenceElementsXpath",value:e})}}if(!o?.length){const e=[];let n;const r=t.tagName;if(t.textContent&&a&&g(t.textContent)){const a=x(p(t)).trim();a?.length>1&&e.push(`contains(text(),${v(a)})`),e?.length&&(n=O(t)?`*[local-name()='${r}' and ${e.join(" and ")}]`:`${r}[${e.join(" and ")}]`,n&&o.push({key:"getReferenceElementsXpath",value:n}))}}if(!o?.length){const e=((e,t)=>{const n=Array.prototype.slice.call(e),a=[];try{n.map(e=>{if(D(e,t)){const n=L(e,t);n&&a.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return a})(t.attributes,t);e?.length&&o.concat(e)}return o},ae=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"),re=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function oe(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",r=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:r?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function le(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function se(e,t,n,a){const r=a?.getRootNode?.()??e,o=e=>{try{return Array.from(r.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===o(`#${le(n)}`).length;case"name":return 1===o(`[name="${le(n)}"]`).length;case"className":return 1===o(`.${n}`).length;case"tagName":case"cssSelector":return 1===o(n).length;case"linkText":return 1===o("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===o("a").filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const ie={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:ne,getAbsoluteXPath:X,getRelativeXPath:_,getCombinationXpath:L,getAttributeCombinationXpath:I,getElementFromXpath:(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const r=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?r.evaluate(e,a,null,XPathResult.ANY_TYPE,null):r.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},isSvg:O,findXpathWithIndex:b,isNumberExist:g,getTextContent:p,getCountOfXPath:y,normalizeXPath:ae,getShadowRoot:A,escapeCharacters:v,removeParenthesis:N,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:re,deleteGarbageFromInnerText:E,replaceTempAttributes:T,createObserver:e=>{r=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!d(t))&&n(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(d(t)||"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)=>{r?.observe(e,t)},stopObserver:()=>{r?.disconnect()},modifiedElementAttributes:l,cspEnabled:!1,getXPathPattern:oe,getNormalizedPropertyXPath:Y,getStartsWithPropertyXPath:V,getContainsPropertyXPath:q,getOrAttributesXPath:W,getTagOnlyXPath:G,getFirstMatchedNode:B,isExactUniqueXpath:Z,getAxisNodeTest:J,getUniqueNodeAnchorXpaths:K,escapeAttrValue:le,isUniqueInDOM:se,sanitizeAttributeValue:m,getClassTokenCondition:(e,t,n,a=!1)=>u(e,t,n,a)[0]||null,getClassTokenConditions:u,getXpathStrings:ee,intermediateXpathSteps:M,getContainerTextCondition:w};let ce=[],ue=[],fe=new Map,me=new Map;const de=new Map,ge={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},he=e=>ge[e]||e,pe=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),$e=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const a=e[n];if(t){a===t&&(t=null);continue}if("'"===a||'"'===a){t=a;continue}if("["!==a)continue;const r=e.indexOf("]",n+1);if(-1===r)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,r)))return!0}return!1})(e.value)),ye=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ve=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},Ne=(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},be=(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:()=>ve(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},Ee=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},xe=e=>{let t=0;e.id&&(t+=100),e.getAttribute("data-testid")&&(t+=90),e.className&&(t+=50),0===e.children.length&&(t+=30);const n=e.textContent?.trim();return n&&n.length<40&&(t+=40),t},we=(e,t,n,a,r,o,l)=>{const s=J(n),i=[];let c=0;const u=t.includes("descendant")?10:20;for(const r of e){if(c++>u)break;if(i.length>=5)break;const e="node"in r?r.node:r;if(!(e instanceof Element))continue;if(Ee(e))continue;const f=[()=>K(e,a),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&D(t,e));for(const a of n){const n=a.value;if(!n)continue;const r=q(e,`@${a.name}`,n);r&&t.push({key:"contains",value:r});const o=V(e,`@${a.name}`,n);o&&t.push({key:"starts-with",value:o})}return t},()=>[{key:"tag",value:G(e,a)}]];for(let r=0;r<f.length;r++){let c=f[r]();if(!c.length)continue;l||(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 r=`${e.value}/${t}::${s}`;if(Z(r,n,a)){if(i.push({key:o,value:r}),i.length>=2)return i;if(i.length>=5)return i}}if(l&&r===f.length-1)for(const r of c){const l=y(r.value,e,a);for(let e=1;e<=Math.min(l,3);e++){const l=`(${r.value})[${e}]/${t}::${s}`;if(Z(l,n,a)){if(i.push({key:o,value:l}),i.length>=2)return i;if(i.length>=5)return i}}}}if("expand"in r&&r.expand){const e=r.expand();let l=0;for(const r of e){if(l++>15)break;if(i.length>=5)break;if(!(r instanceof Element))continue;if(Ee(r))continue;const e=K(r,a);for(const r of e.slice(0,5)){const e=`${r.value}/${t}::${s}`;if(Z(e,n,a)){if(i.push({key:o,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},ke=(e,t)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},Se=(e,t)=>{for(let n=e.nextElementSibling;n;n=n.nextElementSibling)if(n===t)return"following-sibling";for(let n=e.previousElementSibling;n;n=n.previousElementSibling)if(n===t)return"preceding-sibling";return""},Ae=(e,t)=>{const n=[];for(let a=e;a&&a!==t;a=a.parentElement){const e=a.parentElement;if(!e)return"";n.push(`/parent::${J(e)}`)}return n.join("")},Ce=(e,t)=>{const n=J(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Re=(e,t,n)=>{const a=[],r=new Set,o=(e=>{const t=[],n=new Set,a=a=>{a&&a!==e&&!n.has(a)&&(a.contains(e)||e.contains(a)||(n.add(a),t.push(a)))};for(let n=e.parentElement,r=0;n&&r<4&&t.length<20;n=n.parentElement,r++){const e=[Ne(n,"previous").slice(0,4),Ne(n,"next").slice(0,4)];for(const t of e)for(const e of t){a(e);let t=0;for(const n of ve(e).sort((e,t)=>xe(t)-xe(e))){if(t++>=8)break;a(n)}}}return t.sort((e,t)=>xe(t)-xe(e)).slice(0,20)})(e),l=ke(e.parentElement,3);for(const n of o){const o=K(n,t).filter(e=>"anchor by tag"!==e.key).slice(0,2);if(!o.length)continue;const s=ke(n,3);for(const i of o)for(const o of s){const s=Ae(n,o);if(o===n||s)for(const n of l){if(!n||!n.contains(e))continue;const l=Se(o,n);if(!l)continue;const c=`/${l}::${J(n)}`;for(const o of Ce(n,e)){const n=`${i.value}${s}${c}${o}`;if(!r.has(n)&&(r.add(n),Z(n,e,t)&&(a.push({key:"chained axes fallback",value:n}),a.length>=2)))return a}}}}return a},De=(e,t)=>{const n=[];for(let a=t;a&&a!==e;a=a.parentElement)n.unshift(J(a));if(!n.length)return"";const a=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${a}`},Oe=(e,t,n,a)=>{const r=new Set,o=[],l=(e,t)=>{t&&!r.has(t)&&(!a&&/\[\d+\]/.test(t)||(r.add(t),o.push({key:e,value:t})))};return K(e,t).filter(e=>"anchor by tag"!==e.key).forEach(e=>l(e.key,e.value)),Array.from(e.attributes||[]).forEach(t=>{if(!(e=>!(!e?.value||["style","locator-data-tooltip","value"].includes(e.name)||0===e.name.indexOf("on")&&e.name.length>3))(t)||!c(t.value)||"class"===t.name)return;const n=(e=>{const t=(e.split(/\d/)[0]||"").replace(/[-_:\s.]+$/g,"").trim();return t.length>2&&/[a-zA-Z]/.test(t)?t:""})(t.value);if(!n)return;const a=q(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,a)}),o},Te=(e,t,n,a)=>{const r=[];for(let t=e.parentElement;t;t=t.parentElement)r.push(t);const o=ve(e),l=Ne(e,"previous"),s=Ne(e,"next"),i=be(e,"previous"),c=be(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(l),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(r),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(r),axis:"descendant",key:"descendant"},{nodes:u(r),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(o,10),axis:"ancestor",key:"ancestor"},{nodes:u(o,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]],m=((e,t,n,a)=>{const r=[],o=new Set;for(let n=e.parentElement,l=0;n&&l<8;n=n.parentElement,l++){const l=De(n,e);if(!l)continue;const s=Oe(n,t,0,a);for(const n of s.slice(0,3)){const a=`${n.value}${l}`;if(!o.has(a)&&(o.add(a),Z(a,e,t)&&(r.push({key:"child chain",value:a}),r.length>=2)))return r}}return r})(e,t,0,a);if(m.length)return m;for(const n of f)for(const r of n){const n=we(r.nodes,r.axis,e,t,0,r.key,a);if(n.length>0)return n}return Re(e,t)||[]},Pe=(e,t,n,a,r)=>{const o=he(a);return"text"===o?pe(a,((e,t,n)=>{if(!ye(e))return[];if("text"===n){const n=j(e)||qe(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?pe(a,((e,t,n)=>{const a=[],r=Array.from(e.attributes||[]).filter(t=>t?.value&&D(t,e)),o=ye(e),l="contains"===n?q:"startsWith"===n?V:"normalizeSpace"===n?Y:null;if(!l)return a;if(r.forEach(t=>{const r=l(e,`@${t.name}`,t.value);r&&a.push({key:`xpath by ${n} ${t.name}`,value:r})}),o){const t=l(e,".",o);t&&a.push({key:`xpath by ${n} text`,value:t})}return a})(e,0,o)):["and","or"].includes(o)?pe(a,((e,t,n,a)=>{const r=Array.from(e.attributes||[]).filter(t=>t?.value&&D(t,e));if("and"===a){const n=I(e,t,r);return n?[{key:"xpath by combination",value:n}]:[]}if("or"===a&&r.length>=1){const t=W(e,r);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,0,o)):"axes"===o?pe(a,Te(e,t,0,!1)):"index"===o?pe(a,((e,t)=>{const n=[],a=e.tagName.toLowerCase(),r=Array.from(t.querySelectorAll(a)).indexOf(e)+1;if(r<=0)return[];n.push({key:"xpath by index",value:`(//${a})[${r}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?ee(o,"id",o.id):ee(o,"class",o.className.toString());for(const r of t){const t=Array.from(o.querySelectorAll(a)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${r}//${a})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?pe(a,[{key:"xpath till tag",value:G(e,t)}]):[]},Xe=(e,t,n,a,r,o)=>{if(e){let l;l="parent"===o?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of l){fe?.get(e)||fe.set(e,y(e,n,a));const t=fe?.get(e);if(1===t)return e;if(t>1&&(ue.length?t<ue[0].count&&(ue.pop(),ue.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})):ue.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})),t>1&&r&&!ce.length){const o=b(e,n,a,t);o&&1===y(o,n,a)&&ce.push({key:"relative xpath by unique parent "+(r?"index":""),value:o})}}}return null},_e=(t,n,a,r,o,l)=>{try{if(de.has(t))return de.get(t);const s=[];let i=t;for(;i&&1===i.nodeType;){const t=!1;for(const e of Array.from(i.attributes))if(D(e,i)){const t=m(e.name,e.nodeValue),r=e.name;for(const e of ee(i,r,t)){let t;try{t=Xe(e,o,a,n,l,"parent")}catch(e){continue}if(t)return t}}if(i.textContent&&!i.textContent)if(!r||r&&!g(i.textContent)){let t;t=e.test(i.textContent)?O(i)?`//*[local-name()='${i.tagName}' and .=${v($(i))}]`:`//${i.tagName||"*"}[.=${v($(i))}]`:O(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${v($(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${v($(i))}]`;const r=Xe(t,o,a,n,l,"parent");if(r)return r}else{const e=[],t=[...new Set($(i).match(/([^0-9]+)/g))],r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&x(t[n].trim())&&(r.test(t[n])?e.push(`contains(.,${v(t[n].trim()).trim()})`):e.push(`contains(.,${v(x(t[n])).trim()})`));if(e?.length){const t=O(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,r=Xe(t,o,a,n,l,"parent");if(r)return r}}if(!t){const e=O(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const c=s.join("")+o;if(1===y(c,t,n))return de.set(t,c),c}catch(e){return console.error(e),null}},Le=(e,t,n,a)=>{const r=new Map;if(r.has(e))return r.get(e);const o=[];let l=e;try{for(;l&&1===l.nodeType;){if(!l.tagName)return"";let e=!1;for(const n of Array.from(l.attributes)){if(D(n,l)){const a=m(n.name,n.nodeValue),r=n.name;for(const n of ee(l,r,a)){let a;try{a=y(n,l,t)}catch(e){continue}if(1===a){o.unshift(n),e=!0;break}}}if(e)break}if(!e&&l.textContent&&!n.textContent){const n=j(l);if(n){if(1===y(n,l,t)){e=!0,o.unshift(n);break}}}if(e)break;{const e=O(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;o.unshift(e)}l=l.parentElement}const a=o.join("");return r.set(e,a),a}catch(e){return console.log(e),null}},Ie=(e,t,n)=>{const a=[];let r;const o=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?o.unshift(e.firstElementChild):null!=e.nextElementSibling&&o.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&o.unshift(t.nextElementSibling);try{do{let e=!1;for(r=o.pop();null!==r;){for(const n of Array.from(r.attributes)){if(D(n,r)){const o=m(n.name,n.nodeValue),l=n.name;for(const n of ee(r,l,o)){let o;try{o=y(n,r,t)}catch(e){continue}if(1===o){e=!0,a.push(n);break}}}if(e)break}if(!e&&r.textContent&&!n.textContent){const n=j(r);if(n){if(1===y(n,r,t)){e=!0,a.push(n);break}}}if(e)break;{const e=O(r)?`/*[local-name()='${r.tagName}']`:`/${r.tagName}`;a.push(e),null!=r.firstElementChild?(o.push(r.nextElementSibling),r=r.firstElementChild):r=r.nextElementSibling}}}while(o.length>0);const l=a.join("");return me.set(e,l),l}catch(e){return console.log(e),null}},ze=(e,t,n,a)=>{try{const r=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==r;o=o.nextElementSibling)Me(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==r;o=o.previousElementSibling)Me(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},Me=(e,t,n,a,r,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){const l=M(e,{name:t.name,value:t.value},o);for(let t of l){t+=`/${r}::${a}`;const o=y(t,e,n);if(1===o)return void ce.push({key:`xpath by ${r}`,value:t});o>1&&(ue.length?o<ue[0].count&&(ue.pop(),ue.push({key:`relative xpath by ${r}`,value:t,count:o})):ue.push({key:`relative xpath by ${r}`,value:t,count:o}))}}if(!o){let t;if(t=z(e,{name:"text",value:e.textContent}),t){const a=y(t,e,n);if(1===a)return void ce.push({key:`xpath by ${r}`,value:t});a>1&&(ue.length?a<ue[0].count&&(ue.pop(),ue.push({key:`relative xpath by ${r}`,value:t,count:a})):ue.push({key:`relative xpath by ${r}`,value:t,count:a}))}}}catch(e){console.log(`${r} xpath-error`,e)}};function je(e,t,n,a){const{tagName:r}=t,o=t.textContent.trim();if(!o)return;const l=x(o),s=S(l);if(c(l)&&!s)return;const i=c(l)?s:l,u=w(t,i);for(const a of e)if(D(a,t)){let e=m(a.name,a.nodeValue);const s=`//${r}[@${a.name}='${e}' and ${u||(c(l)?`contains(normalize-space(.),${v(i)})`:/\s/.test(o)?`normalize-space(.)=${v(i)}`:`text()=${v(i)}`)}]`;if(s){if(1==y(s,t,n))return s}}}const Ye=(e,t,n,a,r)=>{let o;if(o=e.name,D(e,t))return P(t,n,`@${o}`,e.value,a,r)},Ve=(e,t,n,a)=>{let r=e.className;if("string"!=typeof r&&(r=""),r=r?.replace("flndisabled","disabled"),r=m("class",r),r=r?.trim(),r&&D({name:"class",value:r},e))return P(e,t,"@class",r,n,a)},qe=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const r=p(e);if(r)return P(e,t,".",r,n,a)}},We=(e,t,n,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&D(e,t)){const o=Ye(e,t,n,a,r);o&&ce.push({key:`xpath by ${e.name}${a?" index":""}`,value:o})}});const l=qe(t,n,a,r);if(l&&ce.push({key:"xpath by text"+(a?" index":""),value:l}),o.find(e=>"className"===e.name)&&D(o?.find(e=>"className"===e.name),t)){let e=Ve(t,n,a,r);e&&ce.push({key:"xpath by class",value:e})}if(!ce.length&&o.length>1){const e=I(t,n,o);e&&ce.push({key:"xpath by combination",value:e})}if(!ce.length){const a=je(e,t,n);a&&ce.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},Ue=(e,t,n,a,r=[],o=[])=>{ce=[],console.log(e);const l=e,s=l?.getRootNode?.(),i=s?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,c=i?s:l?.ownerDocument||t,u=l.tagName,{attributes:f}=l,m=r.length>0?r:Array.from(f);if(We(m,l,c,n,a),o.length){const e=n||((e=[])=>e.some(e=>"index"===he(e)))(o),t=o.flatMap(e=>Pe(l,c,0,e));return ce=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(t.filter(e=>1===y(e.value,l,c))),$e(ce,e)}if(ce.length){const t=ce.length;for(let n=0;n<t;n++){let t=ce[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===y(t,e,c)&&ce.push({key:`${ce[n].key} regex`,value:t})}}return ce.length||i||(ce=Te(l,c,0,n)),$e(ce,n)},Fe={parseDOM:Ue,getTextXPath:qe,getUniqueClassName:Ve,attributesBasedXPath:Ye,addAllXPathAttributes:We,addRelativeXpaths:(e,t,n,a,r)=>{try{let o,l,s=[];if(ce=[],console.log(r),r)for(const t of r){const n=M(e,{name:t.name,value:t.value},a);console.log(n[0]||"");for(const e of n)e&&s.push(e)}if(e.textContent){let t=z(e,{name:"text",value:e.textContent});console.log(t),t&&s.push(t)}if(s.push(e.tagName),s?.length)for(let r=0;r<s.length;r++)if(!ce.length){if(ze(e,t,a,s[r]),!ce.length&&(o||(o=Le(e.parentElement,t,e)),console.log(o),o&&(o.includes("@")||o.includes("text()")||o.includes(".="))&&o.match(/\//g)?.length-2<5)){const a=o+`/${s[r]}`,l=y(a,e,t);if(1===l)ce.push({key:"relative xpath by relative parent",value:a});else if(l>1&&n){const r=b(a,e,t,l);r&&1===y(r,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(!ce.length&&(l||(l=Ie(e,t,e)),l&&(l.includes("@")||l.includes("text()")||l.includes(".=")))){const a=l.replace(/^\/+/,""),o=`/${s[r]}/${a}`,i=y(o,e,t);if(1===i)ce.push({key:"relative xpath by relative child",value:o});else if(i>1&&n){const a=b(o,e,t,i);a&&1===y(a,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===ce?.length&&ce?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=qe(e,t,n,!1);a&&ce.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!ce.length){let o=_e(e.parentElement,t,e,a,s[r],n);o&&ce.push({key:"xpath by unique parent",value:o})}}return ce}catch(e){console.log(e)}},getXPathUsingAttributeAndText:je,getSiblingRelativeXPath:ze,getChildRelativeXpath:Ie,getParentRelativeXpath:Le,getUniqueParentXpath:_e,checkRelativeXpathRelation:Xe,buildAxesStrategyXpaths:Te};let He=[],Ge=[];const Be=/^[\S]+( [\S]+)*$/gi,Ze=(e,t,n,a,r,o,l,s=0,i=!1)=>{let c="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=o.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=o.length;e++)c.unshift(e===o.length?o[o.length-e]:u[u.length-e]);const f=Et(`${l+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,r,i);if(f)return f}else{c=`//${l+(s?"]".repeat(s):"")}/${n}::${te(t,e[e.length-1])}`;let o=y(c,e[e.length-1],a);if(1===o)return[{key:`dynamic ${n}`,value:T(c)}];if(o>1&&r&&(c=b(c,e[e.length-1],a,o),c&&(o=y(c,e[e.length-1],a),1===o)))return[{key:`dynamic ${n} ${r?" index":""}`,value:T(c)}]}},Je=(e,t,n,a,r,o=!1,l=!1)=>{const s=e[e.length-2],i=e[e.length-1],c=A(i)??i.ownerDocument,u=n.find(e=>e?.key?.includes("absolute"))?.value||X(s,s.ownerDocument),f=[],d=[];u.split("/").map(e=>f.push(e)),f.map(e=>d.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||X(i,i.ownerDocument),h=[],$=[];g.split("/").map(e=>h.push(e)),h.map(e=>$.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var y=0;y<f.length&&f[y]==h[y];y++);const N=[];for(let e=y-1;e<f.length;e++)f[e]&&N.push(d[e]);const b=[];for(let e="descendant"===r?y:y-1;e<h.length;e++)h[e]&&(b.length?b.push($[e]):b.push($[e].replace(/\[([0-9]+)\]/gm,"")));let E;if(Ge=(e=>{const t=e=>{const t=e.value||"",n=/(?:contains\s*\(\s*normalize-space\s*\(\s*\.\s*\)|normalize-space\s*\(\s*\.\s*\)|contains\s*\(\s*text\s*\(\s*\)|text\s*\(\s*\)|\.\s*=)/.test(t),a=/@/.test(t);return n&&!a?0:n?1:2};return[...e].sort((e,n)=>t(e)-t(n))})(a),e[e.length-2].textContent){if(Be.test(e[e.length-2].textContent)){const t=e[e.length-2],n=p(t),a=w(t,n),r=a||(/\s/.test(n.trim())?`normalize-space(.)=${v(x(n))}`:`.=${v(n)}`);E=O(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${r}]`:`${e[e.length-2].tagName}[${r}]`}else E=O(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${Q(e[e.length-2])})]`:`${e[e.length-2].tagName}[${Q(e[e.length-2])}]`;N[N.length-1]=E;const n=N.join("["),a=N.length-1,s=n;for(let n=0;n<Ge.length;n++){let i;if(i=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value,i){const n=Ze(e,i,r,c||t,o,b,s,a,l);if(n?.length)return n}}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(D(n,e[e.length-2])){let a=n.nodeValue;if(a){a=m(n.name,a);const s=n.name;E=O(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${v(a)}]`:`${e[e.length-2].tagName}[@${s}=${v(a)}]`,N[N.length-1]=E;const i=N.join("["),u=N.length-1,f=i;for(let n=0;n<Ge.length;n++){let a;a=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value;const s=Ze(e,a,r,c||t,o,b,f,u,l);if(s?.length)return s}}}for(const n of Array.from(e[e.length-2].attributes))if(D(n,e[e.length-2])){let a=n.nodeValue;if(a){a=m(n.name,a);const s=L(n,e[e.length-2]);if(s){E=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,N[N.length-1]=E;const n=N.join("["),a=N.length-1,i=n;for(let n=0;n<Ge.length;n++){let s;s=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value;const u=Ze(e,s,r,c||t,o,b,i,a,l);if(u?.length)return u}}}}}const k=N.join("["),S=N.length-1,C=Et(`${k+(S?"]".repeat(S):"")}`,b,e[e.length-1],e,t,r,o,l);if(C)return C},Ke=(e,t,n,a,r,o,l)=>{let s,i;console.log("getXpathRelationExpression",n);const c=[];try{s=a.filter(e=>!e?.key?.includes("absolute")).filter(t=>$t(t.value,e)),i=r.filter(e=>!e?.key?.includes("absolute"));for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const l=0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2),u=lt(s[a].value,e);let f=`//${u}/${n}::${te(l)}`;console.log("getXpathRelationExpression",f);const m=y(f,t,t.ownerDocument);if(m>1){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=mt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:T(r)}),c;const l=gt(u,n,t,i,t.ownerDocument);if(l)return c.push({key:`dynamic ${n}`,value:T(l)}),c;if(o){if(f=b(f,t,t.ownerDocument,m),f)return c.push({key:`dynamic ${n}${o?" index":""}`,value:T(f)}),c}else m>1&&(He.length?m<He[0].count&&(He.pop(),He.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m})):He.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m}))}else if(1===m){if(ot(l)){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=mt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:T(r)}),c}return c.push({key:`dynamic ${n}`,value:T(f)}),c}}if(!c.length){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;for(let a=0;a<s.length;a++){const r=lt(s[a].value,e),o=mt(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:T(o)}),c}for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const u=`${0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(u.length>1){const r=lt(s[a].value,e),f=mt(r,e,t,n,i);if(f)return c.push({key:`dynamic ${n} bridge`,value:T(f)}),c;const m=Et(r,u,t,[e,t],t.ownerDocument,n,o,l);if(console.log("getXpathRelationExpression traverseXpath",m),m)return c.push(...m),c}}}}catch(e){console.log(e)}return c},Qe=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,et=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,tt=(e,t)=>nt(e,t)[0]||"",nt=(e,t)=>{const n=[];let a="";const r=e=>{e&&!n.includes(e)&&n.push(e)};for(const n of t){const t=et(n.value);if(t&&1===t.split(Qe).length){if(t===e.tagName||t===e.tagName.toLowerCase()){a=t;continue}r(te(t))}}for(const t of at){const n=e.getAttribute(t);if(!n)continue;const a=rt(t,n);a&&r(O(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`)}if(e.textContent){const t=Q(e);t&&r(O(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`)}const o=u(e,e.getAttribute("class"),e.getRootNode?.()??e.ownerDocument,!1);for(const t of o)r(O(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`);if(e.attributes)for(const t of Array.from(e.attributes))"class"!==t.name&&D(t,e)&&t.nodeValue&&r(O(e)?`*[local-name()='${e.tagName}' and @${t.name}=${v(m(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${v(m(t.name,t.nodeValue))}]`);return a&&r(a),r(O(e)?`*[local-name()='${e.tagName}']`:e.tagName),n},at=["aria-labelledby","aria-label","role","name","data-testid","data-test","data-qa","data-id","id"],rt=(e,t)=>{const n=m(e,t);return n?/\d/.test(n)?"":`@${e}=${v(n)}`:""},ot=e=>e.split(Qe).length>1||/\[\d+\]/.test(e),lt=(e,t)=>0!==e.indexOf("//")?te(e):te(e.substring(e.indexOf("//")+2)),st=e=>{const t=[];for(const n of at){const a=e.getAttribute(n);if(!a)continue;const r=rt(n,a);if(r){t.push(O(e)?`*[local-name()='${e.tagName}' and ${r}]`:`${e.tagName}[${r}]`);break}}return t},it=(e,t=6)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},ct=(e,t)=>{const n=rt(e,t);if(n)return n;const a=m(e,t);if("id"!==e||!a)return"";const r=a.match(/^(.+?)-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),o=r?.[1]?.trim();return!o||o.length<=2||!/[a-zA-Z]/.test(o)?"":`contains(@${e},${v(o)})`},ut=(e,t,n,a,r,o,l)=>{let s=n.parentElement,i=0;for(;s&&s!==a&&i<6;){i++;for(const t of at){const a=s.getAttribute(t);if(!a)continue;const i=rt(t,a);if(!i)continue;const c=O(s)?`*[local-name()='${s.tagName}' and ${i}]`:`${s.tagName}[${i}]`,u=`//${te(e)}/${r}::${o}/descendant::${c}/descendant::${te(l)}`;if(1===y(u,n,n.ownerDocument))return u}s=s.parentElement}return""},ft=["title",...at],mt=(e,t,n,a,r)=>((e,t,n,a,r)=>{if("following"!==a&&"preceding"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=pt(`//${te(e)}`,t.ownerDocument)||t;let s=n.parentElement,i=0;for(;s&&i<6;)if(i++,l.compareDocumentPosition(s)&("following"===a?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING)){for(const t of ft){const r=s.getAttribute(t);if(!r)continue;const l=rt(t,r);if(!l)continue;const i=O(s)?`*[local-name()='${s.tagName}' and ${l}]`:`${s.tagName}[${l}]`;for(const t of o){const r=`//${te(e)}/${a}::${i}/descendant::${te(t)}`;if(1===y(r,n,n.ownerDocument))return r}}s=s.parentElement}else s=s.parentElement;return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("following-sibling"!==a&&"preceding-sibling"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=it(t),s=it(n);for(const t of l){const r=st(t);if(r.length)for(const l of s){const s=st(l);if(!s.length)continue;const i="following-sibling"===a?t.nextElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)>Array.from(t.parentElement?.children||[]).indexOf(t):t.previousElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)<Array.from(t.parentElement?.children||[]).indexOf(t);if(t.parentElement&&t.parentElement===l.parentElement&&i)for(const t of r)for(const r of s)for(const l of o){const o=`//${te(e)}/ancestor-or-self::${t}/${a}::${r}/descendant-or-self::${te(l)}`;if(1===y(o,n,n.ownerDocument))return o}}}return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("child"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=it(n).filter(e=>e.parentElement===t);for(const t of l){const a=st(t);if(a.length)for(const t of a)for(const a of o){const r=`//${te(e)}/child::${t}/descendant-or-self::${te(a)}`;if(1===y(r,n,n.ownerDocument))return r}}return""})(e,t,n,a,r),dt=(e,t,n,a,r)=>"ancestor"!==n&&"ancestor-or-self"!==n?[]:bt(e,t,n,a,r,!1),gt=(e,t,n,a,r)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";for(const o of a){const a=et(o.value);if(!a||a.split(Qe).length>1||/\[\d+\]/.test(a))continue;const l=`//${e}/${t}::${te(a)}`;if(1===y(l,n,r))return l}return""},ht=(e,t,n,a)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";const r=nt(n,[...Ue(n,n.ownerDocument,!1,!1)||[],...ne(n,n.ownerDocument,!0)||[],{key:"tag",value:n.tagName}]);if(!r.length)return"";let o=n.parentElement,l=0;for(;o&&l<10;){l++;for(const l of at){const s=o.getAttribute(l);if(!s)continue;const i=ct(l,s);if(!i)continue;const c=O(o)?`*[local-name()='${o.tagName}' and ${i}]`:`${o.tagName}[${i}]`;for(const o of r){const r=`//${e}/${t}::${c}/descendant::${te(o)}`;if(1===y(r,n,a))return r}}o=o.parentElement}return""},pt=(e,t)=>{try{const n=t.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return n instanceof Element?n:null}catch{return null}},$t=(e,t)=>{const n=et(e);if(!n)return!1;try{const e=t.ownerDocument.evaluate(`//${te(n)}`,t.ownerDocument,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let a=e.iterateNext();for(;a;){if(a===t)return!0;a=e.iterateNext()}}catch{return!1}return!1},yt=e=>{const t=e.getAttribute("fill"),n=e.getAttribute("stroke");if(/\d/.test(t||"")||/\d/.test(n||""))return"";const a=t?`@fill=${v(t)}`:n?`@stroke=${v(n)}`:"";return a?`*[local-name()='${e.tagName.toLowerCase()}' and ${a}]`:""},vt=(e,t,n)=>{const a=t.getAttribute("fill"),r=t.getAttribute("stroke"),o=Array.from(e.querySelectorAll(t.tagName.toLowerCase())).slice(0,30);let l=0;for(const e of o){if(a&&e.getAttribute("fill")!==a||!a&&r&&e.getAttribute("stroke")!==r)continue;const t=e.closest(n.tagName.toLowerCase());if(t&&(l++,t!==n||l>1))return!1}return 1===l},Nt=(e,t,n,a,r)=>{const o=Array.from(n.querySelectorAll("path,use,circle,rect,polygon,polyline,line")).slice(0,25);if(!o.length)return"";const l=[...(s=a,u(s,s.getAttribute("class"),s.getRootNode?.()??s.ownerDocument).map(e=>`${s.tagName.toLowerCase()}[${e}]`)),a.tagName];var s;for(const t of o){const o=yt(t);if(o&&vt(a,t,n))for(const t of l)return`//${te(e)}/${r}::${t}/descendant::${o}/ancestor::${n.tagName.toLowerCase()}`}return""},bt=(e,t,n,a,r,o)=>{const l=[],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 l;const i=O(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let r=t;for(;r&&r!==e;){const e=r===t?tt(t,n):O(r)?`*[local-name()='${r.tagName}']`:r.tagName;a.unshift(e),r=r.parentElement}return r===e?a.join("/"):""})(s,t,r);if(!c)return l;const u=c.split(Qe).length>1?tt(t,r):"",f=u?((e,t)=>{let n=e,a=0;const r=[],o=new Set(["SECTION","FIELDSET","FORM","ARTICLE","MAIN"]);for(;n&&n.contains(t)&&a<6;){a++;for(const e of at){const t=n.getAttribute(e);if(!t)continue;const l=rt(e,t);if(!l)continue;const s=O(n)?`*[local-name()='${n.tagName}' and ${l}]`:`${n.tagName}[${l}]`,i=(o.has(n.tagName)?100:0)+("data-testid"===e?20:0)-a;r.push({nodeTest:s,score:i});break}n=n.parentElement}return r.sort((e,t)=>t.score-e.score)[0]?.nodeTest||""})(s,t):"";for(const e of a){const a=et(e.value);if(!a)continue;if(f){const e=`//${te(a)}/${n}::${f}/descendant::${te(u)}`;if(1===y(e,t,t.ownerDocument))return l.push({key:`dynamic ${n} bridge`,value:T(e)}),l}let r=u?`//${te(a)}/${n}::${i}/descendant::${te(u)}`:`//${te(a)}/${n}::${i}/${c}`,m=y(r,t,t.ownerDocument);const d=Nt(a,0,t,s,n);if(d)return l.push({key:`dynamic ${n} icon bridge`,value:T(d)}),l;if(1===m)return l.push({key:`dynamic ${n} bridge`,value:T(r)}),l;if(u&&m>1){const e=ut(a,0,t,s,n,i,u);if(e)return l.push({key:`dynamic ${n} bridge`,value:T(e)}),l;if(r=`//${te(a)}/${n}::${i}/${c}`,m=y(r,t,t.ownerDocument),1===m)return l.push({key:`dynamic ${n} bridge`,value:T(r)}),l}if(m>1&&o&&(r=b(r,t,t.ownerDocument,m),m=r?y(r,t,t.ownerDocument):0,r&&1===m))return l.push({key:`dynamic ${n} bridge index`,value:T(r)}),l}return l},Et=(e,t,n,a,r,o,l,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${o}::${te(s)}`;const c=y(i,n,r);if(1===c)return[{key:`dynamic ${o}`,value:T(i)}];if(c>1&&l&&(i=b(i,a[a.length-1],r,c),i))return[{key:`dynamic ${o}${l?" index":""}`,value:T(i)}]}else for(let s=1;s<=t.length;s++){const c=xt(t.slice(t.length-s,t.length).join("/"),n);for(const t of c){i=`//${e}/${o}::${te(t)}`;const s=y(i,n,r);if(1===s){if(t.split(Qe).length>1||/\[\d+\]/.test(t)){const t=ht(e,o,n,r);if(t)return[{key:`dynamic ${o}`,value:T(t)}]}return[{key:`dynamic ${o}`,value:T(i)}]}if(s>1){const t=gt(e,o,n,Ue(n,n.ownerDocument,!1,!1)||[],r);if(t)return[{key:`dynamic ${o}`,value:T(t)}];const c=ht(e,o,n,r);if(c)return[{key:`dynamic ${o}`,value:T(c)}];if(l&&(i=b(i,a[a.length-1],r,s),i))return[{key:`dynamic ${o}${l?" index":""}`,value:T(i)}]}}}},xt=(e,t)=>{const n=t.getAttribute("class")||"",a=u(t,n,t.getRootNode?.()??t.ownerDocument);if(!a.length)return[e];const r=`${t.tagName}[@class=${v(n)}]`;return e.endsWith(r)?a.map(n=>{const a=`${t.tagName}[${n}]`;return`${e.slice(0,-r.length)}${a}`}):[e]},wt={findRelativeXpath:(e,t,n,a,r,o,l=!1,s=null)=>{let i=[];const c=s||[],u=(o,s)=>{let c=[];c="descendant"===o||"descendant-or-self"===o?Je([e,t],n,a,r,o,s,l)||[]:Ke(e,t,o,a,r,s,l)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,o);return i},getDescendantXpath:Je,getAncestorBridgeXpath:bt,getXpathRelationExpression:Ke,getTraverseXpathExpression:Et,getReferenceElementXpath:e=>{let t=[];t=Ue(e,e.ownerDocument,!1,!1);const n=ne(e,e.ownerDocument,!1);if(n?.length&&(t=t?.length?t.concat(n):n),t?.length){let n=Ue(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Ue(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value});t?.length||(t=[{key:"",value:_(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:_(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value}));const a=Array.from(e.children||[]).map(t=>{const n=p(t)?.trim();if(!n||n!==p(e)?.trim())return null;const a=w(t,n),r=a||(/\s/.test(n)?`normalize-space(.)=${v(x(n))}`:`.=${v(n)}`);return{key:"reference child text",value:`${t.tagName}[${r}]`}}).filter(e=>!!e);a.length&&(t=a.concat(t));const r=X(e,e.ownerDocument);return t=t.filter(e=>e.value!==r),t.push({key:"absolute xpath",value:r.slice(1)}),t},getSmartRelations:(e,t)=>{const n=e.compareDocumentPosition(t),a=[],r=[],o=[];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&&r.push("following"),n&Node.DOCUMENT_POSITION_PRECEDING&&r.push("preceding"),o.push("descendant","descendant-or-self");const l=[...a,...r,...o];return[...new Set(l)]}};let kt=[];const St=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},At=(e,t="single")=>{const n=[],a=e.getRootNode();try{const r=Ct(e);if(r&&St(r,e,a)&&(n.push({key:"cssSelector by id",value:r}),"single"===t))return n;const o=Tt(e);o&&St(o,e,a)&&n.push({key:"cssSelector by class",value:o});const l=Ot(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},Ct=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&&!g(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(" > ")},Rt=new Set(["id","class","style"]);function Dt(e){return Array.from(e.attributes).filter(e=>!Rt.has(e?.name?.toLowerCase())&&e.value&&!g(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Ot=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 r=Dt(e);for(const t of r){const r=`${a}${t}`;if(St(r,e,n))return r}},Tt=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||g(e.className)||kt?.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(" > ")},Pt={parseCssSelectors:At,getIdCssPath:Ct,getAttributeCssPath:Ot,getClassCssPath:Tt,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 r=e.parentNode;if(r){const t=Array.from(r.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(" > ")}},Xt=(e,t,n)=>{const a=ae(e);if(Wt(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},_t=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return zt(e.body,t)},Lt=(e,t,n)=>_t(t,e)===n,It=e=>e.name?.toLowerCase().includes("cssselector")??!1,zt=(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=zt(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},Mt=e=>e?.id||null,jt=e=>e.className||null,Yt=e=>e.textContent?.trim()||null,Vt=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},qt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Wt(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 Ut(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),r=n.defaultView;if(!r)return null;if(!e.includes("dynamic")){const t=new r.XPathEvaluator;if(t.evaluate(a,n,null,r.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,r.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 Ft=(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 r=[];function o(e,t={}){const n=e?.value,o=t.value??e?.value,l={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;l.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(l.name,n,o),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),r.push(e))}(l)}function l(e,t,n){if(It(t))return _t(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+le(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=le(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=Wt(e,ae(n));return a&&o(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 r=l(a,t,n);if(r)return r}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)o(e);const u=String(n.value||n.type||"");if(u.includes("dynamic")||u.match("dynamic")||u.includes("{")||u.includes("}")){o(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=l(t,n,a),c||(c=s(t,n,a)),c||(c=zt(t.body,a)),!c){console.error("Element not found at:",a);break}}const f=(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=>It(e)&&e.value);for(const e of n)Xt(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of a)Lt(e.value,t,c)&&o(e,{isSelfHealed:null});const l=r.filter(e=>"xpath"===e.name&&e.value),s=new Set(l.map(e=>oe(e.value))),u=[],m=Mt(c);if(m&&!f("id",m)&&!g(m)){const n=e.locators.find(e=>"id"===e.name);se(t,"id",m,c)&&(u.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:m}))}const d=c.tagName;if(d&&!f("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);se(t,"tagName",d,c)&&(u.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const h=Yt(c);if(h&&!g(h)){const n=e.locators.find(e=>"linkText"===e.name);se(t,"linkText",h,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:h}))}const p=Vt(c);if(p&&!f("name",p)&&!g(p)){const n=e.locators.find(e=>"name"===e.name);se(t,"name",p,c)&&(u.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=jt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!g($)){const n=e.locators.find(e=>"className"===e.name);se(t,"className",$,c)&&(u.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}At(c,"single").forEach(e=>{e.value&&!f("cssSelector",e.value)&&o(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=Ue(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Xt(e.value,t,c));let a=0;for(const t of e){if(a>=e.length)break;const n=oe(t.value);if(s.has(n))continue;const r=v.find(e=>e.value&&oe(e.value)===n);r?.value&&(o(t,{name:"xpath",value:r.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=oe(t.value);s.has(n)||(o(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 qt)if(a.value.includes(e)){const r=Ut(a.value,e,t);if(r){o(a,{name:"xpath",value:r,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(r.length<5){const e=[{name:"id",value:Mt(c)},{name:"name",value:Vt(c)},{name:"className",value:jt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Yt(c)}];for(const n of e){if(r.length>4)break;const{name:e,value:a}=n;a&&(g(a)||f(e,a)||"className"===e&&a.includes(" ")||se(t,e,a,c)&&o(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}r.length<5&&At(c,"multiple").forEach(e=>{r.length>4||e.value&&(f("cssSelector",e.value)||se(t,"cssSelector",e.value,c)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=r.map(e=>({...e,value:i(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};const Ht={getOptimalClassChain:function e(t,n,a){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const r=n.tagName,o=["name","label","value"];for(const e of o){const o=a.find(t=>t.name===e);if(!o)continue;let l=o.value;if(!l)continue;if(l=l.trim().replace(/\s+/g," "),g(l))continue;const s=`//${r}[@${e}="${l}"]`;let i=0;try{i=y(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(l);if(1===i)return c?`/${r}[\`${e} CONTAINS "${l}"\`]`:`/${r}[\`${e} == "${l}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===r).indexOf(n)+1;return c?`/${r}[\`${e} CONTAINS "${l}"\`][${t}]`:`/${r}[\`${e} == "${l}"\`][${t}]`}}let l=`/${r}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===r);if(e.length>1){l+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,a)+l}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=[],r=[];for(let o of n){const n=o.value,l=o.name;if(0!==n.length&&(n&&!g(n))){a.push(`@${l}="${n}"`);const o=`//*[${a.join(" and ")}]`;let s;r.push(`${l} == "${n}"`);try{s=y(o,t,e)}catch(e){console.log(e);continue}if(1===s)return r.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}},Gt=()=>({xpath:Fe,referenceXpaths:wt,xpathUtils:ie,getElementsFromHTML:Ft,cssSelectors:Pt,iosSelectors:Ht});export{Gt as createXPathAPI,Gt as default};
2
- //# sourceMappingURL=index.browser.js.map
1
+ const e=/^[\S]+( [\S]+)*$/i;let t=new WeakMap;const n=new Set,a=e=>{if(!e)return t=new WeakMap,l=new WeakMap,s=new WeakMap,void n.forEach(e=>e(null));(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const a=e.getRootNode?.();return 9!==a?.nodeType&&11!==a?.nodeType||n(a),n(9===e.nodeType?e:e.ownerDocument),t})(e).forEach(e=>{t.delete(e)}),l=new WeakMap,s=new WeakMap,n.forEach(t=>t(e))},r=e=>(n.add(e),()=>n.delete(e)),o=(e,n)=>{const{owner:a,contextNode:r}=(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 o=t.get(r);o||(o=new Map,t.set(r,o));const l=o.get(e);if(l)return l;const s=a.evaluate(e,r,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let l=new WeakMap,s=new WeakMap;const i=(e,t,n,a)=>{return[9===e.nodeType?"document":"root",t?"index":"no-index",n?"target":"reference",(r=a,Array.from(r||[]).map(e=>`${e.name}=${e.value}`).join("|"))].join("::");var r};let c=[];const u=new WeakMap,f=new WeakMap;let m;const d=new Set(["flntooltip","flntooltip-bottom","fln-shield"]),g=new Set(["marked-element-temp","marked-element","mark-successfully","removePointers",...d]),h=/^(?:(?:ng|ion)-(?:pristine|dirty|valid|invalid|touched|untouched|pending|submitted|focused)|(?:item-)?has-(?:focus|value)|ng-star-inserted|hydrated|md|ios)$/,p=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!g.has(e)).sort(),$=e=>/\d/.test(e||""),y=e=>h.test(e),v=(e,t,n,a=!1)=>{const r=p(t),o=N(e,t,a);return o.length?1===r.length&&1===o.length?[`@class=${O(o[0])}`]:o.map(t=>{const a=S(`contains(@class,${O(t)})`,V(e),e.tagName.toLowerCase());return{token:t,count:ae(a,e,n)}}).sort((e,t)=>e.token.length!==t.token.length?e.token.length-t.token.length:e.count-t.count).map(({token:e})=>`contains(@class,${O(e)})`):[]},N=(e,t,n=!1)=>{const a=f.get(e);return p(t).filter(e=>!(a?.has(e)||y(e)||!n&&$(e)))},b=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),x=(e,t)=>t?"class"===e||"className"===e?p(t).join(" "):t.replace("removePointers","").trim():"",E=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(V(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=p(e.oldValue),n=p(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},w=e=>(e||"").split(/\s+/).some(e=>d.has(e)),k=e=>/\d/.test(e),S=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,A=e=>{const t=e?.textContent;return t},C=e=>e?.childNodes[0]?.nodeValue||"",R=(e,t,n,a=!1)=>{try{if(M(n)){const{owner:r,contextNode:o,cloneElement:l,cloneElements:s}=j(n,t),i=r.evaluate(e,o,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),c=i.iterateNext(),u=i.iterateNext();if(!c)return 0;if(!u)return c===l?1:0;if(a&&Array.isArray(t)){let e,t=0;if(s.includes(c)&&t++,s.includes(u)&&t++,2===t)return 2;for(;e=i.iterateNext();)if(s.includes(e)&&(t++,2===t))return 2;return 0}return 2}const{first:r,second:l}=o(e,n);if(!r)return 0;if(!l)return r===t?1:0;if(a&&Array.isArray(t)){let a=0;if(t.includes(r)&&a++,t.includes(l)&&a++,2===a)return 2;const o=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=o.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}},O=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},T=e=>{const t=e.split("");let n=t.length;const a=[];for(;"["!==t[n-2];)a.push(t[n-2]),n--;a.reverse();let r="";for(let e=0;e<a.length;e++)r+=a[e];const o=r.length+2;let l=e.slice(0,e.length-o);return l=l.startsWith("(")&&l.endsWith(")")?l.slice(1,-1):e,l},D=(e,t,n,a)=>{try{const r=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===R(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===R(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const l=r.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=l.iterateNext();)if(o++,s.isSameNode(t))return 1===R(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===R(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},P=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(),X=e=>e?e.replace(/\s\s+/g," ").trim():e,L=(e,t)=>{const n=X((t||"").trim());if(!e.children.length||n.length<=50)return"";const a=n.split(/\s+/).slice(0,3).join(" ");return a.length>2?`contains(normalize-space(.),${O(a)})`:""},_=e=>{const t=X((e||"").trim());if(!t||!$(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),a=n.split(/[^a-zA-Z]+/).map(e=>X(e).trim()).filter(e=>e.length>2&&/[a-zA-Z]/.test(e)).join(" ").trim();return{prefix:n.length>2&&/[a-zA-Z]/.test(n)?n:"",fragment:a.length>2?a:""}},z=e=>_(e).fragment,I=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},M=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,j=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),a=n.createElement("div");a.innerHTML=e.innerHTML,n.body.appendChild(a);const r=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},o=Array.isArray(t)?t.map(e=>r(e)).filter(Boolean):[],l=Array.isArray(t)?null:r(t??null);return{owner:n,contextNode:a,cloneElement:l,cloneElements:o}},W=(e,t,n)=>{const a=x(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;if("class"===e.name||"className"===e.name){const n=f.get(t);return p(e.value).filter(e=>!n?.has(e)&&!y(e)&&!$(e)).length>0}const r=c?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!r&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(o=e.name,l=a,(!b.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(l))&&("class"===e.name||!$(a)))));var o,l},Y=(e,t,n)=>{const a=((e,t)=>[t?"target":"reference",e.name,String(e.value)].join("::"))(e,n);let r=s.get(t);if(r){if(r.has(a))return r.get(a)}else r=new Map,s.set(t,r);const o=W(e,t);return r.set(a,o),o},V=e=>e instanceof SVGElement,q=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,U=(t,n,a,r,o,l)=>{if(r){const{tagName:s}=t;let i,c="";const u=[];let f;const m=a.startsWith("@"),d="."===a||"text()"===a,g=d?".":a,h=d&&/\s/.test(r.trim()),p=d?z(r):r,y=d&&$(r)?p:r,N=d?L(t,y):"";if("@class"===a){for(const e of v(t,r,n))if(f=S(e,V(t),t.tagName.toLowerCase()),i=R(f,t,n),1===i&&!o)return f;return}if(d&&$(r)&&!p)return;if(r&&(!m||!k(r))&&(f=N?S(N,V(t),t.tagName.toLowerCase()):h?S(`normalize-space(${g})=${O(X(y)).trim()}`,V(t),t.tagName.toLowerCase()):e.test(r)?`//${s}[${a}=${O(y)}]`:S(`normalize-space(${a})=${O(X(y)).trim()}`,V(t),t.tagName.toLowerCase()),i=R(f,t,n),1===i&&!o))return f;if(m&&$(r))return;if(r&&l){const l=r.split(" ");if(l?.length)if(1===l.length){const u=[...new Set(l[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&X(u[0].trim())?.length>1&&r.startsWith(u[0])&&(c=e.test(u[0])?`starts-with(${a},${O(u[0]).trim()})`:`starts-with(${a},${O(X(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&X(u[u.length-1].trim())?.length>1&&r.endsWith(u[u.length-1])&&(c=e.test(u[u.length-1])?`ends-with(${a},${O(u[u.length-1]).trim()})`:`ends-with(${a},${O(X(u[u.length-1])).trim()})`),c?.length&&(f=V(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=R(f,t,n),1===i&&!o))return f}else{const u=l.length%2==0?l.length/2:l.length%2,m=l.slice(0,u).join(" ");let d=[...new Set(m.match(/([^0-9]+)/g))];if(d?.length&&d[0]&&X(d[0].trim())?.length&&r.startsWith(d[0])&&(c=e.test(d[0])?`starts-with(${a},${O(d[0]).trim()})`:`starts-with(${a},${O(X(d[0])).trim()})`),c?.length&&(f=V(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=R(f,t,n),1===i&&!o))return f;const g=l.slice(u,l.length-1).join(" ");if(d=[...new Set(g.match(/([^0-9]+)/g))],d?.length&&d[0]&&X(d[0].trim())?.length>3&&r.endsWith(d[0])&&(c=e.test(d[0])?`ends-with(${a},${O(d[0]).trim()})`:`ends-with(${a},${O(X(d[0])).trim()})`),c?.length&&(f=V(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=R(f,t,n),1===i&&!o))return f}}if(r&&l&&k(r)){const l=[...new Set(r.match(/([^0-9]+)/g))];if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&X(l[t].trim())?.length>1&&(e.test(l[t])?u.push(`contains(${a},${O(l[t].trim()).trim()})`):u.push(`contains(${a},${O(X(l[t])).trim()})`));if(u?.length&&(f=V(t)?`//*[local-name()='${s}' and ${u.join(" and ")}]`:`//${s}[${u.join(" and ")}]`,i=R(f,t,n),1===i&&!o))return f}if(f=V(t)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=R(f,t,n),1===i&&!o)return f}},F=(e,t)=>{try{if(!e)return"";let n=V(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 F(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},H=(e,t,n,a=!1,r)=>{try{const o=i(t,n,a,r??e.attributes);let s=l.get(e);if(s){if(s.has(o))return s.get(o)}else s=new Map,l.set(e,s);const c=[];let u=e;for(;u;){let o="",l=!1,s=e===u?r??u.attributes:u.attributes;for(const e of Array.from(s))if(Y(e,u,a)){const a=x(e.name,e.nodeValue),r=e.name;for(const e of me(u,r,a)){o=e;let a=0;if(a=R(o,u,t),1===a){c.unshift(q(o)),l=!0;break}if(a>1&&n&&(o=D(o,u,t,a),o)){c.unshift(q(o)),l=!0;break}}}if(u.textContent)if(!a||a&&!k(u.textContent)){let e=new RegExp(/^[\S]+( [\S]+)*$/gi);const a=C(u),r=L(u,a);o=r?S(r,V(u),u.tagName||"*"):e.test(u.textContent)?V(u)?`//*[local-name()='${u.tagName}' and .=${O(a)}]`:`//${u.tagName||"*"}[.=${O(a)}]`:V(u)?`//*[local-name()='${u.tagName}' and normalize-space(.)=${O(a)}]`:`//${u.tagName||"*"}[normalize-space(.)=${O(a)}]`;let l=R(o,u,t);if(1===l)return o;if(l>1&&n)return o=D(o,u,t,l),o||""}else{let e=[];const a=[...new Set(C(u).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&X(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${O(a[t].trim()).trim()})`):e.push(`contains(.,${O(X(a[t])).trim()})`));if(e?.length){o=V(u)?`//*[local-name()='${u.tagName}' and ${e.join(" and ")}]`:`//${u.tagName||"*"}[${e.join(" and ")}]`;let a=R(o,u,t);if(1===a)return o;if(a>1&&n)return o=D(o,u,t,a),o||""}}if(l)break;{let e=V(u)?`/*[local-name()='${u.tagName}']`:`/${u.tagName}`;if(u.parentElement){const t=Array.from(u.parentElement.children).filter(e=>e.tagName===u.tagName);if(t.length>1){e+=`[${t.indexOf(u)+1}]`}}c.unshift(e)}u=u.parentElement}const f=`${c.join("")}`;return s.set(o,f),f}catch(o){console.log(o);const s=i(t,n,a,r??e.attributes);let c=l.get(e);return c||(c=new Map,l.set(e,c)),c.set(s,""),""}},G=(t,n)=>{const a=[];let r="";if(t&&"function"!=typeof t.nodeValue){if("class"===t.name){const e=n.getRootNode?.()??n.ownerDocument,a=v(n,t.value,e);for(const e of a)if(r=V(n)?`//*[local-name()='${n.tagName}' and ${e}]`:`//${n.tagName}[${e}]`,r)return r;return}if(k(t.value))return;const o=[...new Set(t.value.match(/([^0-9]+)/g))];if(o?.length)for(let n=0;n<o?.length;n++)o[n]&&X(o[n].trim())?.length>2&&(e.test(o[n])?a.push(`contains(@${t.name},${O(o[n].trim())})`):a.push(`contains(@${t.name},${O(X(o[n])).trim()})`));if(a?.length)return r=V(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,r}},B=(t,n,a,r)=>{try{const o=a.filter(e=>Y(e,t,r)),l=a=>{const r=x(a.name,a.nodeValue);return r?"class"===a.name?v(t,r,n):$(r)?[]:e.test(r)?[`@${a.name}="${r}"`]:[`normalize-space(@${a.name})="${r}"`]:[]},s=e=>{const t=l(e);return"class"===e.name?t.map(e=>[e]):t.length?[t]:[]},i=e=>e.reduce((e,t)=>{const n=s(t);return n.length?e.flatMap(e=>n.map(t=>[...e,...t])):[]},[[]]),c=()=>{const n=X(A(t)?.trim()||""),a=z(n);if($(n))return a?[`contains(normalize-space(.),${O(a)})`]:[];if(!n||n.length>80||/^\d+$/.test(n)){const e=L(t,n);return e?[e]:[]}const r=new Set,o=L(t,n);return o?(r.add(o),Array.from(r)):(e.test(n)&&n.length<=40&&!n.includes(" ")&&r.add(`text()=${O(n)}`),n.includes(" ")&&r.add(`normalize-space(.)=${O(X(n))}`),r.add(`contains(text(),${O(n)})`),Array.from(r))},u=(e,t)=>{const n=[],a=(r,o)=>{if(o.length!==t)for(let t=r;t<e.length;t++)o.push(e[t]),a(t+1,o),o.pop();else n.push([...o])};return a(0,[]),n},f=e=>V(t)?`//*[local-name()='${t.tagName}' and ${e.join(" and ")}]`:`//${t.tagName}[${e.join(" and ")}]`,m=()=>{if(!(o.length<2))for(let e=2;e<=o.length;e++){const a=u(o,e);for(const e of a){const a=i(e);for(const e of a){if(e.length<2)continue;const a=f(e);let r;try{r=R(a,t,n)}catch{continue}if(1===r)return a}}}},d=m();if(d)return d;const g=c();if(!g.length||!o.length)return;for(let e=1;e<=o.length;e++){const a=u(o,e);for(const e of a){const a=i(e);for(const e of a)if(e.length)for(const a of g){const r=[...e,a],o=f(r);try{if(1===R(o,t,n))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},Z=(e,t,n)=>J(e,t,n)[0]||"",J=(t,n,a)=>{let r=V(t),o="";if(Y(n,t,a)){let a=x(n.name,n.value);const l=n.name;if("class"===l){const e=t.getRootNode?.()??t.ownerDocument;return v(t,a,e).map(e=>r?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName||"*"}[${e}]`)}if($(a))return[];o=e.test(a)?r?`*[local-name()='${t.tagName}' and @${l}=${O(a)}]`:`${t.tagName||"*"}[@${l}=${O(a)}]`:r?`*[local-name()='${t.tagName}' and normalize-space(@${l})=${O(a)}]`:`${t.tagName||"*"}[normalize-space(@${l})=${O(a)}]`}return o?[o]:[]},K=(t,n)=>{if(!t.textContent)return"";const a=C(t),r=z(a);if($(a)&&!r)return"";const o=$(a)?r:a,l=L(t,o);let s;return s=l?S(l,V(t),t.tagName||"*"):$(a)?S(`contains(normalize-space(.),${O(o)})`,V(t),t.tagName||"*"):!e.test(a)||/\s/.test(a.trim())?S(`normalize-space(.)=${O(o)}`,V(t),t.tagName||"*"):V(t)?`//*[local-name()='${t.tagName}' and .=${O(o)}]`:`//${t.tagName||"*"}[.=${O(o)}]`,s},Q=(e,t,n)=>{if("@class"===t){const t=N(e,n);return 1===p(n).length&&1===t.length?S(`normalize-space(@class)=${O(t[0])}`,V(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&$(n))return"";if(("."===t||"text()"===t)&&$(n)){const{fragment:t}=_(n);return t?S(`contains(normalize-space(.),${O(t)})`,V(e),e.tagName.toLowerCase()):""}return S(`normalize-space(${t})=${O(X(n)).trim()}`,V(e),e.tagName.toLowerCase())},ee=(e,t,n)=>{if("@class"===t){const t=N(e,n);return 1===t.length?S(`starts-with(normalize-space(@class),${O(t[0])})`,V(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&$(n))return"";if(("."===t||"text()"===t)&&$(n)){const{prefix:t,fragment:a}=_(n),r=t||a;return r?S(`starts-with(normalize-space(.),${O(r)})`,V(e),e.tagName.toLowerCase()):""}return S(`starts-with(${t},${O(X(n)).trim()})`,V(e),e.tagName.toLowerCase())},te=(e,t,n)=>{if("@class"===t){const t=N(e,n);return 1===t.length?S(`contains(@class,${O(t[0])})`,V(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&$(n))return"";if(("."===t||"text()"===t)&&$(n)){const{fragment:t}=_(n);return t?S(`contains(normalize-space(.),${O(t)})`,V(e),e.tagName.toLowerCase()):""}return S(`contains(${t},${O(X(n)).trim()})`,V(e),e.tagName.toLowerCase())},ne=(t,n)=>{const a=n.flatMap(n=>(n=>{const a=x(n.name,n.value);if(!a)return[];if("class"===n.name){const e=t.getRootNode?.()??t.ownerDocument;return v(t,a,e)}return $(a)?[]:e.test(a)?[`@${n.name}=${O(a)}`]:[`normalize-space(@${n.name})=${O(a)}`]})(n)).filter(Boolean);if(a.length>=2)return S(`${a[0]} or ${a[1]}`,V(t),t.tagName.toLowerCase());const r=(()=>{const n=X(A(t)?.trim()||""),a=z(n);if($(n))return a?`contains(normalize-space(.),${O(a)})`:null;const r=L(t,n);return r||(!n||n.length>80||/^\d+$/.test(n)?null:e.test(n)&&n.length<=40&&!n.includes(" ")?`text()=${O(n)}`:n.includes(" ")?`normalize-space(.)=${O(n)}`:`contains(text(),${O(n)})`)})();return 1===a.length&&r?S(`${a[0]} or ${r}`,V(t),t.tagName.toLowerCase()):""},ae=(e,t,n)=>{try{return R(e,t,n)}catch(e){return 0}},re=(e,t)=>{const n=[],a=new Set,r=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"],l=[...o.map(e=>r.find(t=>t.name===e)).filter(Boolean),...r.filter(e=>!o.includes(e.name))],s=r=>{r&&!a.has(r)&&ie(r,e,t)&&(a.add(r),n.push(r))};l.forEach(t=>{if(Y(t,e,!1))for(const n of me(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=K(e);t&&s(t)}if(r.length>1){const n=B(e,t,r,!1);n&&s(n)}return n},oe=(e,t)=>{const n=[];let a=t;for(;a&&a!==e;)n.unshift(ce(a)),a=a.parentElement;return a===e?n.join("/"):""},le=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),a=ce(e),r=V(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const r=re(t,n);for(const o of r){const r=`${o}/descendant::${a}`;if(1===ae(r,e,n)&&se(r,n)===e)return r;const l=oe(t,e);if(l){const t=`${o}/${l}`;if(1===ae(t,e,n)&&se(t,n)===e)return t}}}return 1===ae(r,e,n)&&se(r,n)===e?r:""},se=(e,t)=>{try{if(M(t)){const{owner:n,contextNode:a,cloneElement:r}=j(t);return n.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||r}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},ie=(e,t,n)=>{try{const{first:a,second:r}=o(e,n);return!!a&&!r&&a===t}catch{return!1}},ce=e=>V(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),ue=(e,t,n)=>{if(!(e instanceof Element))return[];const a=new Set,r=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(a=t.value,!/\d/.test(a))&&Y(t,e,n);var a}),l=(e,t)=>{t&&!a.has(t)&&(a.add(t),r.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"];s.forEach(n=>{const a=o.find(e=>e.name===n);if(a)for(const n of me(e,a.name,a.value))n&&ie(n,e,t)&&l(`anchor by ${a.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const a of me(e,n.name,n.value))a&&ie(a,e,t)&&l(`anchor by ${n.name}`,a)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=K(e);n&&ie(n,e,t)&&l("anchor by text",n)}if(o.length>1){const a=B(e,t,o,n);a&&ie(a,e,t)&&l("anchor by combination",a)}return r},fe=e=>{const t=A(e)?.trim(),n=z(t);if(t&&$(t))return n?`contains(normalize-space(.),${O(n)})`:void 0;const a=L(e,t);if(a)return a;const r=t?O(P(t)):t;return r?r!==`'${t}'`?`contains(.,${r})`:/\s/.test(t)?`normalize-space(.)='${X(t)}'`:`normalize-space(.)='${t}'`:void 0},me=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let r="";if(n=x(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return v(e,n,t).map(t=>V(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if($(n))return[];r=a.test(n)?V(e)?`//*[local-name()='${e.tagName}' and @${t}=${O(n)}]`:`//${e.tagName||"*"}[@${t}=${O(n)}]`:V(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${O(n)})]`:`//${e.tagName||"*"}[contains(@${t},${O(n)})]`}return r?[r]:[]},de=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,ge=(t,n,a)=>{let r;const o=[];if(t.textContent&&a&&k(t.textContent)){const{prefix:e,fragment:n}=_(A(t)),a=[e?`starts-with(normalize-space(.),${O(e)})`:"",n?`contains(normalize-space(.),${O(n)})`:""].filter((e,t,n)=>e&&n.indexOf(e)===t);for(const e of a)r=V(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r})}if(t.textContent&&(!a||a&&!k(t.textContent)))if(e.test(t.textContent)){const e=A(t),n=L(t,e),a=n||(/\s/.test(e.trim())?`normalize-space(.)=${O(X(e))}`:`.=${O(e)}`);r=V(t)?`*[local-name()='${t.tagName}' and ${a}]`:`${t.tagName}[${a}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}else{const e=fe(t);e&&(r=V(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r}))}if(t.attributes){const e="IMG"===t.tagName?Array.from(t.attributes).sort((e,t)=>"alt"===e.name?-1:"alt"===t.name?1:0):Array.from(t.attributes);for(const l of e)if(Y(l,t,a)){let e=l.nodeValue;if(e){e=x(l.name,e);const a=l.name;if("class"!==a&&$(e))continue;if("class"===a){const a=v(t,e,n);if(!a.length)continue;for(const e of a)r=V(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r});continue}r=V(t)?`*[local-name()='${t.tagName}' and @${a}=${O(e)}]`:`${t.tagName}[@${a}=${O(e)}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}}}if(!o?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=B(t,n,Array.prototype.slice.call(t.attributes),a);e&&o.push({key:"getReferenceElementsXpath",value:e})}}if(!o?.length){const e=[];let n;const r=t.tagName;if(t.textContent&&a&&k(t.textContent)){const a=X(A(t)).trim();a?.length>1&&e.push(`contains(text(),${O(a)})`),e?.length&&(n=V(t)?`*[local-name()='${r}' and ${e.join(" and ")}]`:`${r}[${e.join(" and ")}]`,n&&o.push({key:"getReferenceElementsXpath",value:n}))}}if(!o?.length){const e=((e,t,n,a)=>{const r=Array.prototype.slice.call(e),o=[];try{r.map(e=>{if(Y(e,t,a)){const n=G(e,t);n&&o.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return o})(t.attributes,t,0,a);e?.length&&o.concat(e)}return o},he=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"),pe=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function $e(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",r=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:r?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function ye(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function ve(e,t,n,a){const r=a?.getRootNode?.()??e,o=e=>{try{return Array.from(r.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===o(`#${ye(n)}`).length;case"name":return 1===o(`[name="${ye(n)}"]`).length;case"className":return 1===o(`.${n}`).length;case"tagName":case"cssSelector":return 1===o(n).length;case"linkText":return 1===o("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===o("a").filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const Ne={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:ge,getAbsoluteXPath:F,getRelativeXPath:H,getCombinationXpath:G,getAttributeCombinationXpath:B,getElementFromXpath:(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const r=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?r.evaluate(e,a,null,XPathResult.ANY_TYPE,null):r.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},isSvg:V,findXpathWithIndex:D,isNumberExist:k,getTextContent:A,getCountOfXPath:R,clearXPathEvalCache:a,registerXPathCacheInvalidation:r,normalizeXPath:he,getShadowRoot:I,escapeCharacters:O,removeParenthesis:T,checkBlockedAttributes:Y,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:pe,deleteGarbageFromInnerText:P,replaceTempAttributes:q,createObserver:e=>{m=new MutationObserver(t=>{t.forEach(t=>{if(("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!E(t))&&a(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement)if(E(t)||(e=>"attributes"===e.type&&e.target instanceof Element&&(w(e.oldValue)||w(e.target.getAttribute("class"))||e.target.hasAttribute("locator-data-tooltip")))(t));else if("attributes"===t?.type&&"class"===t.attributeName)(e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return;const t=new Set(p(e.oldValue)),n=p(e.target.getAttribute("class")).filter(e=>!t.has(e));if(!n.length)return;let a=f.get(e.target);a||(a=new Set,f.set(e.target,a));const r=n.filter(e=>!a?.has(e));r.length&&r.forEach(e=>a?.add(e))})(t);else if("attributes"===t?.type&&!["flndisabled"].includes(t.attributeName)){const e={url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument};let n=u.get(t.target);n||(n=new Set,u.set(t.target,n)),n.has(t.attributeName)||(n.add(t.attributeName),c.push(e))}})})},startObserver:(e,t)=>{m?.observe(e,t)},stopObserver:()=>{m?.disconnect()},modifiedElementAttributes:c,cspEnabled:!1,getXPathPattern:$e,getNormalizedPropertyXPath:Q,getStartsWithPropertyXPath:ee,getContainsPropertyXPath:te,getOrAttributesXPath:ne,getTagOnlyXPath:le,getFirstMatchedNode:se,isExactUniqueXpath:ie,getAxisNodeTest:ce,getUniqueNodeAnchorXpaths:ue,escapeAttrValue:ye,isUniqueInDOM:ve,sanitizeAttributeValue:x,getClassTokenCondition:(e,t,n,a=!1)=>v(e,t,n,a)[0]||null,getClassTokenConditions:v,getXpathStrings:me,intermediateXpathSteps:J,getContainerTextCondition:L};let be=[],xe=[],Ee=new WeakMap,we=new WeakMap;const ke=e=>e?[e.tagName,Array.from(e.attributes||[]).map(e=>`${e.name}=${e.value}`).join("|"),e.textContent||""].join("::"):"";r(()=>{Ee=new WeakMap,we=new WeakMap,xe=[]});const Se={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},Ae=e=>Se[e]||e,Ce=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),Re=e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value))&&(t.add(e.value),!0))},Oe=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const a=e[n];if(t){a===t&&(t=null);continue}if("'"===a||'"'===a){t=a;continue}if("["!==a)continue;const r=e.indexOf("]",n+1);if(-1===r)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,r)))return!0}return!1})(e.value)),Te=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",De=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},Pe=(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},Xe=(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:()=>De(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},Le=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},_e=e=>{let t=0;e.id&&(t+=100),e.getAttribute("data-testid")&&(t+=90),e.className&&(t+=50),0===e.children.length&&(t+=30);const n=e.textContent?.trim();return n&&n.length<40&&(t+=40),t},ze=(e,t,n,a,r,o,l)=>{const s=fe(n),i=s?`${ce(n)}[${s}]`:ce(n),c=[];let u=0;const f=t.includes("descendant")?10:20;for(const s of e){if(u++>f)break;if(c.length>=5)break;const e="node"in s?s.node:s;if(!(e instanceof Element))continue;if(Le(e))continue;const m=[()=>ue(e,a,r),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&Y(t,e,r));for(const a of n){const n=a.value;if(!n)continue;const r=te(e,`@${a.name}`,n);r&&t.push({key:"contains",value:r});const o=ee(e,`@${a.name}`,n);o&&t.push({key:"starts-with",value:o})}return t}];for(let r=0;r<m.length;r++){let s=m[r]();if(!s.length)continue;l||(s=s.filter(e=>!/\[\d+\]/.test(e.value)));const u=new Set;s=s.filter(e=>!u.has(e.value)&&(u.add(e.value),!0)),s=s.slice(0,5);for(const e of s){const r=`${e.value}/${t}::${i}`;if(ie(r,n,a)){if(c.push({key:o,value:r}),c.length>=2)return c;if(c.length>=5)return c}}if(l&&r===m.length-1)for(const r of s){const l=R(r.value,e,a);for(let e=1;e<=Math.min(l,3);e++){const l=`(${r.value})[${e}]/${t}::${i}`;if(ie(l,n,a)){if(c.push({key:o,value:l}),c.length>=2)return c;if(c.length>=5)return c}}}}if("expand"in s&&s.expand){const e=s.expand();let l=0;for(const s of e){if(l++>15)break;if(c.length>=5)break;if(!(s instanceof Element))continue;if(Le(s))continue;const e=ue(s,a,r);for(const r of e.slice(0,5)){const e=`${r.value}/${t}::${i}`;if(ie(e,n,a)){if(c.push({key:o,value:e}),c.length>=2)return c;if(c.length>=5)return c}}}}}return c},Ie=(e,t)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},Me=(e,t)=>{for(let n=e.nextElementSibling;n;n=n.nextElementSibling)if(n===t)return"following-sibling";for(let n=e.previousElementSibling;n;n=n.previousElementSibling)if(n===t)return"preceding-sibling";return""},je=(e,t)=>{const n=[];for(let a=e;a&&a!==t;a=a.parentElement){const e=a.parentElement;if(!e)return"";n.push(`/parent::${ce(e)}`)}return n.join("")},We=(e,t)=>{const n=ce(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Ye=(e,t,n)=>{const a=[],r=new Set,o=(e=>{const t=[],n=new Set,a=a=>{a&&a!==e&&!n.has(a)&&(a.contains(e)||e.contains(a)||(n.add(a),t.push(a)))};for(let n=e.parentElement,r=0;n&&r<4&&t.length<20;n=n.parentElement,r++){const e=[Pe(n,"previous").slice(0,4),Pe(n,"next").slice(0,4)];for(const t of e)for(const e of t){a(e);let t=0;for(const n of De(e).sort((e,t)=>_e(t)-_e(e))){if(t++>=8)break;a(n)}}}return t.sort((e,t)=>_e(t)-_e(e)).slice(0,20)})(e),l=Ie(e.parentElement,3);for(const s of o){const o=ue(s,t,n).slice(0,2);if(!o.length)continue;const i=Ie(s,3);for(const n of o)for(const o of i){const i=je(s,o);if(o===s||i)for(const s of l){if(!s||!s.contains(e))continue;const l=Me(o,s);if(!l)continue;const c=`/${l}::${ce(s)}`;for(const o of We(s,e)){const l=`${n.value}${i}${c}${o}`;if(!r.has(l)&&(r.add(l),ie(l,e,t)&&(a.push({key:"chained axes fallback",value:l}),a.length>=2)))return a}}}}return a},Ve=e=>{const t=ce(e),n=e.textContent?.trim(),a=(e=>{const t=z(e);return t||(e||"").split(/[^a-zA-Z]+/).map(e=>e.trim()).filter(e=>e.length>2).pop()})(n),r=fe(e),o=[];return a&&a!==n&&o.push(`${t}[contains(text(),${O(a)})]`),r&&o.push(`${t}[${r}]`),o.push(t),Array.from(new Set(o))},qe=(e,t,n)=>{const a=A(e)?.trim(),r=[];if(a&&a.length>2&&a.length<40&&!$(a)){const t=`//${e.tagName}[.=${O(a)}]`;r.push({key:"anchor by text",value:t})}return[...r,...ue(e,t,n)]},Ue=(e,t,n)=>{const a=[],r=new Set,o=(e=>{const t=[],n=new Set,a=a=>{a&&a!==e&&!n.has(a)&&(a.contains(e)||e.contains(a)||(n.add(a),t.push(a)))},r=e=>{for(const t of[e,...De(e)]){const e=A(t)?.trim();e&&e.length<40&&!$(e)&&0===t.children.length&&a(t)}};for(let n=e.parentElement,o=0;n&&o<4&&t.length<30;n=n.parentElement,o++){const e=Pe(n,"previous").reverse(),t=Pe(n,"next");for(const n of[...e,...t])r(n),a(n)}return t.slice(0,30)})(e),l=Ve(e);for(const s of o){const o=qe(s,t,n).slice(0,2);if(o.length)for(const n of o)for(const o of Ie(s.parentElement,5)){if(!o.contains(e))continue;const s=`/ancestor::${ce(o)}`;for(const o of l){const l=`${n.value}${s}/descendant::${o}`;if(!r.has(l)&&(r.add(l),ie(l,e,t)&&(a.push({key:"ancestor descendant bridge",value:l}),a.length>=1)))return a}}}return a},Fe=(e,t)=>{const n=[];for(let a=t;a&&a!==e;a=a.parentElement)n.unshift(ce(a));if(!n.length)return"";const a=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${a}`},He=(e,t,n,a)=>{const r=new Set,o=[],l=(e,t)=>{t&&!r.has(t)&&(!a&&/\[\d+\]/.test(t)||(r.add(t),o.push({key:e,value:t})))};return ue(e,t,n).forEach(e=>l(e.key,e.value)),Array.from(e.attributes||[]).forEach(t=>{if(!(e=>!(!e?.value||["style","locator-data-tooltip","value"].includes(e.name)||0===e.name.indexOf("on")&&e.name.length>3))(t)||!$(t.value)||"class"===t.name)return;const n=(e=>{const t=(e.split(/\d/)[0]||"").replace(/[-_:\s.]+$/g,"").trim();return t.length>2&&/[a-zA-Z]/.test(t)?t:""})(t.value);if(!n)return;const a=te(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,a)}),o},Ge=(e,t,n,a)=>{const r=[];for(let t=e.parentElement;t;t=t.parentElement)r.push(t);const o=De(e),l=Pe(e,"previous"),s=Pe(e,"next"),i=Xe(e,"previous"),c=Xe(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(l),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(r),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(r),axis:"descendant",key:"descendant"},{nodes:u(r),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(o,10),axis:"ancestor",key:"ancestor"},{nodes:u(o,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]],m=((e,t,n,a)=>{const r=[],o=new Set;for(let l=e.parentElement,s=0;l&&s<8;l=l.parentElement,s++){const s=Fe(l,e);if(!s)continue;const i=He(l,t,n,a);for(const n of i.slice(0,3)){const a=`${n.value}${s}`;if(!o.has(a)&&(o.add(a),ie(a,e,t)&&(r.push({key:"child chain",value:a}),r.length>=2)))return r}}return r})(e,t,n,a);if(m.length)return m;for(const r of f)for(const o of r){const r=ze(o.nodes,o.axis,e,t,n,o.key,a);if(r.length>0)return r}const d=Ue(e,t,n);return d.length?d:Ye(e,t,n)||[]},Be=(e,t,n,a,r)=>{const o=Ae(a);return"text"===o?Ce(a,((e,t,n)=>{if(!Te(e))return[];if("text"===n){const n=K(e)||ot(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?Ce(a,((e,t,n,a)=>{const r=[],o=Array.from(e.attributes||[]).filter(t=>t?.value&&Y(t,e,n)),l=Te(e),s="contains"===a?te:"startsWith"===a?ee:"normalizeSpace"===a?Q:null;if(!s)return r;if("contains"===a&&l)for(const n of["text()","."]){const r=s(e,n,l);if(r&&1===R(r,e,t))return[{key:`xpath by ${a} text`,value:r}]}if(o.forEach(n=>{if("class"===n.name)return void v(e,n.value,t).forEach(t=>{const n=S(t,V(e),e.tagName.toLowerCase());n&&r.push({key:`xpath by ${a} class`,value:n})});const o=s(e,`@${n.name}`,n.value);o&&r.push({key:`xpath by ${a} ${n.name}`,value:o})}),"contains"===a&&r.length){const n=r.find(n=>1===R(n.value,e,t));return n?[n]:[]}if(l){const t=s(e,".",l);t&&r.push({key:`xpath by ${a} text`,value:t})}return r})(e,t,n,o)):["and","or"].includes(o)?Ce(a,((e,t,n,a)=>{const r=Array.from(e.attributes||[]).filter(t=>t?.value&&Y(t,e,n));if("and"===a){const a=B(e,t,r,n);return a?[{key:"xpath by combination",value:a}]:[]}if("or"===a&&r.length>=1){const t=ne(e,r);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,n,o)):"axes"===o?Ce(a,Ge(e,t,n,!1)):"index"===o?Ce(a,((e,t)=>{const n=[],a=e.tagName.toLowerCase(),r=Array.from(t.querySelectorAll(a)).indexOf(e)+1;if(r<=0)return[];n.push({key:"xpath by index",value:`(//${a})[${r}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?me(o,"id",o.id):me(o,"class",o.className.toString());for(const r of t){const t=Array.from(o.querySelectorAll(a)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${r}//${a})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?Ce(a,[{key:"xpath till tag",value:le(e,t)}]):[]},Ze=(e,t,n,a,r,o)=>{if(e){let l;l="parent"===o?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of l){const t=R(e,n,a);if(1===t)return e;if(t>1&&(xe.length?t<xe[0].count&&(xe.pop(),xe.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})):xe.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})),t>1&&r&&!be.length){const o=D(e,n,a,t);o&&1===R(o,n,a)&&be.push({key:"relative xpath by unique parent "+(r?"index":""),value:o})}}}return null},Je=(t,n,a,r,o,l)=>{try{const s=[r?"target":"reference",l?"index":"no-index",o,ke(a)].join("::");let i=Ee.get(t);if(i){if(i.has(s))return i.get(s)}else i=new Map,Ee.set(t,i);const c=[];let u=t;for(;u&&1===u.nodeType;){const t=!1;for(const e of Array.from(u.attributes))if(Y(e,u,r)){const t=x(e.name,e.nodeValue),r=e.name;for(const e of me(u,r,t)){let t;try{t=Ze(e,o,a,n,l,"parent")}catch(e){continue}if(t)return t}}if(u.textContent&&!u.textContent)if(!r||r&&!k(u.textContent)){let t;t=e.test(u.textContent)?V(u)?`//*[local-name()='${u.tagName}' and .=${O(C(u))}]`:`//${u.tagName||"*"}[.=${O(C(u))}]`:V(u)?`//*[local-name()='${u.tagName}' and normalize-space(.)=${O(C(u))}]`:`//${u.tagName||"*"}[normalize-space(.)=${O(C(u))}]`;const r=Ze(t,o,a,n,l,"parent");if(r)return r}else{const e=[],t=[...new Set(C(u).match(/([^0-9]+)/g))],r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&X(t[n].trim())&&(r.test(t[n])?e.push(`contains(.,${O(t[n].trim()).trim()})`):e.push(`contains(.,${O(X(t[n])).trim()})`));if(e?.length){const t=V(u)?`//*[local-name()='${u.tagName}' and ${e.join(" and ")}]`:`//${u.tagName||"*"}[${e.join(" and ")}]`,r=Ze(t,o,a,n,l,"parent");if(r)return r}}if(!t){const e=V(u)?`/*[local-name()='${u.tagName}']`:`/${u.tagName}`;c.unshift(e)}u=u.parentElement}const f=c.join("")+o;if(1===R(f,t,n))return i.set(s,f),f;i.set(s,null)}catch(e){return console.error(e),null}},Ke=(e,t,n,a)=>{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(Y(n,o,a)){const a=x(n.name,n.nodeValue),l=n.name;for(const n of me(o,l,a)){let a;try{a=R(n,o,t)}catch(e){continue}if(1===a){r.unshift(n),e=!0;break}}}if(e)break}if(!e&&o.textContent&&!n.textContent){const n=K(o);if(n){if(1===R(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=V(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}return r.join("")}catch(e){return console.log(e),null}},Qe=(e,t,n)=>{const a=ke(n);let r=we.get(e);if(r){if(r.has(a))return r.get(a)}else r=new Map,we.set(e,r);const o=[];let l;const s=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?s.unshift(e.firstElementChild):null!=e.nextElementSibling&&s.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&s.unshift(t.nextElementSibling);try{do{let e=!1;for(l=s.pop();null!==l;){for(const n of Array.from(l.attributes)){if(Y(n,l,!0)){const a=x(n.name,n.nodeValue),r=n.name;for(const n of me(l,r,a)){let a;try{a=R(n,l,t)}catch(e){continue}if(1===a){e=!0,o.push(n);break}}}if(e)break}if(!e&&l.textContent&&!n.textContent){const n=K(l);if(n){if(1===R(n,l,t)){e=!0,o.push(n);break}}}if(e)break;{const e=V(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;o.push(e),null!=l.firstElementChild?(s.push(l.nextElementSibling),l=l.firstElementChild):l=l.nextElementSibling}}}while(s.length>0);const e=o.join("");return r.set(a,e),e}catch(e){return console.log(e),r.set(a,null),null}},et=(e,t,n,a)=>{try{const r=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==r;o=o.nextElementSibling)tt(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==r;o=o.previousElementSibling)tt(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},tt=(e,t,n,a,r,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){const l=J(e,{name:t.name,value:t.value},o);for(let t of l){t+=`/${r}::${a}`;const o=R(t,e,n);if(1===o)return void be.push({key:`xpath by ${r}`,value:t});o>1&&(xe.length?o<xe[0].count&&(xe.pop(),xe.push({key:`relative xpath by ${r}`,value:t,count:o})):xe.push({key:`relative xpath by ${r}`,value:t,count:o}))}}if(!o){let t;if(t=Z(e,{name:"text",value:e.textContent},o),t){const a=R(t,e,n);if(1===a)return void be.push({key:`xpath by ${r}`,value:t});a>1&&(xe.length?a<xe[0].count&&(xe.pop(),xe.push({key:`relative xpath by ${r}`,value:t,count:a})):xe.push({key:`relative xpath by ${r}`,value:t,count:a}))}}}catch(e){console.log(`${r} xpath-error`,e)}};function nt(e,t,n,a){const{tagName:r}=t,o=t.textContent.trim();if(!o)return;const l=X(o),s=z(l);if($(l)&&!s)return;const i=$(l)?s:l,c=L(t,i);for(const s of e)if(Y(s,t,a)){let e=x(s.name,s.nodeValue);const a=`//${r}[@${s.name}='${e}' and ${c||($(l)?`contains(normalize-space(.),${O(i)})`:/\s/.test(o)?`normalize-space(.)=${O(i)}`:`text()=${O(i)}`)}]`;if(a){if(1==R(a,t,n))return a}}}const at=(e,t,n,a,r)=>{let o;if(o=e.name,Y(e,t,r))return U(t,n,`@${o}`,e.value,a,r)},rt=(e,t,n,a)=>{let r=e.className;if("string"!=typeof r&&(r=""),r=r?.replace("flndisabled","disabled"),r=x("class",r),r=r?.trim(),r&&Y({name:"class",value:r},e,a))return U(e,t,"@class",r,n,a)},ot=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const r=A(e);if(r)return U(e,t,"text()",r,n,a)||U(e,t,".",r,n,a)}},lt=(e,t,n,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&Y(e,t,r)){const o=at(e,t,n,a,r);o&&be.push({key:`xpath by ${e.name}${a?" index":""}`,value:o})}});const l=ot(t,n,a,r);if(l&&be.push({key:"xpath by text"+(a?" index":""),value:l}),o.find(e=>["className","class"].includes(e.name))&&Y(o?.find(e=>["className","class"].includes(e.name)),t,r)){let e=rt(t,n,a,r);e&&be.push({key:"xpath by class",value:e})}if(!be.length&&o.length>1){const e=B(t,n,o,r);e&&be.push({key:"xpath by combination",value:e})}if(!be.length){const a=nt(e,t,n,r);a&&be.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},st=(e,t,n,r,o=[],l=[])=>{be=[],console.log(e);const s=e,i=s?.getRootNode?.(),c=i?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,u=c?i:s?.ownerDocument||t;a(u);const f=s.tagName,{attributes:m}=s,d=o.length>0?o:Array.from(m);if(lt(d,s,u,n,r),l.length){const e=n||((e=[])=>e.some(e=>"index"===Ae(e)))(l),t=l.flatMap(e=>Be(s,u,r,e));return be=Re(t.filter(e=>1===R(e.value,s,u))),Oe(be,e)}if(be.length){const t=be.length;for(let n=0;n<t;n++){let t=be[n].value;t="//*"+t.substring(t.indexOf("//")+2+f.length);1===R(t,e,u)&&be.push({key:`${be[n].key} regex`,value:t})}}return be.length||c||(be=Ge(s,u,r,n)),Oe(Re(be),n)},it={parseDOM:st,getTextXPath:ot,getUniqueClassName:rt,attributesBasedXPath:at,addAllXPathAttributes:lt,addRelativeXpaths:(e,t,n,r,o)=>{try{a(t);let l,s,i=[];if(be=[],o)for(const t of o){const n=J(e,{name:t.name,value:t.value},r);for(const e of n)e&&i.push(e)}if(e.textContent){let t=Z(e,{name:"text",value:e.textContent},r);t&&i.push(t)}if(i.push(e.tagName),i?.length)for(let a=0;a<i.length;a++)if(!be.length){if(et(e,t,r,i[a]),!be.length&&(l||(l=Ke(e.parentElement,t,e,r)),l&&(l.includes("@")||l.includes("text()")||l.includes(".="))&&(l.match(/\//g)?.length??0)-2<5)){const r=l+`/${i[a]}`,o=R(r,e,t);if(1===o)be.push({key:"relative xpath by relative parent",value:r});else if(o>1&&n){const a=D(r,e,t,o);a&&1===R(a,e,t)&&be.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!be.length&&(s||(s=Qe(e,t,e)),s&&(s.includes("@")||s.includes("text()")||s.includes(".=")))){const r=s.replace(/^\/+/,""),o=`/${i[a]}/${r}`,l=R(o,e,t);if(1===l)be.push({key:"relative xpath by relative child",value:o});else if(l>1&&n){const a=D(o,e,t,l);a&&1===R(a,e,t)&&be.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===be?.length&&be?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=ot(e,t,n,!1);a&&be.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!be.length){let o=Je(e.parentElement,t,e,r,i[a],n);o&&be.push({key:"xpath by unique parent",value:o})}}return be}catch(e){console.log(e)}},getXPathUsingAttributeAndText:nt,getSiblingRelativeXPath:et,getChildRelativeXpath:Qe,getParentRelativeXpath:Ke,getUniqueParentXpath:Je,checkRelativeXpathRelation:Ze,buildAxesStrategyXpaths:Ge};let ct=[],ut=[];const ft=/^[\S]+( [\S]+)*$/gi,mt=new WeakMap,dt=(e,t,n=!1)=>{let a=mt.get(e);if(!a&&n&&(a=new WeakMap,mt.set(e,a)),!a)return[];let r=a.get(t);return!r&&n&&(r=[],a.set(t,r)),r||[]},gt=(e,t)=>{dt(e,t,!0).length=0},ht=(e,t,n,a,r)=>{if(!a||r<=1)return;const o=dt(e,t,!0);o.some(e=>e.value===a)||(o.push({key:`dynamic ${n} index`,relation:n,value:a,count:r}),o.sort((e,t)=>e.count-t.count),o.length>25&&(o.length=25))},pt=(e,t,n)=>{try{const a=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let r,o=0;for(;r=a.iterateNext();)if(o++,r===t){const a=`(${e})[${o}]`;return 1===R(a,t,n)?a:""}}catch(e){console.log(e)}return""},$t=(e,t,n,a,r,o,l,s=0,i=!1)=>{let c="";const u=()=>{const t=e[e.length-1],r=z(A(t)?.trim());if(!r||r.length<=1)return"";const o=`//${(t=>{for(const n of e){const e=A(n)?.trim();if(!e)continue;const a=`normalize-space(.)=${O(X(e))}`,r=`${n.tagName}[${a}]`;if(!t.includes(r))continue;const o=Array.from(n.children||[]).find(t=>A(t)?.trim()===e);if(o)return t.replace(r,`${n.tagName}[${o.tagName}[${a}]]`)}return t})(l+(s?"]".repeat(s):""))}/${n}::${t.tagName.toLowerCase()}[contains(text(),${O(r)})]`,i=R(o,t,a),c=D(o,t,a,i);return c&&1===R(c,t,a)?c:""};if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=o.length){const c=[],f=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=o.length;e++)c.unshift(e===o.length?o[o.length-e]:f[f.length-e]);if(r){const e=u();if(e)return[{key:`dynamic ${n} ${r?" index":""}`,value:q(e)}]}const m=Yt(`${l+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,r,i);if(m)return m}else{c=`//${l+(s?"]".repeat(s):"")}/${n}::${de(t,e[e.length-1])}`;let o=R(c,e[e.length-1],a);if(1===o)return[{key:`dynamic ${n}`,value:q(c)}];if(o>1&&(r||ht(e[0],e[e.length-1],n,c,o),r)){const t=u();if(t)return[{key:`dynamic ${n} ${r?" index":""}`,value:q(t)}];if(c=D(c,e[e.length-1],a,o),c&&(o=R(c,e[e.length-1],a),1===o))return[{key:`dynamic ${n} ${r?" index":""}`,value:q(c)}]}}},yt=(e,t,n,a,r,o=!1,l=!1)=>{const s=e[e.length-2],i=e[e.length-1],c=I(i)??i.ownerDocument,u=n.find(e=>e?.key?.includes("absolute"))?.value||F(s,s.ownerDocument),f=[],m=[];u.split("/").map(e=>f.push(e)),f.map(e=>m.push(e.replace(/\[([0-9]+)\]/gm,"")));const d=a.find(e=>e?.key?.includes("absolute"))?.value||F(i,i.ownerDocument),g=[],h=[];d.split("/").map(e=>g.push(e)),g.map(e=>h.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var p=0;p<f.length&&f[p]==g[p];p++);const $=[];for(let e=p-1;e<f.length;e++)f[e]&&$.push(m[e]);const y=[];for(let e="descendant"===r?p:p-1;e<g.length;e++)g[e]&&(y.length?y.push(h[e]):y.push(h[e].replace(/\[([0-9]+)\]/gm,"")));let v;if(ut=(e=>{const t=e=>{const t=e.value||"",n=/(?:contains\s*\(\s*normalize-space\s*\(\s*\.\s*\)|normalize-space\s*\(\s*\.\s*\)|contains\s*\(\s*text\s*\(\s*\)|text\s*\(\s*\)|\.\s*=)/.test(t),a=/@/.test(t);return n&&!a?0:n?1:2};return[...e].sort((e,n)=>t(e)-t(n))})(a),e[e.length-2].textContent){if(ft.test(e[e.length-2].textContent)){const t=e[e.length-2],n=A(t),a=L(t,n),r=a||(/\s/.test(n.trim())?`normalize-space(.)=${O(X(n))}`:`.=${O(n)}`);v=V(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${r}]`:`${e[e.length-2].tagName}[${r}]`}else v=V(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${fe(e[e.length-2])})]`:`${e[e.length-2].tagName}[${fe(e[e.length-2])}]`;$[$.length-1]=v;const n=$.join("["),a=$.length-1,s=n;for(let n=0;n<ut.length;n++){let i;if(i=ut[n].value.startsWith("//")?ut[n].value.substring(ut[n].value.indexOf("//")+2):ut[n].value,i){const n=$t(e,i,r,c||t,o,y,s,a,l);if(n?.length)return n}}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(Y(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=x(n.name,a);const s=n.name;v=V(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${O(a)}]`:`${e[e.length-2].tagName}[@${s}=${O(a)}]`,$[$.length-1]=v;const i=$.join("["),u=$.length-1,f=i;for(let n=0;n<ut.length;n++){let a;a=ut[n].value.startsWith("//")?ut[n].value.substring(ut[n].value.indexOf("//")+2):ut[n].value;const s=$t(e,a,r,c||t,o,y,f,u,l);if(s?.length)return s}}}for(const n of Array.from(e[e.length-2].attributes))if(Y(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=x(n.name,a);const s=G(n,e[e.length-2]);if(s){v=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,$[$.length-1]=v;const n=$.join("["),a=$.length-1,i=n;for(let n=0;n<ut.length;n++){let s;s=ut[n].value.startsWith("//")?ut[n].value.substring(ut[n].value.indexOf("//")+2):ut[n].value;const u=$t(e,s,r,c||t,o,y,i,a,l);if(u?.length)return u}}}}}const N=$.join("["),b=$.length-1,E=Yt(`${N+(b?"]".repeat(b):"")}`,y,e[e.length-1],e,t,r,o,l);if(E)return E},vt=(e,t,n,a,r,o,l)=>{let s,i;const c=[];try{s=a.filter(e=>!e?.key?.includes("absolute")),i=r.filter(e=>!e?.key?.includes("absolute"));for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const l=0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2),u=At(s[a].value,e);let f=`//${u}/${n}::${de(l)}`;const m=R(f,t,t.ownerDocument);if(m>1){const a=Xt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=Pt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:q(r)}),c;const l=Lt(u,n,t,i,t.ownerDocument);if(l)return c.push({key:`dynamic ${n}`,value:q(l)}),c;if(o){if(f=D(f,t,t.ownerDocument,m),f)return c.push({key:`dynamic ${n}${o?" index":""}`,value:q(f)}),c}else m>1&&(ht(e,t,n,f,m),ct.length?m<ct[0].count&&(ct.pop(),ct.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m})):ct.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m}))}else if(1===m){if(St(l)){const a=Xt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=Pt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:q(r)}),c}return c.push({key:`dynamic ${n}`,value:q(f)}),c}}if(!c.length){const a=Xt(e,t,n,s,i);if(a.length)return c.push(...a),c;for(let a=0;a<s.length;a++){const r=At(s[a].value,e),o=Pt(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:q(o)}),c}for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const u=`${0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(u.length>1){const r=At(s[a].value,e),f=Pt(r,e,t,n,i);if(f)return c.push({key:`dynamic ${n} bridge`,value:q(f)}),c;const m=Yt(r,u,t,[e,t],t.ownerDocument,n,o,l);if(m)return c.push(...m),c}}}}catch(e){console.log(e)}return c},Nt=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,bt=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,xt=(e,t)=>Et(e,t)[0]||"",Et=(e,t)=>{const n=[];let a="";const r=e=>{e&&!n.includes(e)&&n.push(e)};for(const n of t){const t=bt(n.value);if(t&&1===t.split(Nt).length){if(t===e.tagName||t===e.tagName.toLowerCase()){a=t;continue}r(de(t))}}for(const t of wt){const n=e.getAttribute(t);if(!n)continue;const a=kt(t,n);a&&r(V(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`)}if(e.textContent){const t=fe(e);t&&r(V(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`)}const o=v(e,e.getAttribute("class"),e.getRootNode?.()??e.ownerDocument,!1);for(const t of o)r(V(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`);if(e.attributes)for(const t of Array.from(e.attributes))"class"!==t.name&&Y(t,e,!1)&&t.nodeValue&&r(V(e)?`*[local-name()='${e.tagName}' and @${t.name}=${O(x(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${O(x(t.name,t.nodeValue))}]`);return a&&r(a),r(V(e)?`*[local-name()='${e.tagName}']`:e.tagName),n},wt=["aria-labelledby","aria-label","role","name","formcontrolname","data-testid","data-test","data-qa","data-id","id"],kt=(e,t)=>{const n=x(e,t);return n?/\d/.test(n)?"":`@${e}=${O(n)}`:""},St=e=>e.split(Nt).length>1||/\[\d+\]/.test(e),At=(e,t)=>0!==e.indexOf("//")?de(e):de(e.substring(e.indexOf("//")+2)),Ct=e=>{const t=[];for(const n of wt){const a=e.getAttribute(n);if(!a)continue;const r=kt(n,a);if(r){t.push(V(e)?`*[local-name()='${e.tagName}' and ${r}]`:`${e.tagName}[${r}]`);break}}return t},Rt=(e,t=6)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},Ot=(e,t)=>{const n=kt(e,t);if(n)return n;const a=x(e,t);if("id"!==e||!a)return"";const r=a.match(/^(.+?)-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),o=r?.[1]?.trim();return!o||o.length<=2||!/[a-zA-Z]/.test(o)?"":`contains(@${e},${O(o)})`},Tt=(e,t,n,a,r,o,l)=>{let s=n.parentElement,i=0;for(;s&&s!==a&&i<6;){i++;for(const t of wt){const a=s.getAttribute(t);if(!a)continue;const i=kt(t,a);if(!i)continue;const c=V(s)?`*[local-name()='${s.tagName}' and ${i}]`:`${s.tagName}[${i}]`,u=`//${de(e)}/${r}::${o}/descendant::${c}/descendant::${de(l)}`;if(1===R(u,n,n.ownerDocument))return u}s=s.parentElement}return""},Dt=["title",...wt],Pt=(e,t,n,a,r)=>((e,t,n,a,r)=>{if("following"!==a&&"preceding"!==a)return"";const o=Et(n,r);if(!o.length)return"";const l=zt(`//${de(e)}`,t.ownerDocument)||t;let s=n.parentElement,i=0;for(;s&&i<6;)if(i++,l.compareDocumentPosition(s)&("following"===a?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING)){for(const t of Dt){const r=s.getAttribute(t);if(!r)continue;const l=kt(t,r);if(!l)continue;const i=V(s)?`*[local-name()='${s.tagName}' and ${l}]`:`${s.tagName}[${l}]`;for(const t of o){const r=`//${de(e)}/${a}::${i}/descendant::${de(t)}`;if(1===R(r,n,n.ownerDocument))return r}}s=s.parentElement}else s=s.parentElement;return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("following-sibling"!==a&&"preceding-sibling"!==a)return"";const o=Et(n,r);if(!o.length)return"";const l=Rt(t),s=Rt(n);for(const t of l){const r=Ct(t);if(r.length)for(const l of s){const s=Ct(l);if(!s.length)continue;const i="following-sibling"===a?t.nextElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)>Array.from(t.parentElement?.children||[]).indexOf(t):t.previousElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)<Array.from(t.parentElement?.children||[]).indexOf(t);if(t.parentElement&&t.parentElement===l.parentElement&&i)for(const t of r)for(const r of s)for(const l of o){const o=`//${de(e)}/ancestor-or-self::${t}/${a}::${r}/descendant-or-self::${de(l)}`;if(1===R(o,n,n.ownerDocument))return o}}}return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("child"!==a)return"";const o=Et(n,r);if(!o.length)return"";const l=Rt(n).filter(e=>e.parentElement===t);for(const t of l){const a=Ct(t);if(a.length)for(const t of a)for(const a of o){const r=`//${de(e)}/child::${t}/descendant-or-self::${de(a)}`;if(1===R(r,n,n.ownerDocument))return r}}return""})(e,t,n,a,r),Xt=(e,t,n,a,r)=>"ancestor"!==n&&"ancestor-or-self"!==n?[]:Wt(e,t,n,a,r,!1),Lt=(e,t,n,a,r)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";for(const o of a){const a=bt(o.value);if(!a||a.split(Nt).length>1||/\[\d+\]/.test(a))continue;const l=`//${e}/${t}::${de(a)}`;if(1===R(l,n,r))return l}return""},_t=(e,t,n,a)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";const r=Et(n,[...st(n,n.ownerDocument,!1,!1)||[],...ge(n,n.ownerDocument,!0)||[],{key:"tag",value:n.tagName}]);if(!r.length)return"";let o=n.parentElement,l=0;for(;o&&l<10;){l++;for(const l of wt){const s=o.getAttribute(l);if(!s)continue;const i=Ot(l,s);if(!i)continue;const c=V(o)?`*[local-name()='${o.tagName}' and ${i}]`:`${o.tagName}[${i}]`;for(const o of r){const r=`//${e}/${t}::${c}/descendant::${de(o)}`;if(1===R(r,n,a))return r}}o=o.parentElement}return""},zt=(e,t)=>{try{const n=t.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return n instanceof Element?n:null}catch{return null}},It=e=>{const t=e.getAttribute("fill"),n=e.getAttribute("stroke");if(/\d/.test(t||"")||/\d/.test(n||""))return"";const a=t?`@fill=${O(t)}`:n?`@stroke=${O(n)}`:"";return a?`*[local-name()='${e.tagName.toLowerCase()}' and ${a}]`:""},Mt=(e,t,n)=>{const a=t.getAttribute("fill"),r=t.getAttribute("stroke"),o=Array.from(e.querySelectorAll(t.tagName.toLowerCase())).slice(0,30);let l=0;for(const e of o){if(a&&e.getAttribute("fill")!==a||!a&&r&&e.getAttribute("stroke")!==r)continue;const t=e.closest(n.tagName.toLowerCase());if(t&&(l++,t!==n||l>1))return!1}return 1===l},jt=(e,t,n,a,r)=>{const o=Array.from(n.querySelectorAll("path,use,circle,rect,polygon,polyline,line")).slice(0,25);if(!o.length)return"";const l=[...(s=a,v(s,s.getAttribute("class"),s.getRootNode?.()??s.ownerDocument).map(e=>`${s.tagName.toLowerCase()}[${e}]`)),a.tagName];var s;for(const t of o){const o=It(t);if(o&&Mt(a,t,n))for(const t of l)return`//${de(e)}/${r}::${t}/descendant::${o}/ancestor::${n.tagName.toLowerCase()}`}return""},Wt=(e,t,n,a,r,o)=>{const l=[],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 l;const i=V(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let r=t;for(;r&&r!==e;){const e=r===t?xt(t,n):V(r)?`*[local-name()='${r.tagName}']`:r.tagName;a.unshift(e),r=r.parentElement}return r===e?a.join("/"):""})(s,t,r);if(!c)return l;const u=c.split(Nt).length>1?xt(t,r):"",f=u?((e,t)=>{let n=e,a=0;const r=[],o=new Set(["SECTION","FIELDSET","FORM","ARTICLE","MAIN"]);for(;n&&n.contains(t)&&a<6;){a++;for(const e of wt){const t=n.getAttribute(e);if(!t)continue;const l=kt(e,t);if(!l)continue;const s=V(n)?`*[local-name()='${n.tagName}' and ${l}]`:`${n.tagName}[${l}]`,i=(o.has(n.tagName)?100:0)+("data-testid"===e?20:0)-a;r.push({nodeTest:s,score:i});break}n=n.parentElement}return r.sort((e,t)=>t.score-e.score)[0]?.nodeTest||""})(s,t):"";for(const r of a){const a=bt(r.value);if(!a)continue;if(f){const e=`//${de(a)}/${n}::${f}/descendant::${de(u)}`;if(1===R(e,t,t.ownerDocument))return l.push({key:`dynamic ${n} bridge`,value:q(e)}),l}let m=u?`//${de(a)}/${n}::${i}/descendant::${de(u)}`:`//${de(a)}/${n}::${i}/${c}`,d=R(m,t,t.ownerDocument);const g=jt(a,0,t,s,n);if(g)return l.push({key:`dynamic ${n} icon bridge`,value:q(g)}),l;if(1===d)return l.push({key:`dynamic ${n} bridge`,value:q(m)}),l;if(u&&d>1){const e=Tt(a,0,t,s,n,i,u);if(e)return l.push({key:`dynamic ${n} bridge`,value:q(e)}),l;if(m=`//${de(a)}/${n}::${i}/${c}`,d=R(m,t,t.ownerDocument),1===d)return l.push({key:`dynamic ${n} bridge`,value:q(m)}),l}if(d>1&&o&&(m=D(m,t,t.ownerDocument,d),d=m?R(m,t,t.ownerDocument):0,m&&1===d))return l.push({key:`dynamic ${n} bridge index`,value:q(m)}),l;d>1&&!o&&ht(e,t,n,m,d)}return l},Yt=(e,t,n,a,r,o,l,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${o}::${de(s)}`;const c=R(i,n,r);if(1===c)return[{key:`dynamic ${o}`,value:q(i)}];if(c>1&&(l||ht(a[0],a[a.length-1],o,i,c),l&&(i=D(i,a[a.length-1],r,c),i)))return[{key:`dynamic ${o}${l?" index":""}`,value:q(i)}]}else for(let s=1;s<=t.length;s++){const c=Vt(t.slice(t.length-s,t.length).join("/"),n);for(const t of c){i=`//${e}/${o}::${de(t)}`;const s=R(i,n,r);if(1===s){if(t.split(Nt).length>1||/\[\d+\]/.test(t)){const t=_t(e,o,n,r);if(t)return[{key:`dynamic ${o}`,value:q(t)}]}if(!l&&/\[\d+\]/.test(t))continue;return[{key:`dynamic ${o}`,value:q(i)}]}if(s>1){l||ht(a[0],a[a.length-1],o,i,s);const t=Lt(e,o,n,st(n,n.ownerDocument,!1,!1)||[],r);if(t)return[{key:`dynamic ${o}`,value:q(t)}];const c=_t(e,o,n,r);if(c)return[{key:`dynamic ${o}`,value:q(c)}];if(l&&(i=D(i,a[a.length-1],r,s),i))return[{key:`dynamic ${o}${l?" index":""}`,value:q(i)}]}}}},Vt=(e,t)=>{const n=t.getAttribute("class")||"",a=v(t,n,t.getRootNode?.()??t.ownerDocument);if(!a.length)return[e];const r=`${t.tagName}[@class=${O(n)}]`;return e.endsWith(r)?a.map(n=>{const a=`${t.tagName}[${n}]`;return`${e.slice(0,-r.length)}${a}`}):[e]},qt={findRelativeXpath:(e,t,n,r,o,l,s=!1,i=null)=>{a(n),ct=[],ut=[];let c=[];const u=i||[];if(l){const a=((e,t,n,a)=>{const r=new Set(a),o=[],l=[...dt(e,t)];gt(e,t);for(const e of l){if(r.size&&!r.has(e.relation))continue;const a=pt(e.value,t,n);a&&o.push({key:e.key,value:q(a)})}return o})(e,t,n,u);if(a.length)return a}else gt(e,t);const f=(a,l)=>{let i=[];i="descendant"===a||"descendant-or-self"===a?yt([e,t],n,r,o,a,l,s)||[]:vt(e,t,a,r,o,l,s)||[],i.length&&(c=c.concat(i))};for(const e of u)f(e,l);return c},getDescendantXpath:yt,getAncestorBridgeXpath:Wt,getXpathRelationExpression:vt,getTraverseXpathExpression:Yt,getReferenceElementXpath:e=>{let t=[];t=st(e,e.ownerDocument,!1,!1);const n=ge(e,e.ownerDocument,!1);if(n?.length&&(t=t?.length?t.concat(n):n),t?.length){let n=st(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&pe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:T(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=st(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&pe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:T(e.value)}:{key:"",value:e.value});t?.length||(t=[{key:"",value:H(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:H(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&pe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:T(e.value)}:{key:"",value:e.value}));const a=Array.from(e.children||[]).map(t=>{const n=A(t)?.trim();if(!n||n!==A(e)?.trim())return null;const a=L(t,n),r=a||(/\s/.test(n)?`normalize-space(.)=${O(X(n))}`:`.=${O(n)}`);return{key:"reference child text",value:`${t.tagName}[${r}]`}}).filter(e=>!!e);a.length&&(t=a.concat(t));const r=F(e,e.ownerDocument);return t=t.filter(e=>e.value!==r),t.push({key:"absolute xpath",value:r.slice(1)}),t},getSmartRelations:(e,t)=>{const n=e.compareDocumentPosition(t),a=[],r=[],o=[];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&&r.push("following"),n&Node.DOCUMENT_POSITION_PRECEDING&&r.push("preceding"),o.push("descendant","descendant-or-self");const l=[...a,...r,...o];return[...new Set(l)]}},Ut=["data-testid","data-test-id","data-test","data-cy","data-qa","name","aria-label","aria-labelledby","placeholder","title","alt","role"],Ft=new Set(["id","class","style"]),Ht=(e,t)=>{const n=t?.ownerDocument?.defaultView?.CSS??globalThis.CSS;return n?.escape?n.escape(e):String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")},Gt=e=>{if(!e)return!1;const t=e.ownerDocument?.defaultView;return Boolean(t&&e instanceof t.Element)},Bt=e=>{const t=e.tagName.toLowerCase();return"style"===t||"script"===t},Zt=e=>{const t=e.trim();return Boolean(t)&&t.length<=120&&!/^\d+$/.test(t)},Jt=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},Kt=(e,t,n)=>{n&&!e.some(e=>e.value===n)&&e.push({key:t,value:n})},Qt=(e,t="single")=>{const n=[],a=e.getRootNode();try{const r=en(e);if(r&&Jt(r,e,a)&&(Kt(n,"cssSelector by id",r),"single"===t))return n;const o=nn(e);if(o&&(Kt(n,"cssSelector by attribute",o),"single"===t))return n;const l=an(e);if(l&&Jt(l,e,a)&&(Kt(n,"cssSelector by class",l),"single"===t))return n;const s=ln(e);if(s&&Jt(s,e,a)&&(Kt(n,"cssSelector by stable parent",s),"single"===t))return n;if("multiple"===t&&0===n.length){const t=cn(e);t&&Jt(t,e,a)&&Kt(n,"cssSelector by position fallback",t)}}catch(e){console.error(e)}return n},en=e=>{if(!Gt(e)||Bt(e))return;const t=e.getAttributeNode("id");return t&&Zt(t.value)&&Y(t,e,!0)?`#${Ht(e.id,e)}`:void 0};function tn(e,t=!1){const n=Array.from(e.attributes).filter(n=>{const a=n.name.toLowerCase();return!Ft.has(a)&&(!(t&&!Ut.includes(a))&&(Zt(n.value)&&Y(n,e,!0)))});return n.sort((e,t)=>{const n=Ut.indexOf(e.name.toLowerCase()),a=Ut.indexOf(t.name.toLowerCase());return(-1===n?999:n)-(-1===a?999:a)}),n.map(e=>{return`[${e.name}="${t=e.value.trim(),String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const nn=e=>{if(!Gt(e)||Bt(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase(),a=tn(e);for(const r of a){if(Jt(r,e,t))return r;const a=`${n}${r}`;if(Jt(a,e,t))return a}},an=e=>{if(!Gt(e)||Bt(e))return;const t=rn(e);if(!t)return;const n=e.getRootNode(),a=`${e.tagName.toLowerCase()}${t}`;return Jt(t,e,n)?t:Jt(a,e,n)?a:void 0},rn=e=>{if("string"!=typeof e.className||!e.className||c?.find(t=>t.element===e&&"class"===t.attributeName))return;const t=N(e,e.className).filter(Zt);return t.length?t.slice(0,3).map(t=>`.${Ht(t,e)}`).join(""):void 0},on=(e,t={})=>{if(!Gt(e)||Bt(e))return[];const n=[],a=e.tagName.toLowerCase(),r=en(e);r&&n.push(r);for(const r of tn(e,t.preferredAttributesOnly))n.push(r),t.includeTag&&n.push(`${a}${r}`);const o=rn(e);return o&&(n.push(o),t.includeTag&&n.push(`${a}${o}`)),Array.from(new Set(n))},ln=e=>{if(!Gt(e)||Bt(e))return;const t=e.getRootNode(),n=on(e,{includeTag:!0,preferredAttributesOnly:!1});let a=e.parentElement;for(;a&&Gt(a)&&!Bt(a);){const r=on(a,{includeTag:!0,preferredAttributesOnly:!0});for(const o of r)if(Jt(o,a,t))for(const a of n){const n=`${o} ${a}`;if(Jt(n,e,t))return n;const r=`${o} > ${a}`;if(Jt(r,e,t))return r}a=a.parentElement}},sn=e=>{let t=1,n=e.previousElementSibling;for(;n;)n.tagName===e.tagName&&t++,n=n.previousElementSibling;return t},cn=e=>{if(!Gt(e)||Bt(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase();let a=e.parentElement;for(;a&&Gt(a)&&!Bt(a);){const r=on(a,{includeTag:!0,preferredAttributesOnly:!0});for(const o of r){if(!Jt(o,a,t))continue;const r=`${o} > ${n}:nth-of-type(${sn(e)})`;if(Jt(r,e,t))return r}a=a.parentElement}return un(e)},un=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=[];for(;e&&e.nodeType===t.Node.ELEMENT_NODE;){const t=e.tagName.toLowerCase();if("style"===t||"script"===t)return;let a=t;const r=e.parentNode;if(r){const t=Array.from(r.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(" > ")},fn={parseCssSelectors:Qt,getIdCssPath:en,getAttributeCssPath:nn,getClassCssPath:an,getAbsoluteCssPath:un},mn=(e,t,n)=>{const a=he(e);if(xn(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},dn=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return pn(e.body,t)},gn=(e,t,n)=>dn(t,e)===n,hn=e=>e.name?.toLowerCase().includes("cssselector")??!1,pn=(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=pn(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},$n=e=>e?.id||null,yn=e=>e.className||null,vn=e=>e.textContent?.trim()||null,Nn=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},bn=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function xn(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 En(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),r=n.defaultView;if(!r)return null;if(!e.includes("dynamic")){const t=new r.XPathEvaluator;if(t.evaluate(a,n,null,r.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,r.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 wn=(e,t)=>{a(t);const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const r=new Set;let o=[];function l(e,t={}){const n=e?.value,a=t.value??e?.value,l={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;l.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(l.name,n,a),function(e){const t=`${e.name}:${e.value}`;r.has(t)||(r.add(t),o.push(e))}(l)}function s(e,t,n){if(hn(t))return dn(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+ye(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=ye(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=xn(e,he(n));return a&&l(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 r=s(a,t,n);if(r)return r}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 a=e.locators.filter(e=>"N"===e.isRecorded);if(a.length>0)for(const e of a)l(e);const u=String(n.value||n.type||"");if(u.includes("dynamic")||u.match("dynamic")||u.includes("{")||u.includes("}")){l(n);continue}if(e.isShared.includes("Y"))break e;try{let a=null;const u=n.value.split(">>>");for(const e of u){if(!t){console.error("Element not found at:",e);break}const r=e.trim();if(a=s(t,n,r),a||(a=i(t,n,r)),a||(a=pn(t.body,r)),!a){console.error("Element not found at:",r);break}}const f=(e,t)=>{const n=`${e}:${t}`;return r.has(n)};if(a){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),r=e.locators.filter(e=>hn(e)&&e.value);for(const e of n)mn(e.value,t,a)&&l(e,{isSelfHealed:null});for(const e of r)gn(e.value,t,a)&&l(e,{isSelfHealed:null});const s=o.filter(e=>"xpath"===e.name&&e.value),i=new Set(s.map(e=>$e(e.value))),u=[],m=$n(a);if(m&&!f("id",m)&&!k(m)){const n=e.locators.find(e=>"id"===e.name);ve(t,"id",m,a)&&(u.push("id"),l(n,{name:"id",type:"static",isRecorded:"Y",value:m}))}const d=a.tagName;if(d&&!f("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);ve(t,"tagName",d,a)&&(u.push("tagName"),l(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const g=vn(a);if(g&&!k(g)){const n=e.locators.find(e=>"linkText"===e.name);ve(t,"linkText",g,a)&&(u.push("linkText"),l(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const h=Nn(a);if(h&&!f("name",h)&&!k(h)){const n=e.locators.find(e=>"name"===e.name);ve(t,"name",h,a)&&(u.push("name"),l(n,{name:"name",type:"static",isRecorded:"Y",value:h}))}const p=yn(a);if(p&&""!==p.trim()&&!p.includes(" ")&&!f("className",p)&&!k(p)){const n=e.locators.find(e=>"className"===e.name);ve(t,"className",p,a)&&(u.push("className"),l(n,{name:"className",type:"static",isRecorded:"Y",value:p}))}Qt(a,"single").forEach(e=>{e.value&&!f("cssSelector",e.value)&&l(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const $=Array.from(a.attributes).filter(e=>!u.includes(e.name));let y=[];try{y=st(a,t,!1,!0,$)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==y?.length){const e=n.filter(e=>!mn(e.value,t,a));let r=0;for(const t of e){if(r>=e.length)break;const n=$e(t.value);if(i.has(n))continue;const a=y.find(e=>e.value&&$e(e.value)===n);a?.value&&(l(t,{name:"xpath",value:a.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),i.add(n),r++)}if(r<e.length)for(const t of y){if(r>=e.length)break;if(!t.value)continue;const n=$e(t.value);i.has(n)||(l(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),i.add(n),r++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of bn)if(a.value.includes(e)){const r=En(a.value,e,t);if(r){l(a,{name:"xpath",value:r,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(o.length<5){const e=[{name:"id",value:$n(a)},{name:"name",value:Nn(a)},{name:"className",value:yn(a)},{name:"linkText",value:vn(a)}];for(const n of e){if(o.length>4)break;const{name:e,value:r}=n;r&&(k(r)||f(e,r)||"className"===e&&r.includes(" ")||ve(t,e,r,a)&&l(void 0,{name:e,type:"static",value:r,isRecorded:"Y",isSelfHealed:"Y"}))}o.length<5&&Qt(a,"multiple").forEach(e=>{o.length>4||e.value&&(f("cssSelector",e.value)||ve(t,"cssSelector",e.value,a)&&l(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const v=o.map(e=>({...e,value:c(e.value,e.name,e.isRecorded)})),N=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:v.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return N}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};const kn={getOptimalClassChain:function e(t,n,a){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const r=n.tagName,o=["name","label","value"];for(const e of o){const o=a.find(t=>t.name===e);if(!o)continue;let l=o.value;if(!l)continue;if(l=l.trim().replace(/\s+/g," "),k(l))continue;const s=`//${r}[@${e}="${l}"]`;let i=0;try{i=R(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(l);if(1===i)return c?`/${r}[\`${e} CONTAINS "${l}"\`]`:`/${r}[\`${e} == "${l}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===r).indexOf(n)+1;return c?`/${r}[\`${e} CONTAINS "${l}"\`][${t}]`:`/${r}[\`${e} == "${l}"\`][${t}]`}}let l=`/${r}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===r);if(e.length>1){l+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,a)+l}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=[],r=[];for(let o of n){const n=o.value,l=o.name;if(0!==n.length&&(n&&!k(n))){a.push(`@${l}="${n}"`);const o=`//*[${a.join(" and ")}]`;let s;r.push(`${l} == "${n}"`);try{s=R(o,t,e)}catch(e){console.log(e);continue}if(1===s)return r.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}},Sn=()=>({xpath:it,referenceXpaths:qt,xpathUtils:Ne,getElementsFromHTML:wn,cssSelectors:fn,iosSelectors:kn});export{Sn as createXPathAPI,Sn as default};