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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/xpath.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{VirtualConsole as e,JSDOM as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i;let r=new WeakMap;const a=(e,t)=>{const{owner:n,contextNode:a}=(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}})(t);let o=r.get(a);o||(o=new Map,r.set(a,o));const l=o.get(e);if(l)return l;const s=n.evaluate(e,a,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let o=[];const l=new Set(["marked-element-temp","removePointers"]),s=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!l.has(e)).sort(),i=e=>/\d/.test(e||""),c=(e,t,n,r=!1)=>{const a=s(t),o=a.filter(e=>!!r||!i(e));return o.length?1===a.length&&1===o.length?[`@class=${p(o[0])}`]:o.map(t=>{const r=d(`contains(@class,${p(t)})`,b(e),e.tagName.toLowerCase());return{token:t,count:D(r,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,${p(e)})`):[]},u=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),f=(e,t)=>t?"class"===e||"className"===e?s(t).join(" "):t.replace("removePointers","").trim():"",m=e=>/\d/.test(e),d=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,h=e=>{const t=e?.textContent;return t},g=(e,t,n,r=!1)=>{try{if(N(n)){const{owner:a,contextNode:o,cloneElement:l,cloneElements:s}=x(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 r=0;if(t.includes(o)&&r++,t.includes(l)&&r++,2===r)return 2;const a=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=a.iterateNext();)if(t.includes(s)&&(r++,2===r))return 2;return 0}return 2}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},p=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},$=e=>e?e.replace(/\s\s+/g," ").trim():e,y=(e,t)=>{const n=$((t||"").trim());if(!e.children.length||n.length<=50)return"";const r=n.split(/\s+/).slice(0,3).join(" ");return r.length>2?`contains(normalize-space(.),${p(r)})`:""},v=e=>{const t=$((e||"").trim());if(!t||!i(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),r=n.split(/[^a-zA-Z]+/).map(e=>$(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:r.length>2?r:""}},E=e=>v(e).fragment,N=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,x=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),r=n.createElement("div");r.innerHTML=e.innerHTML,n.body.appendChild(r);const a=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let r=t;for(;r&&r.parentElement;){const e=r.parentElement;n.unshift(Array.from(e.children).indexOf(r)),r=e}return r&&r.parentNode===e?(n.unshift(Array.from(e.children).indexOf(r)),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})(r,n):null},o=Array.isArray(t)?t.map(e=>a(e)).filter(Boolean):[],l=Array.isArray(t)?null:a(t??null);return{owner:n,contextNode:r,cloneElement:l,cloneElements:o}},S=(e,t,n)=>{const r=f(e.name,e.value);if(!r||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(e=>e===r))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const a=o?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!a&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(l=e.name,s=r,(!u.has(l.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(s))&&("class"===e.name||!i(r)))));var l,s},b=e=>e instanceof SVGElement,w=(e,t,r,a,o,l)=>{if(a){const{tagName:s}=e;let u,f="";const h=[];let v;const N=r.startsWith("@"),x="."===r||"text()"===r,S=x?".":r,w=x&&/\s/.test(a.trim()),k=x?E(a):a,R=x&&i(a)?k:a,T=x?y(e,R):"";if("@class"===r){for(const n of c(e,a,t))if(v=d(n,b(e),e.tagName.toLowerCase()),u=g(v,e,t),1===u&&!o)return v;return}if(x&&i(a)&&!k)return;if(a&&(!N||!m(a))&&(v=T?d(T,b(e),e.tagName.toLowerCase()):w?d(`normalize-space(${S})=${p($(R)).trim()}`,b(e),e.tagName.toLowerCase()):n.test(a)?`//${s}[${r}=${p(R)}]`:d(`normalize-space(${r})=${p($(R)).trim()}`,b(e),e.tagName.toLowerCase()),u=g(v,e,t),1===u&&!o))return v;if(N&&i(a))return;if(a&&l){const l=a.split(" ");if(l?.length)if(1===l.length){const i=[...new Set(l[0].match(/([^0-9]+)/g))];if(i?.length>=1&&i[0]&&$(i[0].trim())?.length>1&&a.startsWith(i[0])&&(f=n.test(i[0])?`starts-with(${r},${p(i[0]).trim()})`:`starts-with(${r},${p($(i[0])).trim()})`),i?.length>1&&i[i.length-1]&&$(i[i.length-1].trim())?.length>1&&a.endsWith(i[i.length-1])&&(f=n.test(i[i.length-1])?`ends-with(${r},${p(i[i.length-1]).trim()})`:`ends-with(${r},${p($(i[i.length-1])).trim()})`),f?.length&&(v=b(e)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,u=g(v,e,t),1===u&&!o))return v}else{const i=l.length%2==0?l.length/2:l.length%2,c=l.slice(0,i).join(" ");let m=[...new Set(c.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&$(m[0].trim())?.length&&a.startsWith(m[0])&&(f=n.test(m[0])?`starts-with(${r},${p(m[0]).trim()})`:`starts-with(${r},${p($(m[0])).trim()})`),f?.length&&(v=b(e)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,u=g(v,e,t),1===u&&!o))return v;const d=l.slice(i,l.length-1).join(" ");if(m=[...new Set(d.match(/([^0-9]+)/g))],m?.length&&m[0]&&$(m[0].trim())?.length>3&&a.endsWith(m[0])&&(f=n.test(m[0])?`ends-with(${r},${p(m[0]).trim()})`:`ends-with(${r},${p($(m[0])).trim()})`),f?.length&&(v=b(e)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,u=g(v,e,t),1===u&&!o))return v}}if(a&&l&&m(a)){const l=[...new Set(a.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&$(l[e].trim())?.length>1&&(n.test(l[e])?h.push(`contains(${r},${p(l[e].trim()).trim()})`):h.push(`contains(${r},${p($(l[e])).trim()})`));if(h?.length&&(v=b(e)?`//*[local-name()='${s}' and ${h.join(" and ")}]`:`//${s}[${h.join(" and ")}]`,u=g(v,e,t),1===u&&!o))return v}if(v=b(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,u=g(v,e,t),1===u&&!o)return v}},k=(e,t,r,a)=>{try{const a=r.filter(t=>S(t,e)),o=r=>{const a=f(r.name,r.nodeValue);return a?"class"===r.name?c(e,a,t):i(a)?[]:n.test(a)?[`@${r.name}="${a}"`]:[`normalize-space(@${r.name})="${a}"`]:[]},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])):[]},[[]]),u=()=>{const t=$(h(e)?.trim()||""),r=E(t);if(i(t))return r?[`contains(normalize-space(.),${p(r)})`]:[];if(!t||t.length>80||/^\d+$/.test(t)){const n=y(e,t);return n?[n]:[]}const a=new Set,o=y(e,t);return o?(a.add(o),Array.from(a)):(n.test(t)&&t.length<=40&&!t.includes(" ")&&a.add(`text()=${p(t)}`),t.includes(" ")&&a.add(`normalize-space(.)=${p($(t))}`),a.add(`contains(text(),${p(t)})`),Array.from(a))},m=(e,t)=>{const n=[],r=(a,o)=>{if(o.length!==t)for(let t=a;t<e.length;t++)o.push(e[t]),r(t+1,o),o.pop();else n.push([...o])};return r(0,[]),n},d=t=>b(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,v=(()=>{if(!(a.length<2))for(let n=2;n<=a.length;n++){const r=m(a,n);for(const n of r){const r=s(n);for(const n of r){if(n.length<2)continue;const r=d(n);let a;try{a=g(r,e,t)}catch{continue}if(1===a)return r}}}})();if(v)return v;const N=u();if(!N.length||!a.length)return;for(let n=1;n<=a.length;n++){const r=m(a,n);for(const n of r){const r=s(n);for(const n of r)if(n.length)for(const r of N){const a=[...n,r],o=d(a);try{if(1===g(o,e,t))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},R=(e,t)=>{if(!e.textContent)return"";const r=(a=e,a?.childNodes[0]?.nodeValue||"");var a;const o=E(r);if(i(r)&&!o)return"";const l=i(r)?o:r,s=y(e,l);let c;return c=s?d(s,b(e),e.tagName||"*"):i(r)?d(`contains(normalize-space(.),${p(l)})`,b(e),e.tagName||"*"):!n.test(r)||/\s/.test(r.trim())?d(`normalize-space(.)=${p(l)}`,b(e),e.tagName||"*"):b(e)?`//*[local-name()='${e.tagName}' and .=${p(l)}]`:`//${e.tagName||"*"}[.=${p(l)}]`,c},T=(e,t,n)=>{if(("."===t||"text()"===t)&&i(n)){const{fragment:t}=v(n);return t?d(`contains(normalize-space(.),${p(t)})`,b(e),e.tagName.toLowerCase()):""}return d(`normalize-space(${t})=${p($(n)).trim()}`,b(e),e.tagName.toLowerCase())},C=(e,t,n)=>{if(("."===t||"text()"===t)&&i(n)){const{prefix:t,fragment:r}=v(n),a=t||r;return a?d(`starts-with(normalize-space(.),${p(a)})`,b(e),e.tagName.toLowerCase()):""}return d(`starts-with(${t},${p($(n)).trim()})`,b(e),e.tagName.toLowerCase())},A=(e,t,n)=>{if(("."===t||"text()"===t)&&i(n)){const{fragment:t}=v(n);return t?d(`contains(normalize-space(.),${p(t)})`,b(e),e.tagName.toLowerCase()):""}return d(`contains(${t},${p($(n)).trim()})`,b(e),e.tagName.toLowerCase())},L=(e,t)=>{const r=t.flatMap(t=>(t=>{const r=f(t.name,t.value);if(!r)return[];if("class"===t.name){const t=e.getRootNode?.()??e.ownerDocument;return c(e,r,t)}return i(r)?[]:n.test(r)?[`@${t.name}=${p(r)}`]:[`normalize-space(@${t.name})=${p(r)}`]})(t)).filter(Boolean);if(r.length>=2)return d(`${r[0]} or ${r[1]}`,b(e),e.tagName.toLowerCase());const a=(()=>{const t=$(h(e)?.trim()||""),r=E(t);if(i(t))return r?`contains(normalize-space(.),${p(r)})`:null;const a=y(e,t);return a||(!t||t.length>80||/^\d+$/.test(t)?null:n.test(t)&&t.length<=40&&!t.includes(" ")?`text()=${p(t)}`:t.includes(" ")?`normalize-space(.)=${p(t)}`:`contains(text(),${p(t)})`)})();return 1===r.length&&a?d(`${r[0]} or ${a}`,b(e),e.tagName.toLowerCase()):""},D=(e,t,n)=>{try{return g(e,t,n)}catch(e){return 0}},P=(e,t)=>{const n=[],r=new Set,a=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","aria-label","role"],l=[...o.map(e=>a.find(t=>t.name===e)).filter(Boolean),...a.filter(e=>!o.includes(e.name))],s=a=>{a&&!r.has(a)&&Y(a,e,t)&&(r.add(a),n.push(a))};l.forEach(t=>{if(S(t,e))for(const n of M(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=R(e);t&&s(t)}if(a.length>1){const n=k(e,t,a);n&&s(n)}return n},O=(e,t)=>{const n=[];let r=t;for(;r&&r!==e;)n.unshift(X(r)),r=r.parentElement;return r===e?n.join("/"):""},_=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),r=X(e),a=b(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const a=P(t,n);for(const o of a){console.log(`Trying ancestor XPath: ${o}`);const a=`${o}/descendant::${r}`;console.log(`Trying descendant XPath: ${a}`);const l=D(a,e,n);if(console.log(`Match count: ${l}`),1===l&&z(a,n)===e)return console.log(`Selected XPath: ${a}`),a;const s=O(t,e);if(s){const t=`${o}/${s}`;console.log(`Trying descendant XPath: ${t}`);const r=D(t,e,n);if(console.log(`Match count: ${r}`),1===r&&z(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${a}`);const o=D(a,e,n);return console.log(`Match count: ${o}`),1===o&&z(a,n)===e?(console.log(`Selected XPath: ${a}`),a):(console.log("Selected XPath: "),"")},z=(e,t)=>{try{if(N(t)){const{owner:n,contextNode:r,cloneElement:a}=x(t);return n.evaluate(e,r,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||a}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},Y=(e,t,n)=>{try{const{first:r,second:o}=a(e,n);return!!r&&!o&&r===t}catch{return!1}},X=e=>b(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),j=(e,t,n)=>{if(!(e instanceof Element))return[];const r=new Set,a=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(n=t.value,!/\d/.test(n))&&S(t,e);var n}),l=(e,t)=>{t&&!r.has(t)&&(r.add(t),a.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","aria-label","role"];s.forEach(n=>{const r=o.find(e=>e.name===n);if(r)for(const n of M(e,r.name,r.value))n&&Y(n,e,t)&&l(`anchor by ${r.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const r of M(e,n.name,n.value))r&&Y(r,e,t)&&l(`anchor by ${n.name}`,r)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=R(e);n&&Y(n,e,t)&&l("anchor by text",n)}if(o.length>1){const n=k(e,t,o);n&&Y(n,e,t)&&l("anchor by combination",n)}const c=_(e,t);return c&&Y(c,e,t)&&l("anchor by tag",c),a},M=(e,t,n)=>{const r=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";if(n=f(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return c(e,n,t).map(t=>b(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(i(n))return[];a=r.test(n)?b(e)?`//*[local-name()='${e.tagName}' and @${t}=${p(n)}]`:`//${e.tagName||"*"}[@${t}=${p(n)}]`:b(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`}return a?[a]:[]},H=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function I(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)::/),r=n?.[1]??"none",a=t.match(/@([a-z0-9:-]+)/);return{axis:r,attribute:a?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function V(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function q(e,t,n,r){const a=r?.getRootNode?.()??e,o=e=>{try{return Array.from(a.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===o(`#${V(n)}`).length;case"name":return 1===o(`[name="${V(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}}let W=[];const F={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},G=e=>F[e]||e,Z=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),B=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const r=e[n];if(t){r===t&&(t=null);continue}if("'"===r||'"'===r){t=r;continue}if("["!==r)continue;const a=e.indexOf("]",n+1);if(-1===a)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,a)))return!0}return!1})(e.value)),U=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",J=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},K=(e,t)=>{const n=[];let r="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;r;)r.classList?.contains("flntooltip")||n.push(r),r="previous"===t?r.previousElementSibling:r.nextElementSibling;return n},Q=(e,t)=>{const n=[];for(let r=e;r?.parentElement;r=r.parentElement){let e="previous"===t?r.previousElementSibling:r.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>J(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},te=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},ne=(e,t,n,r,a,o,l)=>{const s=X(n),i=[];let c=0;const u=t.includes("descendant")?10:20;for(const a of e){if(c++>u)break;if(i.length>=5)break;const e="node"in a?a.node:a;if(!(e instanceof Element))continue;if(ee(e))continue;const f=[()=>j(e,r),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&S(t,e));for(const r of n){const n=r.value;if(!n)continue;const a=A(e,`@${r.name}`,n);a&&t.push({key:"contains",value:a});const o=C(e,`@${r.name}`,n);o&&t.push({key:"starts-with",value:o})}return t},()=>[{key:"tag",value:_(e,r)}]];for(let a=0;a<f.length;a++){let c=f[a]();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 a=`${e.value}/${t}::${s}`;if(Y(a,n,r)){if(i.push({key:o,value:a}),i.length>=2)return i;if(i.length>=5)return i}}if(l&&a===f.length-1)for(const a of c){const l=g(a.value,e,r);for(let e=1;e<=Math.min(l,3);e++){const l=`(${a.value})[${e}]/${t}::${s}`;if(Y(l,n,r)){if(i.push({key:o,value:l}),i.length>=2)return i;if(i.length>=5)return i}}}}if("expand"in a&&a.expand){const e=a.expand();let l=0;for(const a of e){if(l++>15)break;if(i.length>=5)break;if(!(a instanceof Element))continue;if(ee(a))continue;const e=j(a,r);for(const a of e.slice(0,5)){const e=`${a.value}/${t}::${s}`;if(Y(e,n,r)){if(i.push({key:o,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},re=(e,t)=>{const n=[];let r=e;for(;r&&n.length<t;)n.push(r),r=r.parentElement;return n},ae=(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""},oe=(e,t)=>{const n=[];for(let r=e;r&&r!==t;r=r.parentElement){const e=r.parentElement;if(!e)return"";n.push(`/parent::${X(e)}`)}return n.join("")},le=(e,t)=>{const n=X(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},se=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))};for(let n=e.parentElement,a=0;n&&a<4&&t.length<20;n=n.parentElement,a++){const e=[K(n,"previous").slice(0,4),K(n,"next").slice(0,4)];for(const t of e)for(const e of t){r(e);let t=0;for(const n of J(e).sort((e,t)=>te(t)-te(e))){if(t++>=8)break;r(n)}}}return t.sort((e,t)=>te(t)-te(e)).slice(0,20)})(e),l=re(e.parentElement,3);for(const n of o){const o=j(n,t).filter(e=>"anchor by tag"!==e.key).slice(0,2);if(!o.length)continue;const s=re(n,3);for(const i of o)for(const o of s){const s=oe(n,o);if(o===n||s)for(const n of l){if(!n||!n.contains(e))continue;const l=ae(o,n);if(!l)continue;const c=`/${l}::${X(n)}`;for(const o of le(n,e)){const n=`${i.value}${s}${c}${o}`;if(!a.has(n)&&(a.add(n),Y(n,e,t)&&(r.push({key:"chained axes fallback",value:n}),r.length>=2)))return r}}}}return r},ie=(e,t)=>{const n=[];for(let r=t;r&&r!==e;r=r.parentElement)n.unshift(X(r));if(!n.length)return"";const r=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${r}`},ce=(e,t,n,r)=>{const a=new Set,o=[],l=(e,t)=>{t&&!a.has(t)&&(!r&&/\[\d+\]/.test(t)||(a.add(t),o.push({key:e,value:t})))};return j(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)||!i(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 r=A(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,r)}),o},ue=(e,t,n,r)=>{const a=[];for(let t=e.parentElement;t;t=t.parentElement)a.push(t);const o=J(e),l=K(e,"previous"),s=K(e,"next"),i=Q(e,"previous"),c=Q(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(a),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(a),axis:"descendant",key:"descendant"},{nodes:u(a),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,r)=>{const a=[],o=new Set;for(let n=e.parentElement,l=0;n&&l<8;n=n.parentElement,l++){const l=ie(n,e);if(!l)continue;const s=ce(n,t,0,r);for(const n of s.slice(0,3)){const r=`${n.value}${l}`;if(!o.has(r)&&(o.add(r),Y(r,e,t)&&(a.push({key:"child chain",value:r}),a.length>=2)))return a}}return a})(e,t,0,r);if(m.length)return m;for(const n of f)for(const a of n){const n=ne(a.nodes,a.axis,e,t,0,a.key,r);if(n.length>0)return n}return se(e,t)||[]},fe=(e,t,n,r,a)=>{const o=G(r);return"text"===o?Z(r,((e,t,n)=>{if(!U(e))return[];if("text"===n){const n=R(e)||me(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?Z(r,((e,t,n)=>{const r=[],a=Array.from(e.attributes||[]).filter(t=>t?.value&&S(t,e)),o=U(e),l="contains"===n?A:"startsWith"===n?C:"normalizeSpace"===n?T:null;if(!l)return r;if(a.forEach(t=>{const a=l(e,`@${t.name}`,t.value);a&&r.push({key:`xpath by ${n} ${t.name}`,value:a})}),o){const t=l(e,".",o);t&&r.push({key:`xpath by ${n} text`,value:t})}return r})(e,0,o)):["and","or"].includes(o)?Z(r,((e,t,n,r)=>{const a=Array.from(e.attributes||[]).filter(t=>t?.value&&S(t,e));if("and"===r){const n=k(e,t,a);return n?[{key:"xpath by combination",value:n}]:[]}if("or"===r&&a.length>=1){const t=L(e,a);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,0,o)):"axes"===o?Z(r,ue(e,t,0,!1)):"index"===o?Z(r,((e,t)=>{const n=[],r=e.tagName.toLowerCase(),a=Array.from(t.querySelectorAll(r)).indexOf(e)+1;if(a<=0)return[];n.push({key:"xpath by index",value:`(//${r})[${a}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?M(o,"id",o.id):M(o,"class",o.className.toString());for(const a of t){const t=Array.from(o.querySelectorAll(r)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${a}//${r})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?Z(r,[{key:"xpath till tag",value:_(e,t)}]):[]};const me=(e,t,n,r)=>{if(""!=(e.textContent??"").trim()){const a=h(e);if(a)return w(e,t,".",a,n,r)}},de=(e,t,n,r,a)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&S(e,t)){const o=((e,t,n,r,a)=>{let o;if(o=e.name,S(e,t))return w(t,n,`@${o}`,e.value,r,a)})(e,t,n,r,a);o&&W.push({key:`xpath by ${e.name}${r?" index":""}`,value:o})}});const l=me(t,n,r,a);if(l&&W.push({key:"xpath by text"+(r?" index":""),value:l}),o.find(e=>"className"===e.name)&&S(o?.find(e=>"className"===e.name),t)){let e=((e,t,n,r)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=f("class",a),a=a?.trim(),a&&S({name:"class",value:a},e))return w(e,t,"@class",a,n,r)})(t,n,r,a);e&&W.push({key:"xpath by class",value:e})}if(!W.length&&o.length>1){const e=k(t,n,o);e&&W.push({key:"xpath by combination",value:e})}if(!W.length){const r=function(e,t,n){const{tagName:r}=t,a=t.textContent.trim();if(!a)return;const o=$(a),l=E(o);if(i(o)&&!l)return;const s=i(o)?l:o,c=y(t,s);for(const l of e)if(S(l,t)){let e=f(l.name,l.nodeValue);const u=`//${r}[@${l.name}='${e}' and ${c||(i(o)?`contains(normalize-space(.),${p(s)})`:/\s/.test(a)?`normalize-space(.)=${p(s)}`:`text()=${p(s)}`)}]`;if(u&&1==g(u,t,n))return u}}(e,t,n);r&&W.push({key:"xpath by textAttribute",value:r})}}catch(e){console.log(e)}},he=(e,t,n,r,a=[],o=[])=>{W=[],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=a.length>0?a:Array.from(f);if(de(m,l,c,n,r),o.length){const e=n||((e=[])=>e.some(e=>"index"===G(e)))(o),t=o.flatMap(e=>fe(l,c,0,e));return W=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(t.filter(e=>1===g(e.value,l,c))),B(W,e)}if(W.length){const t=W.length;for(let n=0;n<t;n++){let t=W[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===g(t,e,c)&&W.push({key:`${W[n].key} regex`,value:t})}}return W.length||i||(W=ue(l,c,0,n)),B(W,n)};let ge=[];const pe=(e,t,n)=>{try{const r=n.querySelectorAll(e);return 1===r.length&&r[0]===t}catch{return!1}},$e=(e,t="single")=>{const n=[],r=e.getRootNode();try{const a=ye(e);if(a&&pe(a,e,r)&&(n.push({key:"cssSelector by id",value:a}),"single"===t))return n;const o=xe(e);o&&pe(o,e,r)&&n.push({key:"cssSelector by class",value:o});const l=Ne(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},ye=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 r=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!m(e.id)){t+=`#${CSS.escape(e.id)}`,r.unshift(t);break}{let n=e,r=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&r++;1!==r&&(t+=`:nth-of-type(${r})`),1===r&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${r})`)}r.unshift(t),e=e.parentElement}return r.join(" > ")},ve=new Set(["id","class","style"]);function Ee(e){return Array.from(e.attributes).filter(e=>!ve.has(e?.name?.toLowerCase())&&e.value&&!m(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Ne=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.getRootNode(),r=e.tagName.toLowerCase();if("style"===r||"script"===r)return;const a=Ee(e);for(const t of a){const a=`${r}${t}`;if(pe(a,e,n))return a}},xe=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const r=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||m(e.className)||ge?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,r=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&r++;1!==r&&(t+=`:nth-of-type(${r})`),1===r&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${r})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,r.unshift(t);break}r.unshift(t),e=e.parentElement}return r.join(" > ")},Se=(e,t,n)=>{const r=H(e);if(Pe(t,r)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(r)){const e=t.evaluate(r,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},be=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Re(e.body,t)},we=(e,t,n)=>be(t,e)===n,ke=e=>e.name?.toLowerCase().includes("cssselector")??!1,Re=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:r}=n[e];if(r){const e=Re(r,t);if(e)return e;if(r&&!t.includes("dynamic"))return r.querySelector(t)}}}catch(e){console.log(e)}return null},Te=e=>e?.id||null,Ce=e=>e.className||null,Ae=e=>e.textContent?.trim()||null,Le=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},De=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Pe(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function Oe(e,t,n){if(e.includes(t)){const r=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(r,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let r;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(r=e,r):(console.error("Complete Locator is Invalid:",e),r=e,r)}console.error("Source Locator Not Found:",r)}}return null}const _e=(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 r=new Set;let a=[];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}`;r.has(t)||(r.add(t),a.push(e))}(l)}function l(e,t,n){if(ke(t))return be(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+V(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=V(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 r=Pe(e,H(n));return r&&o(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),r}}function s(e,t,n){const r=e.querySelectorAll("iframe");for(const e of r)try{const r=e.contentDocument||e.contentWindow?.document;if(!r)continue;const a=l(r,t,n);if(a)return a}catch{continue}return null}const i=(e,t,n)=>{if(!e)return null;let r=e.trim();return r&&"null"!==r.toLowerCase()?(r=r.replace(/\\"/g,'"').replace(/\\'/g,"'"),r=r.replace(/^['"](.+?)['"]$/,"$1"),r=r.replace(/''/g,"'"),r=r.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(r=r.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!r||/^['"]{2}$/.test(r)?null:r: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 r=e.trim();if(c=l(t,n,r),c||(c=s(t,n,r)),c||(c=Re(t.body,r)),!c){console.error("Element not found at:",r);break}}const f=(e,t)=>{const n=`${e}:${t}`;return r.has(n)};if(c){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),r=e.locators.filter(e=>ke(e)&&e.value);for(const e of n)Se(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of r)we(e.value,t,c)&&o(e,{isSelfHealed:null});const l=a.filter(e=>"xpath"===e.name&&e.value),s=new Set(l.map(e=>I(e.value))),u=[],d=Te(c);if(d&&!f("id",d)&&!m(d)){const n=e.locators.find(e=>"id"===e.name);q(t,"id",d,c)&&(u.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:d}))}const h=c.tagName;if(h&&!f("tagName",h)){const n=e.locators.find(e=>"tagName"===e.name);q(t,"tagName",h,c)&&(u.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:h}))}const g=Ae(c);if(g&&!m(g)){const n=e.locators.find(e=>"linkText"===e.name);q(t,"linkText",g,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const p=Le(c);if(p&&!f("name",p)&&!m(p)){const n=e.locators.find(e=>"name"===e.name);q(t,"name",p,c)&&(u.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=Ce(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!m($)){const n=e.locators.find(e=>"className"===e.name);q(t,"className",$,c)&&(u.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}$e(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=he(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Se(e.value,t,c));let r=0;for(const t of e){if(r>=e.length)break;const n=I(t.value);if(s.has(n))continue;const a=v.find(e=>e.value&&I(e.value)===n);a?.value&&(o(t,{name:"xpath",value:a.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),r++)}if(r<e.length)for(const t of v){if(r>=e.length)break;if(!t.value)continue;const n=I(t.value);s.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),r++)}}for(const n of e.locators)try{for(const r of e.locators)if(r.value)for(const e of De)if(r.value.includes(e)){const a=Oe(r.value,e,t);if(a){o(r,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(a.length<5){const e=[{name:"id",value:Te(c)},{name:"name",value:Le(c)},{name:"className",value:Ce(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Ae(c)}];for(const n of e){if(a.length>4)break;const{name:e,value:r}=n;r&&(m(r)||f(e,r)||"className"===e&&r.includes(" ")||q(t,e,r,c)&&o(void 0,{name:e,type:"static",value:r,isRecorded:"Y",isSelfHealed:"Y"}))}a.length<5&&$e(c,"multiple").forEach(e=>{a.length>4||e.value&&(f("cssSelector",e.value)||q(t,"cssSelector",e.value,c)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const E=a.map(e=>({...e,value:i(e.value,e.name,e.isRecorded)})),N=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:E.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};async function ze(){return{fromHTML:async n=>{const r=new e,a=new t(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"dangerously",resources:"usable",virtualConsole:r}),{window:o}=a;global.document=o.document,global.Node=o.Node,global.Element=o.Element,global.HTMLElement=o.HTMLElement,global.SVGElement=o.SVGElement;const l=o.CSS??{};return l.escape||(l.escape=e=>String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")),global.CSS=l,global.XPathResult=o.XPathResult,global.XPathEvaluator=o.XPathEvaluator,{autoHeal:async e=>_e(e,o.document)}}}}export{ze as default};
1
+ import{VirtualConsole as e,JSDOM as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i;let r=new WeakMap;const a=(e,t)=>{const{owner:n,contextNode:a}=(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}})(t);let o=r.get(a);o||(o=new Map,r.set(a,o));const s=o.get(e);if(s)return s;const l=n.evaluate(e,a,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:l.iterateNext(),second:l.iterateNext()};return o.set(e,i),i};let o=[];const s=new WeakMap,l=new Set(["marked-element-temp","marked-element","mark-successfully","flntooltip","flntooltip-bottom","fln-shield","removePointers"]),i=/^(?:(?:ng|ion)-(?:pristine|dirty|valid|invalid|touched|untouched|pending|submitted|focused)|(?:item-)?has-(?:focus|value)|ng-star-inserted|hydrated|md|ios)$/,c=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!l.has(e)).sort(),u=e=>/\d/.test(e||""),f=e=>i.test(e),d=(e,t,n,r=!1)=>{const a=c(t),o=m(e,t,r);return o.length?1===a.length&&1===o.length?[`@class=${N(o[0])}`]:o.map(t=>{const r=$(`contains(@class,${N(t)})`,T(e),e.tagName.toLowerCase());return{token:t,count:_(r,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,${N(e)})`):[]},m=(e,t,n=!1)=>{const r=s.get(e);return c(t).filter(e=>!(r?.has(e)||f(e)||!n&&u(e)))},h=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),g=(e,t)=>t?"class"===e||"className"===e?c(t).join(" "):t.replace("removePointers","").trim():"",p=e=>/\d/.test(e),$=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,y=e=>{const t=e?.textContent;return t},v=(e,t,n,r=!1)=>{try{if(S(n)){const{owner:a,contextNode:o,cloneElement:s,cloneElements:l}=k(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===s?1:0;if(r&&Array.isArray(t)){let e,t=0;if(l.includes(c)&&t++,l.includes(u)&&t++,2===t)return 2;for(;e=i.iterateNext();)if(l.includes(e)&&(t++,2===t))return 2;return 0}return 2}const{first:o,second:s}=a(e,n);if(!o)return 0;if(!s)return o===t?1:0;if(r&&Array.isArray(t)){let r=0;if(t.includes(o)&&r++,t.includes(s)&&r++,2===r)return 2;const a=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let l;for(;l=a.iterateNext();)if(t.includes(l)&&(r++,2===r))return 2;return 0}return 2}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},N=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},x=e=>e?e.replace(/\s\s+/g," ").trim():e,E=(e,t)=>{const n=x((t||"").trim());if(!e.children.length||n.length<=50)return"";const r=n.split(/\s+/).slice(0,3).join(" ");return r.length>2?`contains(normalize-space(.),${N(r)})`:""},b=e=>{const t=x((e||"").trim());if(!t||!u(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),r=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:r.length>2?r:""}},w=e=>b(e).fragment,S=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,k=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),r=n.createElement("div");r.innerHTML=e.innerHTML,n.body.appendChild(r);const a=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let r=t;for(;r&&r.parentElement;){const e=r.parentElement;n.unshift(Array.from(e.children).indexOf(r)),r=e}return r&&r.parentNode===e?(n.unshift(Array.from(e.children).indexOf(r)),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})(r,n):null},o=Array.isArray(t)?t.map(e=>a(e)).filter(Boolean):[],s=Array.isArray(t)?null:a(t??null);return{owner:n,contextNode:r,cloneElement:s,cloneElements:o}},R=(e,t,n)=>{const r=g(e.name,e.value);if(!r||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(e=>e===r))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;if("class"===e.name||"className"===e.name){const n=s.get(t);return c(e.value).filter(e=>!n?.has(e)&&!f(e)&&!u(e)).length>0}const a=o?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return console.log("[ff-dom] checking attribute",o,{attribute:e,isModified:a}),!a&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(l=e.name,i=r,(!h.has(l.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(i))&&("class"===e.name||!u(r)))));var l,i},T=e=>e instanceof SVGElement,A=(e,t,r,a,o,s)=>{if(a){const{tagName:l}=e;let i,c="";const f=[];let m;const h=r.startsWith("@"),g="."===r||"text()"===r,y=g?".":r,b=g&&/\s/.test(a.trim()),S=g?w(a):a,k=g&&u(a)?S:a,R=g?E(e,k):"";if("@class"===r){for(const n of d(e,a,t))if(m=$(n,T(e),e.tagName.toLowerCase()),i=v(m,e,t),1===i&&!o)return m;return}if(g&&u(a)&&!S)return;if(a&&(!h||!p(a))&&(m=R?$(R,T(e),e.tagName.toLowerCase()):b?$(`normalize-space(${y})=${N(x(k)).trim()}`,T(e),e.tagName.toLowerCase()):n.test(a)?`//${l}[${r}=${N(k)}]`:$(`normalize-space(${r})=${N(x(k)).trim()}`,T(e),e.tagName.toLowerCase()),i=v(m,e,t),1===i&&!o))return m;if(h&&u(a))return;if(a&&s){const s=a.split(" ");if(s?.length)if(1===s.length){const u=[...new Set(s[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&x(u[0].trim())?.length>1&&a.startsWith(u[0])&&(c=n.test(u[0])?`starts-with(${r},${N(u[0]).trim()})`:`starts-with(${r},${N(x(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&x(u[u.length-1].trim())?.length>1&&a.endsWith(u[u.length-1])&&(c=n.test(u[u.length-1])?`ends-with(${r},${N(u[u.length-1]).trim()})`:`ends-with(${r},${N(x(u[u.length-1])).trim()})`),c?.length&&(m=T(e)?`//*[local-name()='${l}' and ${c}]`:`//${l}[${c}]`,i=v(m,e,t),1===i&&!o))return m}else{const u=s.length%2==0?s.length/2:s.length%2,f=s.slice(0,u).join(" ");let d=[...new Set(f.match(/([^0-9]+)/g))];if(d?.length&&d[0]&&x(d[0].trim())?.length&&a.startsWith(d[0])&&(c=n.test(d[0])?`starts-with(${r},${N(d[0]).trim()})`:`starts-with(${r},${N(x(d[0])).trim()})`),c?.length&&(m=T(e)?`//*[local-name()='${l}' and ${c}]`:`//${l}[${c}]`,i=v(m,e,t),1===i&&!o))return m;const h=s.slice(u,s.length-1).join(" ");if(d=[...new Set(h.match(/([^0-9]+)/g))],d?.length&&d[0]&&x(d[0].trim())?.length>3&&a.endsWith(d[0])&&(c=n.test(d[0])?`ends-with(${r},${N(d[0]).trim()})`:`ends-with(${r},${N(x(d[0])).trim()})`),c?.length&&(m=T(e)?`//*[local-name()='${l}' and ${c}]`:`//${l}[${c}]`,i=v(m,e,t),1===i&&!o))return m}}if(a&&s&&p(a)){const s=[...new Set(a.match(/([^0-9]+)/g))];if(s?.length)for(let e=0;e<s?.length;e++)s[e]&&x(s[e].trim())?.length>1&&(n.test(s[e])?f.push(`contains(${r},${N(s[e].trim()).trim()})`):f.push(`contains(${r},${N(x(s[e])).trim()})`));if(f?.length&&(m=T(e)?`//*[local-name()='${l}' and ${f.join(" and ")}]`:`//${l}[${f.join(" and ")}]`,i=v(m,e,t),1===i&&!o))return m}if(m=T(e)?`//*[local-name()='${l}' and text()]`:`//${l}[text()]`,i=v(m,e,t),1===i&&!o)return m}},C=(e,t,r,a)=>{try{const a=r.filter(t=>R(t,e)),o=r=>{const a=g(r.name,r.nodeValue);return a?"class"===r.name?d(e,a,t):u(a)?[]:n.test(a)?[`@${r.name}="${a}"`]:[`normalize-space(@${r.name})="${a}"`]:[]},s=e=>{const t=o(e);return"class"===e.name?t.map(e=>[e]):t.length?[t]:[]},l=e=>e.reduce((e,t)=>{const n=s(t);return n.length?e.flatMap(e=>n.map(t=>[...e,...t])):[]},[[]]),i=()=>{const t=x(y(e)?.trim()||""),r=w(t);if(u(t))return r?[`contains(normalize-space(.),${N(r)})`]:[];if(!t||t.length>80||/^\d+$/.test(t)){const n=E(e,t);return n?[n]:[]}const a=new Set,o=E(e,t);return o?(a.add(o),Array.from(a)):(n.test(t)&&t.length<=40&&!t.includes(" ")&&a.add(`text()=${N(t)}`),t.includes(" ")&&a.add(`normalize-space(.)=${N(x(t))}`),a.add(`contains(text(),${N(t)})`),Array.from(a))},c=(e,t)=>{const n=[],r=(a,o)=>{if(o.length!==t)for(let t=a;t<e.length;t++)o.push(e[t]),r(t+1,o),o.pop();else n.push([...o])};return r(0,[]),n},f=t=>T(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,m=(()=>{if(!(a.length<2))for(let n=2;n<=a.length;n++){const r=c(a,n);for(const n of r){const r=l(n);for(const n of r){if(n.length<2)continue;const r=f(n);let a;try{a=v(r,e,t)}catch{continue}if(1===a)return r}}}})();if(m)return m;const h=i();if(!h.length||!a.length)return;for(let n=1;n<=a.length;n++){const r=c(a,n);for(const n of r){const r=l(n);for(const n of r)if(n.length)for(const r of h){const a=[...n,r],o=f(a);try{if(1===v(o,e,t))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},L=(e,t)=>{if(!e.textContent)return"";const r=(a=e,a?.childNodes[0]?.nodeValue||"");var a;const o=w(r);if(u(r)&&!o)return"";const s=u(r)?o:r,l=E(e,s);let i;return i=l?$(l,T(e),e.tagName||"*"):u(r)?$(`contains(normalize-space(.),${N(s)})`,T(e),e.tagName||"*"):!n.test(r)||/\s/.test(r.trim())?$(`normalize-space(.)=${N(s)}`,T(e),e.tagName||"*"):T(e)?`//*[local-name()='${e.tagName}' and .=${N(s)}]`:`//${e.tagName||"*"}[.=${N(s)}]`,i},D=(e,t,n)=>{if("@class"===t){const t=m(e,n);return 1===c(n).length&&1===t.length?$(`normalize-space(@class)=${N(t[0])}`,T(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&u(n))return"";if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=b(n);return t?$(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return $(`normalize-space(${t})=${N(x(n)).trim()}`,T(e),e.tagName.toLowerCase())},O=(e,t,n)=>{if("@class"===t){const t=m(e,n);return 1===t.length?$(`starts-with(normalize-space(@class),${N(t[0])})`,T(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&u(n))return"";if(("."===t||"text()"===t)&&u(n)){const{prefix:t,fragment:r}=b(n),a=t||r;return a?$(`starts-with(normalize-space(.),${N(a)})`,T(e),e.tagName.toLowerCase()):""}return $(`starts-with(${t},${N(x(n)).trim()})`,T(e),e.tagName.toLowerCase())},z=(e,t,n)=>{if("@class"===t){const t=m(e,n);return 1===t.length?$(`contains(@class,${N(t[0])})`,T(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&u(n))return"";if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=b(n);return t?$(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return $(`contains(${t},${N(x(n)).trim()})`,T(e),e.tagName.toLowerCase())},P=(e,t)=>{const r=t.flatMap(t=>(t=>{const r=g(t.name,t.value);if(!r)return[];if("class"===t.name){const t=e.getRootNode?.()??e.ownerDocument;return d(e,r,t)}return u(r)?[]:n.test(r)?[`@${t.name}=${N(r)}`]:[`normalize-space(@${t.name})=${N(r)}`]})(t)).filter(Boolean);if(r.length>=2)return $(`${r[0]} or ${r[1]}`,T(e),e.tagName.toLowerCase());const a=(()=>{const t=x(y(e)?.trim()||""),r=w(t);if(u(t))return r?`contains(normalize-space(.),${N(r)})`:null;const a=E(e,t);return a||(!t||t.length>80||/^\d+$/.test(t)?null:n.test(t)&&t.length<=40&&!t.includes(" ")?`text()=${N(t)}`:t.includes(" ")?`normalize-space(.)=${N(t)}`:`contains(text(),${N(t)})`)})();return 1===r.length&&a?$(`${r[0]} or ${a}`,T(e),e.tagName.toLowerCase()):""},_=(e,t,n)=>{try{return v(e,t,n)}catch(e){return 0}},Y=(e,t)=>{const n=[],r=new Set,a=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"],s=[...o.map(e=>a.find(t=>t.name===e)).filter(Boolean),...a.filter(e=>!o.includes(e.name))],l=a=>{a&&!r.has(a)&&q(a,e,t)&&(r.add(a),n.push(a))};s.forEach(t=>{if(R(t,e))for(const n of W(e,t.name,t.value))l(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=L(e);t&&l(t)}if(a.length>1){const n=C(e,t,a);n&&l(n)}return n},X=(e,t)=>{const n=[];let r=t;for(;r&&r!==e;)n.unshift(H(r)),r=r.parentElement;return r===e?n.join("/"):""},M=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),r=H(e),a=T(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const a=Y(t,n);for(const o of a){console.log(`Trying ancestor XPath: ${o}`);const a=`${o}/descendant::${r}`;console.log(`Trying descendant XPath: ${a}`);const s=_(a,e,n);if(console.log(`Match count: ${s}`),1===s&&j(a,n)===e)return console.log(`Selected XPath: ${a}`),a;const l=X(t,e);if(l){const t=`${o}/${l}`;console.log(`Trying descendant XPath: ${t}`);const r=_(t,e,n);if(console.log(`Match count: ${r}`),1===r&&j(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${a}`);const o=_(a,e,n);return console.log(`Match count: ${o}`),1===o&&j(a,n)===e?(console.log(`Selected XPath: ${a}`),a):(console.log("Selected XPath: "),"")},j=(e,t)=>{try{if(S(t)){const{owner:n,contextNode:r,cloneElement:a}=k(t);return n.evaluate(e,r,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||a}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},q=(e,t,n)=>{try{const{first:r,second:o}=a(e,n);return!!r&&!o&&r===t}catch{return!1}},H=e=>T(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),I=(e,t,n)=>{if(!(e instanceof Element))return[];const r=new Set,a=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(n=t.value,!/\d/.test(n))&&R(t,e);var n}),s=(e,t)=>{t&&!r.has(t)&&(r.add(t),a.push({key:e,value:t}))},l=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"];l.forEach(n=>{const r=o.find(e=>e.name===n);if(r)for(const n of W(e,r.name,r.value))n&&q(n,e,t)&&s(`anchor by ${r.name}`,n)}),o.forEach(n=>{if(!l.includes(n.name))for(const r of W(e,n.name,n.value))r&&q(r,e,t)&&s(`anchor by ${n.name}`,r)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=L(e);n&&q(n,e,t)&&s("anchor by text",n)}if(o.length>1){const n=C(e,t,o);n&&q(n,e,t)&&s("anchor by combination",n)}const c=M(e,t);return c&&q(c,e,t)&&s("anchor by tag",c),a},V=e=>{const t=y(e)?.trim(),n=w(t);if(t&&u(t))return n?`contains(normalize-space(.),${N(n)})`:void 0;const r=E(e,t);if(r)return r;const a=t?N((e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(t).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim().split("/")[0].trim()):t;return a?a!==`'${t}'`?`contains(.,${a})`:/\s/.test(t)?`normalize-space(.)='${x(t)}'`:`normalize-space(.)='${t}'`:void 0},W=(e,t,n)=>{const r=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";if(n=g(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return d(e,n,t).map(t=>T(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(u(n))return[];a=r.test(n)?T(e)?`//*[local-name()='${e.tagName}' and @${t}=${N(n)}]`:`//${e.tagName||"*"}[@${t}=${N(n)}]`:T(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${N(n)})]`:`//${e.tagName||"*"}[contains(@${t},${N(n)})]`}return a?[a]:[]},F=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function Z(e){const t=function(e){return e.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e),n=function(e){const t=e.toLowerCase(),n=t.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),r=n?.[1]??"none",a=t.match(/@([a-z0-9:-]+)/);return{axis:r,attribute:a?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function B(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function G(e,t,n,r){const a=r?.getRootNode?.()??e,o=e=>{try{return Array.from(a.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===o(`#${B(n)}`).length;case"name":return 1===o(`[name="${B(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}}let U=[];const J={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},K=e=>J[e]||e,Q=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),ee=e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value))&&(t.add(e.value),!0))},te=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const r=e[n];if(t){r===t&&(t=null);continue}if("'"===r||'"'===r){t=r;continue}if("["!==r)continue;const a=e.indexOf("]",n+1);if(-1===a)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,a)))return!0}return!1})(e.value)),ne=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",re=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},ae=(e,t)=>{const n=[];let r="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;r;)r.classList?.contains("flntooltip")||n.push(r),r="previous"===t?r.previousElementSibling:r.nextElementSibling;return n},oe=(e,t)=>{const n=[];for(let r=e;r?.parentElement;r=r.parentElement){let e="previous"===t?r.previousElementSibling:r.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>re(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},se=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},le=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},ie=(e,t,n,r,a,o,s)=>{const l=V(n),i=l?`${H(n)}[${l}]`:H(n),c=[];let u=0;const f=t.includes("descendant")?10:20;for(const a of e){if(u++>f)break;if(c.length>=5)break;const e="node"in a?a.node:a;if(!(e instanceof Element))continue;if(se(e))continue;const l=[()=>I(e,r),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&R(t,e));for(const r of n){const n=r.value;if(!n)continue;const a=z(e,`@${r.name}`,n);a&&t.push({key:"contains",value:a});const o=O(e,`@${r.name}`,n);o&&t.push({key:"starts-with",value:o})}return t},()=>[{key:"tag",value:M(e,r)}]];for(let a=0;a<l.length;a++){let u=l[a]();if(!u.length)continue;s||(u=u.filter(e=>!/\[\d+\]/.test(e.value)));const f=new Set;u=u.filter(e=>!f.has(e.value)&&(f.add(e.value),!0)),u=u.slice(0,5);for(const e of u){const a=`${e.value}/${t}::${i}`;if(q(a,n,r)){if(c.push({key:o,value:a}),c.length>=2)return c;if(c.length>=5)return c}}if(s&&a===l.length-1)for(const a of u){const s=v(a.value,e,r);for(let e=1;e<=Math.min(s,3);e++){const s=`(${a.value})[${e}]/${t}::${i}`;if(q(s,n,r)){if(c.push({key:o,value:s}),c.length>=2)return c;if(c.length>=5)return c}}}}if("expand"in a&&a.expand){const e=a.expand();let s=0;for(const a of e){if(s++>15)break;if(c.length>=5)break;if(!(a instanceof Element))continue;if(se(a))continue;const e=I(a,r);for(const a of e.slice(0,5)){const e=`${a.value}/${t}::${i}`;if(q(e,n,r)){if(c.push({key:o,value:e}),c.length>=2)return c;if(c.length>=5)return c}}}}}return c},ce=(e,t)=>{const n=[];let r=e;for(;r&&n.length<t;)n.push(r),r=r.parentElement;return n},ue=(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""},fe=(e,t)=>{const n=[];for(let r=e;r&&r!==t;r=r.parentElement){const e=r.parentElement;if(!e)return"";n.push(`/parent::${H(e)}`)}return n.join("")},de=(e,t)=>{const n=H(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},me=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))};for(let n=e.parentElement,a=0;n&&a<4&&t.length<20;n=n.parentElement,a++){const e=[ae(n,"previous").slice(0,4),ae(n,"next").slice(0,4)];for(const t of e)for(const e of t){r(e);let t=0;for(const n of re(e).sort((e,t)=>le(t)-le(e))){if(t++>=8)break;r(n)}}}return t.sort((e,t)=>le(t)-le(e)).slice(0,20)})(e),s=ce(e.parentElement,3);for(const n of o){const o=I(n,t).filter(e=>"anchor by tag"!==e.key).slice(0,2);if(!o.length)continue;const l=ce(n,3);for(const i of o)for(const o of l){const l=fe(n,o);if(o===n||l)for(const n of s){if(!n||!n.contains(e))continue;const s=ue(o,n);if(!s)continue;const c=`/${s}::${H(n)}`;for(const o of de(n,e)){const n=`${i.value}${l}${c}${o}`;if(!a.has(n)&&(a.add(n),q(n,e,t)&&(r.push({key:"chained axes fallback",value:n}),r.length>=2)))return r}}}}return r},he=e=>{const t=H(e),n=e.textContent?.trim(),r=(e=>{const t=w(e);return t||(e||"").split(/[^a-zA-Z]+/).map(e=>e.trim()).filter(e=>e.length>2).pop()})(n),a=V(e),o=[];return r&&r!==n&&o.push(`${t}[contains(text(),${N(r)})]`),a&&o.push(`${t}[${a}]`),o.push(t),Array.from(new Set(o))},ge=(e,t,n)=>{const r=y(e)?.trim(),a=[];if(r&&r.length>2&&r.length<40&&!u(r)){const t=`//${e.tagName}[.=${N(r)}]`;a.push({key:"anchor by text",value:t})}return[...a,...I(e,t).filter(e=>"anchor by tag"!==e.key)]},pe=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))},a=e=>{for(const t of[e,...re(e)]){const e=y(t)?.trim();e&&e.length<40&&!u(e)&&0===t.children.length&&r(t)}};for(let n=e.parentElement,o=0;n&&o<4&&t.length<30;n=n.parentElement,o++){const e=ae(n,"previous").reverse(),t=ae(n,"next");for(const n of[...e,...t])a(n),r(n)}return t.slice(0,30)})(e),s=he(e);for(const n of o){const o=ge(n,t).slice(0,2);if(o.length)for(const l of o)for(const o of ce(n.parentElement,5)){if(!o.contains(e))continue;const n=`/ancestor::${H(o)}`;for(const o of s){const s=`${l.value}${n}/descendant::${o}`;if(!a.has(s)&&(a.add(s),q(s,e,t)&&(r.push({key:"ancestor descendant bridge",value:s}),r.length>=1)))return r}}}return r},$e=(e,t)=>{const n=[];for(let r=t;r&&r!==e;r=r.parentElement)n.unshift(H(r));if(!n.length)return"";const r=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${r}`},ye=(e,t,n,r)=>{const a=new Set,o=[],s=(e,t)=>{t&&!a.has(t)&&(!r&&/\[\d+\]/.test(t)||(a.add(t),o.push({key:e,value:t})))};return I(e,t).filter(e=>"anchor by tag"!==e.key).forEach(e=>s(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)||!u(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 r=z(e,`@${t.name}`,n);s(`anchor by stable ${t.name}`,r)}),o},ve=(e,t,n,r)=>{const a=[];for(let t=e.parentElement;t;t=t.parentElement)a.push(t);const o=re(e),s=ae(e,"previous"),l=ae(e,"next"),i=oe(e,"previous"),c=oe(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(l),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(s),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(a),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(a),axis:"descendant",key:"descendant"},{nodes:u(a),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"}]],d=((e,t,n,r)=>{const a=[],o=new Set;for(let n=e.parentElement,s=0;n&&s<8;n=n.parentElement,s++){const s=$e(n,e);if(!s)continue;const l=ye(n,t,0,r);for(const n of l.slice(0,3)){const r=`${n.value}${s}`;if(!o.has(r)&&(o.add(r),q(r,e,t)&&(a.push({key:"child chain",value:r}),a.length>=2)))return a}}return a})(e,t,0,r);if(d.length)return d;for(const n of f)for(const a of n){const n=ie(a.nodes,a.axis,e,t,0,a.key,r);if(n.length>0)return n}const m=pe(e,t);return m.length?m:me(e,t)||[]},Ne=(e,t,n,r,a)=>{const o=K(r);return"text"===o?Q(r,((e,t,n)=>{if(!ne(e))return[];if("text"===n){const n=L(e)||xe(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?Q(r,((e,t,n,r)=>{const a=[],o=Array.from(e.attributes||[]).filter(t=>t?.value&&R(t,e)),s=ne(e),l="contains"===r?z:"startsWith"===r?O:"normalizeSpace"===r?D:null;if(!l)return a;if("contains"===r&&s)for(const n of["text()","."]){const a=l(e,n,s);if(a&&1===v(a,e,t))return[{key:`xpath by ${r} text`,value:a}]}if(o.forEach(n=>{if("class"===n.name)return void d(e,n.value,t).forEach(t=>{const n=$(t,T(e),e.tagName.toLowerCase());n&&a.push({key:`xpath by ${r} class`,value:n})});const o=l(e,`@${n.name}`,n.value);o&&a.push({key:`xpath by ${r} ${n.name}`,value:o})}),"contains"===r&&a.length){const n=a.find(n=>1===v(n.value,e,t));return n?[n]:[]}if(s){const t=l(e,".",s);t&&a.push({key:`xpath by ${r} text`,value:t})}return a})(e,t,0,o)):["and","or"].includes(o)?Q(r,((e,t,n,r)=>{const a=Array.from(e.attributes||[]).filter(t=>t?.value&&R(t,e));if("and"===r){const n=C(e,t,a);return n?[{key:"xpath by combination",value:n}]:[]}if("or"===r&&a.length>=1){const t=P(e,a);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,0,o)):"axes"===o?Q(r,ve(e,t,0,!1)):"index"===o?Q(r,((e,t)=>{const n=[],r=e.tagName.toLowerCase(),a=Array.from(t.querySelectorAll(r)).indexOf(e)+1;if(a<=0)return[];n.push({key:"xpath by index",value:`(//${r})[${a}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?W(o,"id",o.id):W(o,"class",o.className.toString());for(const a of t){const t=Array.from(o.querySelectorAll(r)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${a}//${r})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?Q(r,[{key:"xpath till tag",value:M(e,t)}]):[]};const xe=(e,t,n,r)=>{if(""!=(e.textContent??"").trim()){const a=y(e);if(a)return A(e,t,"text()",a,n,r)||A(e,t,".",a,n,r)}},Ee=(e,t,n,r,a)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&R(e,t)){const o=((e,t,n,r,a)=>{let o;if(o=e.name,R(e,t))return A(t,n,`@${o}`,e.value,r,a)})(e,t,n,r,a);o&&U.push({key:`xpath by ${e.name}${r?" index":""}`,value:o})}});const s=xe(t,n,r,a);if(s&&U.push({key:"xpath by text"+(r?" index":""),value:s}),o.find(e=>["className","class"].includes(e.name))&&R(o?.find(e=>["className","class"].includes(e.name)),t)){let e=((e,t,n,r)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=g("class",a),a=a?.trim(),a&&R({name:"class",value:a},e))return A(e,t,"@class",a,n,r)})(t,n,r,a);e&&U.push({key:"xpath by class",value:e})}if(!U.length&&o.length>1){const e=C(t,n,o);e&&U.push({key:"xpath by combination",value:e})}if(!U.length){const r=function(e,t,n){const{tagName:r}=t,a=t.textContent.trim();if(!a)return;const o=x(a),s=w(o);if(u(o)&&!s)return;const l=u(o)?s:o,i=E(t,l);for(const s of e)if(R(s,t)){let e=g(s.name,s.nodeValue);const c=`//${r}[@${s.name}='${e}' and ${i||(u(o)?`contains(normalize-space(.),${N(l)})`:/\s/.test(a)?`normalize-space(.)=${N(l)}`:`text()=${N(l)}`)}]`;if(c&&1==v(c,t,n))return c}}(e,t,n);r&&U.push({key:"xpath by textAttribute",value:r})}}catch(e){console.log(e)}},be=(e,t,n,r,a=[],o=[])=>{U=[],console.log(e);const s=e,l=s?.getRootNode?.(),i=l?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,c=i?l:s?.ownerDocument||t,u=s.tagName,{attributes:f}=s,d=a.length>0?a:Array.from(f);if(Ee(d,s,c,n,r),o.length){const e=n||((e=[])=>e.some(e=>"index"===K(e)))(o),t=o.flatMap(e=>Ne(s,c,0,e));return U=ee(t.filter(e=>1===v(e.value,s,c))),te(U,e)}if(U.length){const t=U.length;for(let n=0;n<t;n++){let t=U[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===v(t,e,c)&&U.push({key:`${U[n].key} regex`,value:t})}}return U.length||i||(U=ve(s,c,0,n)),te(ee(U),n)},we=["data-testid","data-test-id","data-test","data-cy","data-qa","name","aria-label","aria-labelledby","placeholder","title","alt","role"],Se=new Set(["id","class","style"]),ke=(e,t)=>{const n=t?.ownerDocument?.defaultView?.CSS??globalThis.CSS;return n?.escape?n.escape(e):String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")},Re=e=>{if(!e)return!1;const t=e.ownerDocument?.defaultView;return Boolean(t&&e instanceof t.Element)},Te=e=>{const t=e.tagName.toLowerCase();return"style"===t||"script"===t},Ae=e=>{const t=e.trim();return Boolean(t)&&t.length<=120&&!/^\d+$/.test(t)},Ce=(e,t,n)=>{try{const r=n.querySelectorAll(e);return 1===r.length&&r[0]===t}catch{return!1}},Le=(e,t,n)=>{n&&!e.some(e=>e.value===n)&&e.push({key:t,value:n})},De=(e,t="single")=>{const n=[],r=e.getRootNode();try{const a=Oe(e);if(a&&Ce(a,e,r)&&(Le(n,"cssSelector by id",a),"single"===t))return n;const o=Pe(e);if(o&&(Le(n,"cssSelector by attribute",o),"single"===t))return n;const s=_e(e);if(s&&Ce(s,e,r)&&(Le(n,"cssSelector by class",s),"single"===t))return n;const l=Me(e);if(l&&Ce(l,e,r)&&(Le(n,"cssSelector by stable parent",l),"single"===t))return n;if("multiple"===t&&0===n.length){const t=qe(e);t&&Ce(t,e,r)&&Le(n,"cssSelector by position fallback",t)}}catch(e){console.error(e)}return n},Oe=e=>{if(!Re(e)||Te(e))return;const t=e.getAttributeNode("id");return t&&Ae(t.value)&&R(t,e)?`#${ke(e.id,e)}`:void 0};function ze(e,t=!1){const n=Array.from(e.attributes).filter(n=>{const r=n.name.toLowerCase();return!Se.has(r)&&(!(t&&!we.includes(r))&&(Ae(n.value)&&R(n,e)))});return n.sort((e,t)=>{const n=we.indexOf(e.name.toLowerCase()),r=we.indexOf(t.name.toLowerCase());return(-1===n?999:n)-(-1===r?999:r)}),n.map(e=>{return`[${e.name}="${t=e.value.trim(),String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Pe=e=>{if(!Re(e)||Te(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase(),r=ze(e);for(const a of r){if(Ce(a,e,t))return a;const r=`${n}${a}`;if(Ce(r,e,t))return r}},_e=e=>{if(!Re(e)||Te(e))return;const t=Ye(e);if(!t)return;const n=e.getRootNode(),r=`${e.tagName.toLowerCase()}${t}`;return Ce(t,e,n)?t:Ce(r,e,n)?r:void 0},Ye=e=>{if("string"!=typeof e.className||!e.className||o?.find(t=>t.element===e&&"class"===t.attributeName))return;const t=m(e,e.className).filter(Ae);return t.length?t.slice(0,3).map(t=>`.${ke(t,e)}`).join(""):void 0},Xe=(e,t={})=>{if(!Re(e)||Te(e))return[];const n=[],r=e.tagName.toLowerCase(),a=Oe(e);a&&n.push(a);for(const a of ze(e,t.preferredAttributesOnly))n.push(a),t.includeTag&&n.push(`${r}${a}`);const o=Ye(e);return o&&(n.push(o),t.includeTag&&n.push(`${r}${o}`)),Array.from(new Set(n))},Me=e=>{if(!Re(e)||Te(e))return;const t=e.getRootNode(),n=Xe(e,{includeTag:!0,preferredAttributesOnly:!1});let r=e.parentElement;for(;r&&Re(r)&&!Te(r);){const a=Xe(r,{includeTag:!0,preferredAttributesOnly:!0});for(const o of a)if(Ce(o,r,t))for(const r of n){const n=`${o} ${r}`;if(Ce(n,e,t))return n;const a=`${o} > ${r}`;if(Ce(a,e,t))return a}r=r.parentElement}},je=e=>{let t=1,n=e.previousElementSibling;for(;n;)n.tagName===e.tagName&&t++,n=n.previousElementSibling;return t},qe=e=>{if(!Re(e)||Te(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase();let r=e.parentElement;for(;r&&Re(r)&&!Te(r);){const a=Xe(r,{includeTag:!0,preferredAttributesOnly:!0});for(const o of a){if(!Ce(o,r,t))continue;const a=`${o} > ${n}:nth-of-type(${je(e)})`;if(Ce(a,e,t))return a}r=r.parentElement}return He(e)},He=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 r=t;const a=e.parentNode;if(a){const t=Array.from(a.children).filter(t=>t.tagName===e.tagName);t.length>1&&(r+=`:nth-of-type(${t.indexOf(e)+1})`)}n.unshift(r),e=e.parentElement}return n.join(" > ")},Ie=(e,t,n)=>{const r=F(e);if(Qe(t,r)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(r)){const e=t.evaluate(r,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},Ve=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Ze(e.body,t)},We=(e,t,n)=>Ve(t,e)===n,Fe=e=>e.name?.toLowerCase().includes("cssselector")??!1,Ze=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:r}=n[e];if(r){const e=Ze(r,t);if(e)return e;if(r&&!t.includes("dynamic"))return r.querySelector(t)}}}catch(e){console.log(e)}return null},Be=e=>e?.id||null,Ge=e=>e.className||null,Ue=e=>e.textContent?.trim()||null,Je=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Ke=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Qe(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 et(e,t,n){if(e.includes(t)){const r=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(r,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let r;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(r=e,r):(console.error("Complete Locator is Invalid:",e),r=e,r)}console.error("Source Locator Not Found:",r)}}return null}const tt=(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 r=new Set;let a=[];function o(e,t={}){const n=e?.value,o=t.value??e?.value,s={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},l="Y"===e?.isSelfHealed;s.isSelfHealed=l?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(s.name,n,o),function(e){const t=`${e.name}:${e.value}`;r.has(t)||(r.add(t),a.push(e))}(s)}function s(e,t,n){if(Fe(t))return Ve(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+B(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=B(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 r=Qe(e,F(n));return r&&o(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),r}}function l(e,t,n){const r=e.querySelectorAll("iframe");for(const e of r)try{const r=e.contentDocument||e.contentWindow?.document;if(!r)continue;const a=s(r,t,n);if(a)return a}catch{continue}return null}const i=(e,t,n)=>{if(!e)return null;let r=e.trim();return r&&"null"!==r.toLowerCase()?(r=r.replace(/\\"/g,'"').replace(/\\'/g,"'"),r=r.replace(/^['"](.+?)['"]$/,"$1"),r=r.replace(/''/g,"'"),r=r.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(r=r.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!r||/^['"]{2}$/.test(r)?null:r: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 r=e.trim();if(c=s(t,n,r),c||(c=l(t,n,r)),c||(c=Ze(t.body,r)),!c){console.error("Element not found at:",r);break}}const f=(e,t)=>{const n=`${e}:${t}`;return r.has(n)};if(c){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),r=e.locators.filter(e=>Fe(e)&&e.value);for(const e of n)Ie(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of r)We(e.value,t,c)&&o(e,{isSelfHealed:null});const s=a.filter(e=>"xpath"===e.name&&e.value),l=new Set(s.map(e=>Z(e.value))),u=[],d=Be(c);if(d&&!f("id",d)&&!p(d)){const n=e.locators.find(e=>"id"===e.name);G(t,"id",d,c)&&(u.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:d}))}const m=c.tagName;if(m&&!f("tagName",m)){const n=e.locators.find(e=>"tagName"===e.name);G(t,"tagName",m,c)&&(u.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:m}))}const h=Ue(c);if(h&&!p(h)){const n=e.locators.find(e=>"linkText"===e.name);G(t,"linkText",h,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:h}))}const g=Je(c);if(g&&!f("name",g)&&!p(g)){const n=e.locators.find(e=>"name"===e.name);G(t,"name",g,c)&&(u.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:g}))}const $=Ge(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!p($)){const n=e.locators.find(e=>"className"===e.name);G(t,"className",$,c)&&(u.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}De(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=be(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Ie(e.value,t,c));let r=0;for(const t of e){if(r>=e.length)break;const n=Z(t.value);if(l.has(n))continue;const a=v.find(e=>e.value&&Z(e.value)===n);a?.value&&(o(t,{name:"xpath",value:a.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),l.add(n),r++)}if(r<e.length)for(const t of v){if(r>=e.length)break;if(!t.value)continue;const n=Z(t.value);l.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),l.add(n),r++)}}for(const n of e.locators)try{for(const r of e.locators)if(r.value)for(const e of Ke)if(r.value.includes(e)){const a=et(r.value,e,t);if(a){o(r,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(a.length<5){const e=[{name:"id",value:Be(c)},{name:"name",value:Je(c)},{name:"className",value:Ge(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Ue(c)}];for(const n of e){if(a.length>4)break;const{name:e,value:r}=n;r&&(p(r)||f(e,r)||"className"===e&&r.includes(" ")||G(t,e,r,c)&&o(void 0,{name:e,type:"static",value:r,isRecorded:"Y",isSelfHealed:"Y"}))}a.length<5&&De(c,"multiple").forEach(e=>{a.length>4||e.value&&(f("cssSelector",e.value)||G(t,"cssSelector",e.value,c)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=a.map(e=>({...e,value:i(e.value,e.name,e.isRecorded)})),x=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:N.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return x}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};async function nt(){return{fromHTML:async n=>{const r=new e,a=new t(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"dangerously",resources:"usable",virtualConsole:r}),{window:o}=a;global.document=o.document,global.Node=o.Node,global.Element=o.Element,global.HTMLElement=o.HTMLElement,global.SVGElement=o.SVGElement;const s=o.CSS??{};return s.escape||(s.escape=e=>String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")),global.CSS=s,global.XPathResult=o.XPathResult,global.XPathEvaluator=o.XPathEvaluator,{autoHeal:async e=>tt(e,o.document)}}}}export{nt as default};
2
2
  //# sourceMappingURL=xpath.mjs.map