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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cdn.js CHANGED
@@ -1 +1 @@
1
- !function(e){"use strict";const t=/^[\S]+( [\S]+)*$/i;let n=new WeakMap;const a=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=>{n.delete(e)}):n=new WeakMap},r=(e,t)=>{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}})(t);let o=n.get(r);o||(o=new Map,n.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 o,l=new Map,s=[];const i=new Set(["marked-element-temp","removePointers"]),c=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!i.has(e)).sort(),u=e=>/\d/.test(e||""),f=(e,t,n,a=!1)=>{const r=c(t),o=r.filter(e=>!!a||!u(e));return o.length?1===r.length&&1===o.length?[`@class=${N(o[0])}`]:o.map(t=>{const a=p(`contains(@class,${N(t)})`,T(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,${N(e)})`):[]},m=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),d=(e,t)=>t?"class"===e||"className"===e?c(t).join(" "):t.replace("removePointers","").trim():"",g=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(T(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=c(e.oldValue),n=c(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},h=e=>/\d/.test(e),p=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,$=e=>{const t=e?.textContent;return t},y=e=>e?.childNodes[0]?.nodeValue||"",v=(e,t,n,a=!1)=>{try{const{first:o,second:l}=r(e,n);if(!o)return 0;if(!l)return o===t?1:0;if(a&&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}},N=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},b=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},x=(e,t,n,a)=>{try{const r=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===v(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===v(`(${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===v(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===v(`(${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(),w=e=>e?e.replace(/\s\s+/g," ").trim():e,k=(e,t)=>{const n=w((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(.),${N(a)})`:""},S=e=>{const t=w((e||"").trim());if(!t||!u(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),a=n.split(/[^a-zA-Z]+/).map(e=>w(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:""}},C=e=>S(e).fragment,A=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},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(null);return{owner:n,contextNode:a,cloneElement:l,cloneElements:o}},O=(e,t,n)=>{const a=d(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=s?.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,(!m.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(l))&&("class"===e.name||!u(a)))));var o,l},T=e=>e instanceof SVGElement,D=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,P=(e,n,a,r,o,l)=>{if(r){const{tagName:s}=e;let i,c="";const m=[];let d;const g=a.startsWith("@"),$="."===a||"text()"===a,y=$?".":a,b=$&&/\s/.test(r.trim()),x=$?C(r):r,E=$&&u(r)?x:r,S=$?k(e,E):"";if("@class"===a){for(const t of f(e,r,n))if(d=p(t,T(e),e.tagName.toLowerCase()),i=v(d,e,n),1===i&&!o)return d;return}if($&&u(r)&&!x)return;if(r&&(!g||!h(r))&&(d=S?p(S,T(e),e.tagName.toLowerCase()):b?p(`normalize-space(${y})=${N(w(E)).trim()}`,T(e),e.tagName.toLowerCase()):t.test(r)?`//${s}[${a}=${N(E)}]`:p(`normalize-space(${a})=${N(w(E)).trim()}`,T(e),e.tagName.toLowerCase()),i=v(d,e,n),1===i&&!o))return d;if(g&&u(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]&&w(u[0].trim())?.length>1&&r.startsWith(u[0])&&(c=t.test(u[0])?`starts-with(${a},${N(u[0]).trim()})`:`starts-with(${a},${N(w(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&w(u[u.length-1].trim())?.length>1&&r.endsWith(u[u.length-1])&&(c=t.test(u[u.length-1])?`ends-with(${a},${N(u[u.length-1]).trim()})`:`ends-with(${a},${N(w(u[u.length-1])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d}else{const u=l.length%2==0?l.length/2:l.length%2,f=l.slice(0,u).join(" ");let m=[...new Set(f.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&w(m[0].trim())?.length&&r.startsWith(m[0])&&(c=t.test(m[0])?`starts-with(${a},${N(m[0]).trim()})`:`starts-with(${a},${N(w(m[0])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d;const g=l.slice(u,l.length-1).join(" ");if(m=[...new Set(g.match(/([^0-9]+)/g))],m?.length&&m[0]&&w(m[0].trim())?.length>3&&r.endsWith(m[0])&&(c=t.test(m[0])?`ends-with(${a},${N(m[0]).trim()})`:`ends-with(${a},${N(w(m[0])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d}}if(r&&l&&h(r)){const l=[...new Set(r.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&w(l[e].trim())?.length>1&&(t.test(l[e])?m.push(`contains(${a},${N(l[e].trim()).trim()})`):m.push(`contains(${a},${N(w(l[e])).trim()})`));if(m?.length&&(d=T(e)?`//*[local-name()='${s}' and ${m.join(" and ")}]`:`//${s}[${m.join(" and ")}]`,i=v(d,e,n),1===i&&!o))return d}if(d=T(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=v(d,e,n),1===i&&!o)return d}},X=(e,t)=>{try{if(!e)return"";let n=T(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),""}},L=(e,t,n,a=!1,r)=>{try{if(l.has(e))return l.get(e);const o=[];let s=e;for(;s;){let l="",i=!1,c=e===s?r??s.attributes:s.attributes;for(const e of Array.from(c))if(O(e,s)){const a=d(e.name,e.nodeValue),r=e.name;for(const e of ee(s,r,a)){l=e;let a=0;if(a=v(l,s,t),1===a){o.unshift(D(l)),i=!0;break}if(a>1&&n&&(l=x(l,s,t,a),l)){o.unshift(D(l)),i=!0;break}}}if(s.textContent)if(!a||a&&!h(s.textContent)){let e=new RegExp(/^[\S]+( [\S]+)*$/gi);const a=y(s),r=k(s,a);l=r?p(r,T(s),s.tagName||"*"):e.test(s.textContent)?T(s)?`//*[local-name()='${s.tagName}' and .=${N(a)}]`:`//${s.tagName||"*"}[.=${N(a)}]`:T(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${N(a)}]`:`//${s.tagName||"*"}[normalize-space(.)=${N(a)}]`;let o=v(l,s,t);if(1===o)return l;if(o>1&&n)return l=x(l,s,t,o),l}else{let e=[];const a=[...new Set(y(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]&&w(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${N(a[t].trim()).trim()})`):e.push(`contains(.,${N(w(a[t])).trim()})`));if(e?.length){l=T(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=v(l,s,t);if(1===a)return l;if(a>1&&n)return l=x(l,s,t,a),l}}if(i)break;{let e=T(s)?`/*[local-name()='${s.tagName}']`:`/${s.tagName}`;if(s.parentElement){const t=Array.from(s.parentElement.children).filter(e=>e.tagName===s.tagName);if(t.length>1){e+=`[${t.indexOf(s)+1}]`}}o.unshift(e)}s=s.parentElement}const i=`${o.join("")}`;return l.set(e,i),i}catch(e){return console.log(e),null}},_=(e,n)=>{const a=[];let r="";if(e&&"function"!=typeof e.nodeValue){if("class"===e.name){const t=n.getRootNode?.()??n.ownerDocument,a=f(n,e.value,t);for(const e of a)if(r=T(n)?`//*[local-name()='${n.tagName}' and ${e}]`:`//${n.tagName}[${e}]`,r)return r;return}if(h(e.value))return;const o=[...new Set(e.value.match(/([^0-9]+)/g))];if(o?.length)for(let n=0;n<o?.length;n++)o[n]&&w(o[n].trim())?.length>2&&(t.test(o[n])?a.push(`contains(@${e.name},${N(o[n].trim())})`):a.push(`contains(@${e.name},${N(w(o[n])).trim()})`));if(a?.length)return r=T(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,r}},I=(e,n,a,r)=>{try{const r=a.filter(t=>O(t,e)),o=a=>{const r=d(a.name,a.nodeValue);return r?"class"===a.name?f(e,r,n):u(r)?[]:t.test(r)?[`@${a.name}="${r}"`]:[`normalize-space(@${a.name})="${r}"`]:[]},l=()=>{const n=w($(e)?.trim()||""),a=C(n);if(u(n))return a?[`contains(normalize-space(.),${N(a)})`]:[];if(!n||n.length>80||/^\d+$/.test(n)){const t=k(e,n);return t?[t]:[]}const r=new Set,o=k(e,n);return o?(r.add(o),Array.from(r)):(t.test(n)&&n.length<=40&&!n.includes(" ")&&r.add(`text()=${N(n)}`),n.includes(" ")&&r.add(`normalize-space(.)=${N(w(n))}`),r.add(`contains(text(),${N(n)})`),Array.from(r))},s=(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},i=t=>T(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,c=()=>{if(!(r.length<2))for(let t=2;t<=r.length;t++){const a=s(r,t);for(const t of a){let a=[];for(const e of t){const t=o(e);t.length&&a.push(...t)}if(a.length<2)continue;const r=i(a);let l;try{l=v(r,e,n)}catch{continue}if(1===l)return r}}},m=c();if(m)return m;const g=l();if(!g.length||!r.length)return;for(let t=1;t<=r.length;t++){const a=s(r,t);for(const t of a){let a=[];for(const e of t)a.push(...o(e));if(a.length)for(const t of g){const r=[...a,t],o=i(r);try{if(1===v(o,e,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=(e,n,a)=>{let r=T(e),o="";if(O(n,e)){let a=d(n.name,n.value);const l=n.name;if("class"===l){const t=e.getRootNode?.()??e.ownerDocument;return f(e,a,t).map(t=>r?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName||"*"}[${t}]`)}if(u(a))return[];o=t.test(a)?r?`*[local-name()='${e.tagName}' and @${l}=${N(a)}]`:`${e.tagName||"*"}[@${l}=${N(a)}]`:r?`*[local-name()='${e.tagName}' and normalize-space(@${l})=${N(a)}]`:`${e.tagName||"*"}[normalize-space(@${l})=${N(a)}]`}return o?[o]:[]},j=(e,n)=>{if(!e.textContent)return"";const a=y(e),r=C(a);if(u(a)&&!r)return"";const o=u(a)?r:a,l=k(e,o);let s;return s=l?p(l,T(e),e.tagName||"*"):u(a)?p(`contains(normalize-space(.),${N(o)})`,T(e),e.tagName||"*"):!t.test(a)||/\s/.test(a.trim())?p(`normalize-space(.)=${N(o)}`,T(e),e.tagName||"*"):T(e)?`//*[local-name()='${e.tagName}' and .=${N(o)}]`:`//${e.tagName||"*"}[.=${N(o)}]`,s},Y=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=S(n);return t?p(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return p(`normalize-space(${t})=${N(w(n)).trim()}`,T(e),e.tagName.toLowerCase())},V=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{prefix:t,fragment:a}=S(n),r=t||a;return r?p(`starts-with(normalize-space(.),${N(r)})`,T(e),e.tagName.toLowerCase()):""}return p(`starts-with(${t},${N(w(n)).trim()})`,T(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=S(n);return t?p(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return p(`contains(${t},${N(w(n)).trim()})`,T(e),e.tagName.toLowerCase())},W=(e,n)=>{const a=n.flatMap(n=>(n=>{const a=d(n.name,n.value);if(!a)return[];if("class"===n.name){const t=e.getRootNode?.()??e.ownerDocument;return f(e,a,t)}return u(a)?[]:t.test(a)?[`@${n.name}=${N(a)}`]:[`normalize-space(@${n.name})=${N(a)}`]})(n)).filter(Boolean);if(a.length>=2)return p(`${a[0]} or ${a[1]}`,T(e),e.tagName.toLowerCase());const r=(()=>{const n=w($(e)?.trim()||""),a=C(n);if(u(n))return a?`contains(normalize-space(.),${N(a)})`:null;const r=k(e,n);return r||(!n||n.length>80||/^\d+$/.test(n)?null:t.test(n)&&n.length<=40&&!n.includes(" ")?`text()=${N(n)}`:n.includes(" ")?`normalize-space(.)=${N(n)}`:`contains(text(),${N(n)})`)})();return 1===a.length&&r?p(`${a[0]} or ${r}`,T(e),e.tagName.toLowerCase()):""},U=(e,t,n)=>{try{return v(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(O(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=T(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(n=t,n?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in n){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}var n},Z=(e,t,n)=>{try{const{first:a,second:o}=r(e,n);return!!a&&!o&&a===t}catch{return!1}},J=e=>T(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))&&O(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=$(e)?.trim(),n=C(t);if(t&&u(t))return n?`contains(normalize-space(.),${N(n)})`:void 0;const a=k(e,t);if(a)return a;const r=t?N(E(t)):t;return r?r!==`'${t}'`?`contains(.,${r})`:/\s/.test(t)?`normalize-space(.)='${w(t)}'`:`normalize-space(.)='${t}'`:void 0},ee=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let r="";if(n=d(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return f(e,n,t).map(t=>T(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(u(n))return[];r=a.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 r?[r]:[]},te=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,ne=(e,n,a)=>{let r;const o=[];if(e.textContent&&(!a||a&&!h(e.textContent)))if(t.test(e.textContent)){const t=$(e),n=k(e,t),a=n||(/\s/.test(t.trim())?`normalize-space(.)=${N(w(t))}`:`.=${N(t)}`);r=T(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}else{const t=Q(e);t&&(r=T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`,o.push({key:"getReferenceElementsXpath",value:r}))}if(e.attributes){const t="IMG"===e.tagName?Array.from(e.attributes).sort((e,t)=>"alt"===e.name?-1:"alt"===t.name?1:0):Array.from(e.attributes);for(const a of t)if(O(a,e)){let t=a.nodeValue;if(t){t=d(a.name,t);const l=a.name;if("class"!==l&&u(t))continue;if("class"===l){const a=f(e,t,n);if(!a.length)continue;for(const t of a)r=T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`,o.push({key:"getReferenceElementsXpath",value:r});continue}r=T(e)?`*[local-name()='${e.tagName}' and @${l}=${N(t)}]`:`${e.tagName}[@${l}=${N(t)}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}}}if(!o?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=I(e,n,Array.prototype.slice.call(e.attributes));t&&o.push({key:"getReferenceElementsXpath",value:t})}}if(!o?.length){const t=[];let n;const r=e.tagName;if(e.textContent&&a&&h(e.textContent)){const a=w($(e)).trim();a?.length>1&&t.push(`contains(text(),${N(a)})`),t?.length&&(n=T(e)?`*[local-name()='${r}' and ${t.join(" and ")}]`:`${r}[${t.join(" and ")}]`,n&&o.push({key:"getReferenceElementsXpath",value:n}))}}if(!o?.length){const t=((e,t)=>{const n=Array.prototype.slice.call(e),a=[];try{n.map(e=>{if(O(e,t)){const n=_(e,t);n&&a.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return a})(e.attributes,e);t?.length&&o.concat(t)}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:L,getCombinationXpath:_,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:T,findXpathWithIndex:x,isNumberExist:h,getTextContent:$,getCountOfXPath:v,normalizeXPath:ae,getShadowRoot:A,escapeCharacters:N,removeParenthesis:b,checkBlockedAttributes:O,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:D,createObserver:e=>{o=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!g(t))&&a(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(g(t)||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||s.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{o?.observe(e,t)},stopObserver:()=>{o?.disconnect()},modifiedElementAttributes:s,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:d,getClassTokenCondition:(e,t,n,a=!1)=>f(e,t,n,a)[0]||null,getClassTokenConditions:f,getXpathStrings:ee,intermediateXpathSteps:M,getContainerTextCondition:k};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,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),pe=(e,t)=>t?e:e.filter(e=>!(e=>/(?:^|\/)[^/\[]+\[\d+\](?=\/|$)/.test(e)||/^\(.+\)\[\d+\]$/.test(e))(e.value)),$e=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ye=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},ve=(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},Ne=(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:()=>ye(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},be=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,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(be(e))continue;const f=[()=>K(e,a),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&O(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=v(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(be(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},Ee=(e,t,n,a)=>{const r=[];for(let t=e.parentElement;t;t=t.parentElement)r.push(t);const o=ye(e),l=ve(e,"previous"),s=ve(e,"next"),i=Ne(e,"previous"),c=Ne(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"}]];for(const n of f)for(const r of n){const n=xe(r.nodes,r.axis,e,t,0,r.key,a);if(n.length>0)return n}return[]},we=(e,t,n,a,r)=>{const o=(e=>ge[e]||e)(a);return"text"===o?he(a,((e,t,n)=>{if(!$e(e))return[];if("text"===n){const n=j(e)||Xe(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?he(a,((e,t,n)=>{const a=[],r=Array.from(e.attributes||[]).filter(t=>t?.value&&O(t,e)),o=$e(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)?he(a,((e,t,n,a)=>{const r=Array.from(e.attributes||[]).filter(t=>t?.value&&O(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?he(a,Ee(e,t,0,!1)):"index"===o?he(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?he(a,[{key:"xpath till tag",value:G(e,t)}]):[]},ke=(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,v(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=x(e,n,a,t);o&&1===v(o,n,a)&&ce.push({key:"relative xpath by unique parent "+(r?"index":""),value:o})}}}return null},Se=(e,n,a,r,o,l)=>{try{if(de.has(e))return de.get(e);const s=[];let i=e;for(;i&&1===i.nodeType;){const e=!1;for(const e of Array.from(i.attributes))if(O(e,i)){const t=d(e.name,e.nodeValue),r=e.name;for(const e of ee(i,r,t)){let t;try{t=ke(e,o,a,n,l,"parent")}catch(e){continue}if(t)return t}}if(i.textContent&&!i.textContent)if(!r||r&&!h(i.textContent)){let e;e=t.test(i.textContent)?T(i)?`//*[local-name()='${i.tagName}' and .=${N(y(i))}]`:`//${i.tagName||"*"}[.=${N(y(i))}]`:T(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${N(y(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${N(y(i))}]`;const r=ke(e,o,a,n,l,"parent");if(r)return r}else{const e=[],t=[...new Set(y(i).match(/([^0-9]+)/g))],r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&w(t[n].trim())&&(r.test(t[n])?e.push(`contains(.,${N(t[n].trim()).trim()})`):e.push(`contains(.,${N(w(t[n])).trim()})`));if(e?.length){const t=T(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,r=ke(t,o,a,n,l,"parent");if(r)return r}}if(!e){const e=T(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const c=s.join("")+o;if(1===v(c,e,n))return de.set(e,c),c}catch(e){return console.error(e),null}},Ce=(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(O(n,l)){const a=d(n.name,n.nodeValue),r=n.name;for(const n of ee(l,r,a)){let a;try{a=v(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===v(n,l,t)){e=!0,o.unshift(n);break}}}if(e)break;{const e=T(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}},Ae=(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(O(n,r)){const o=d(n.name,n.nodeValue),l=n.name;for(const n of ee(r,l,o)){let o;try{o=v(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===v(n,r,t)){e=!0,a.push(n);break}}}if(e)break;{const e=T(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}},Re=(e,t,n,a)=>{try{const r=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==r;o=o.nextElementSibling)Oe(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==r;o=o.previousElementSibling)Oe(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},Oe=(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=v(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=v(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 Te(e,t,n,a){const{tagName:r}=t,o=t.textContent.trim();if(!o)return;const l=w(o),s=C(l);if(u(l)&&!s)return;const i=u(l)?s:l,c=k(t,i);for(const a of e)if(O(a,t)){let e=d(a.name,a.nodeValue);const s=`//${r}[@${a.name}='${e}' and ${c||(u(l)?`contains(normalize-space(.),${N(i)})`:/\s/.test(o)?`normalize-space(.)=${N(i)}`:`text()=${N(i)}`)}]`;if(s){if(1==v(s,t,n))return s}}}const De=(e,t,n,a,r)=>{let o;if(o=e.name,O(e,t))return P(t,n,`@${o}`,e.value,a,r)},Pe=(e,t,n,a)=>{let r=e.className;if("string"!=typeof r&&(r=""),r=r?.replace("flndisabled","disabled"),r=d("class",r),r=r?.trim(),r&&O({name:"class",value:r},e))return P(e,t,"@class",r,n,a)},Xe=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const r=$(e);if(r)return P(e,t,".",r,n,a)}},Le=(e,t,n,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&O(e,t)){const o=De(e,t,n,a,r);o&&ce.push({key:`xpath by ${e.name}${a?" index":""}`,value:o})}});const l=Xe(t,n,a,r);if(l&&ce.push({key:"xpath by text"+(a?" index":""),value:l}),o.find(e=>"className"===e.name)&&O(o?.find(e=>"className"===e.name),t)){let e=Pe(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=Te(e,t,n);a&&ce.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},_e=(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(Le(m,l,c,n,a),o.length){const e=o.flatMap(e=>we(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)))})(e.filter(e=>1===v(e.value,l,c))),pe(ce,n)}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===v(t,e,c)&&ce.push({key:`${ce[n].key} regex`,value:t})}}return ce.length||i||(ce=Ee(l,c,0,n)),pe(ce,n)},Ie={parseDOM:_e,getTextXPath:Xe,getUniqueClassName:Pe,attributesBasedXPath:De,addAllXPathAttributes:Le,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(Re(e,t,a,s[r]),!ce.length&&(o||(o=Ce(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=v(a,e,t);if(1===l)ce.push({key:"relative xpath by relative parent",value:a});else if(l>1&&n){const r=x(a,e,t,l);r&&1===v(r,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(!ce.length&&(l||(l=Ae(e,t,e)),l&&(l.includes("@")||l.includes("text()")||l.includes(".=")))){const a=`/${s[r]+l.substring(1)}`,o=v(a,e,t);if(1===o)ce.push({key:"relative xpath by relative child",value:a});else if(o>1&&n){const r=x(a,e,t,o);r&&1===v(r,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(1===ce?.length&&ce?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=Xe(e,t,n,!1);a&&ce.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!ce.length){let o=Se(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:Te,getSiblingRelativeXPath:Re,getChildRelativeXpath:Ae,getParentRelativeXpath:Ce,getUniqueParentXpath:Se,checkRelativeXpathRelation:ke,buildAxesStrategyXpaths:Ee};let ze=[],Me=[];const je=/^[\S]+( [\S]+)*$/gi,Ye=(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=st(`${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=v(c,e[e.length-1],a);if(1===o)return[{key:`dynamic ${n}`,value:D(c)}];if(o>1&&r&&(c=x(c,e[e.length-1],a,o),c&&(o=v(c,e[e.length-1],a),1===o)))return[{key:`dynamic ${n} ${r?" index":""}`,value:D(c)}]}},Ve=(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=[],m=[];u.split("/").map(e=>f.push(e)),f.map(e=>m.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||X(i,i.ownerDocument),h=[],p=[];g.split("/").map(e=>h.push(e)),h.map(e=>p.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var y=0;y<f.length&&f[y]==h[y];y++);const v=[];for(let e=y-1;e<f.length;e++)f[e]&&v.push(m[e]);const b=[];for(let e="descendant"===r?y:y-1;e<h.length;e++)h[e]&&(b.length?b.push(p[e]):b.push(p[e].replace(/\[([0-9]+)\]/gm,"")));let x;if(Me=a,e[e.length-2].textContent){if(je.test(e[e.length-2].textContent)){const t=e[e.length-2],n=$(t),a=k(t,n),r=a||(/\s/.test(n.trim())?`normalize-space(.)=${N(w(n))}`:`.=${N(n)}`);x=T(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${r}]`:`${e[e.length-2].tagName}[${r}]`}else x=T(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])}]`;v[v.length-1]=x;const n=v.join("["),a=v.length-1,s=n;for(let n=0;n<Me.length;n++){let i;if(i=Me[n].value.startsWith("//")?Me[n].value.substring(Me[n].value.indexOf("//")+2):Me[n].value,i){const n=Ye(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(O(n,e[e.length-2])){let a=n.nodeValue;if(a){a=d(n.name,a);const s=n.name;x=T(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${N(a)}]`:`${e[e.length-2].tagName}[@${s}=${N(a)}]`,v[v.length-1]=x;const i=v.join("["),u=v.length-1,f=i;for(let n=0;n<Me.length;n++){let a;a=Me[n].value.startsWith("//")?Me[n].value.substring(Me[n].value.indexOf("//")+2):Me[n].value;const s=Ye(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(O(n,e[e.length-2])){let a=n.nodeValue;if(a){a=d(n.name,a);const s=_(n,e[e.length-2]);if(s){x=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,v[v.length-1]=x;const n=v.join("["),a=v.length-1,i=n;for(let n=0;n<Me.length;n++){let s;s=Me[n].value.startsWith("//")?Me[n].value.substring(Me[n].value.indexOf("//")+2):Me[n].value;const u=Ye(e,s,r,c||t,o,b,i,a,l);if(u?.length)return u}}}}}const E=v.join("["),S=v.length-1,C=st(`${E+(S?"]".repeat(S):"")}`,b,e[e.length-1],e,t,r,o,l);if(C)return C},qe=(e,t,n,a,r,o,l)=>{let s,i;console.log("getXpathRelationExpression",n);const c=[];try{if(s=a.filter(e=>!e?.key?.includes("absolute")).filter(t=>nt(t.value,e)),i=r.filter(e=>!e?.key?.includes("absolute")),"ancestor"===n||"ancestor-or-self"===n){const a=lt(e,t,n,s,i,o);if(a.length)return a}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);if(("ancestor"===n||"ancestor-or-self"===n)&&l.split(We).length>1)continue;let u=`//${0!==s[a].value.indexOf("//")?te(s[a].value):te(s[a].value.substring(s[a].value.indexOf("//")+2))}/${n}::${te(l)}`;console.log("getXpathRelationExpression",u);const f=v(u,t,t.ownerDocument);if(f>1){const e=0!==s[a].value.indexOf("//")?te(s[a].value):te(s[a].value.substring(s[a].value.indexOf("//")+2)),r=Qe(e,n,t,i,t.ownerDocument);if(r)return c.push({key:`dynamic ${n}`,value:D(r)}),c;if(o){if(u=x(u,t,t.ownerDocument,f),u)return c.push({key:`dynamic ${n}${o?" index":""}`,value:D(u)}),c}else f>1&&(ze.length?f<ze[0].count&&(ze.pop(),ze.push({key:"relative xpath by relative child "+(o?"index":""),value:u,count:f})):ze.push({key:"relative xpath by relative child "+(o?"index":""),value:u,count:f}))}else if(1===f){if("following"===n&&l.split(We).length>1){const r=0!==s[a].value.indexOf("//")?te(s[a].value):te(s[a].value.substring(s[a].value.indexOf("//")+2)),o=Ke(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:D(o)}),c}return c.push({key:`dynamic ${n}`,value:D(u)}),c}}if(!c.length){if("following"===n)for(let a=0;a<s.length;a++){const r=0!==s[a].value.indexOf("//")?te(s[a].value):te(s[a].value.substring(s[a].value.indexOf("//")+2)),o=Ke(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:D(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=0!==s[a].value.indexOf("//")?te(s[a].value):te(s[a].value.substring(s[a].value.indexOf("//")+2));if("following"===n){const a=Ke(r,e,t,n,i);if(a)return c.push({key:`dynamic ${n} bridge`,value:D(a)}),c}const f=st(r,u,t,[e,t],t.ownerDocument,n,o,l);if(console.log("getXpathRelationExpression traverseXpath",f),f)return c.push(...f),c}}}}catch(e){console.log(e)}return c},We=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,Ue=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,Fe=(e,t)=>He(e,t)[0]||"",He=(e,t)=>{const n=[];let a="";const r=e=>{e&&!n.includes(e)&&n.push(e)};for(const n of t){const t=Ue(n.value);if(t&&1===t.split(We).length){if(t===e.tagName||t===e.tagName.toLowerCase()){a=t;continue}r(te(t))}}for(const t of Ge){const n=e.getAttribute(t);if(!n)continue;const a=Be(t,n);a&&r(T(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`)}if(e.textContent){const t=Q(e);t&&r(T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`)}const o=f(e,e.getAttribute("class"),e.getRootNode?.()??e.ownerDocument,!1);for(const t of o)r(T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`);if(e.attributes)for(const t of Array.from(e.attributes))"class"!==t.name&&O(t,e)&&t.nodeValue&&r(T(e)?`*[local-name()='${e.tagName}' and @${t.name}=${N(d(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${N(d(t.name,t.nodeValue))}]`);return a&&r(a),r(T(e)?`*[local-name()='${e.tagName}']`:e.tagName),n},Ge=["aria-labelledby","aria-label","role","name","data-testid","data-test","data-qa","data-id","id"],Be=(e,t)=>{const n=d(e,t);return n?/\d/.test(n)?"":`@${e}=${N(n)}`:""},Ze=(e,t,n,a,r,o,l)=>{let s=n.parentElement,i=0;for(;s&&s!==a&&i<6;){i++;for(const t of Ge){const a=s.getAttribute(t);if(!a)continue;const i=Be(t,a);if(!i)continue;const c=T(s)?`*[local-name()='${s.tagName}' and ${i}]`:`${s.tagName}[${i}]`,u=`//${te(e)}/${r}::${o}/descendant::${c}/descendant::${te(l)}`;if(1===v(u,n,n.ownerDocument))return u}s=s.parentElement}return""},Je=["title",...Ge],Ke=(e,t,n,a,r)=>{if("following"!==a)return"";const o=He(n,r);if(!o.length)return"";const l=tt(`//${te(e)}`,t.ownerDocument)||t;let s=n.parentElement,i=0;for(;s&&i<6;){i++;if(l.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_FOLLOWING){for(const t of Je){const r=s.getAttribute(t);if(!r)continue;const l=Be(t,r);if(!l)continue;const i=T(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===v(r,n,n.ownerDocument))return r}}s=s.parentElement}else s=s.parentElement}return""},Qe=(e,t,n,a,r)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";for(const o of a){const a=Ue(o.value);if(!a||a.split(We).length>1||/\[\d+\]/.test(a))continue;const l=`//${e}/${t}::${te(a)}`;if(1===v(l,n,r))return l}return""},et=(e,t,n,a)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";const r=Fe(n,_e(n,n.ownerDocument,!1,!1)||[]);let o=n.parentElement,l=0;for(;o&&l<6;){l++;for(const l of Ge){const s=o.getAttribute(l);if(!s)continue;const i=Be(l,s);if(!i)continue;const c=`//${e}/${t}::${T(o)?`*[local-name()='${o.tagName}' and ${i}]`:`${o.tagName}[${i}]`}/descendant::${te(r)}`;if(1===v(c,n,a))return c}o=o.parentElement}return""},tt=(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}},nt=(e,t)=>{const n=Ue(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},at=e=>{const t=e.getAttribute("fill"),n=e.getAttribute("stroke");if(/\d/.test(t||"")||/\d/.test(n||""))return"";const a=t?`@fill=${N(t)}`:n?`@stroke=${N(n)}`:"";return a?`*[local-name()='${e.tagName.toLowerCase()}' and ${a}]`:""},rt=(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},ot=(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,f(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=at(t);if(o&&rt(a,t,n))for(const t of l)return`//${te(e)}/${r}::${t}/descendant::${o}/ancestor::${n.tagName.toLowerCase()}`}return""},lt=(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=T(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let r=t;for(;r&&r!==e;){const e=r===t?Fe(t,n):T(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(We).length>1?Fe(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 Ge){const t=n.getAttribute(e);if(!t)continue;const l=Be(e,t);if(!l)continue;const s=T(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=Ue(e.value);if(!a)continue;if(f){const e=`//${te(a)}/${n}::${f}/descendant::${te(u)}`;if(1===v(e,t,t.ownerDocument))return l.push({key:`dynamic ${n} bridge`,value:D(e)}),l}let r=u?`//${te(a)}/${n}::${i}/descendant::${te(u)}`:`//${te(a)}/${n}::${i}/${c}`,m=v(r,t,t.ownerDocument);const d=ot(a,0,t,s,n);if(d)return l.push({key:`dynamic ${n} icon bridge`,value:D(d)}),l;if(1===m)return l.push({key:`dynamic ${n} bridge`,value:D(r)}),l;if(u&&m>1){const e=Ze(a,0,t,s,n,i,u);if(e)return l.push({key:`dynamic ${n} bridge`,value:D(e)}),l;if(r=`//${te(a)}/${n}::${i}/${c}`,m=v(r,t,t.ownerDocument),1===m)return l.push({key:`dynamic ${n} bridge`,value:D(r)}),l}if(m>1&&o&&(r=x(r,t,t.ownerDocument,m),m=r?v(r,t,t.ownerDocument):0,r&&1===m))return l.push({key:`dynamic ${n} bridge index`,value:D(r)}),l}return l},st=(e,t,n,a,r,o,l,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${o}::${te(s)}`;const c=v(i,n,r);if(1===c)return[{key:`dynamic ${o}`,value:D(i)}];if(c>1&&l&&(i=x(i,a[a.length-1],r,c),i))return[{key:`dynamic ${o}${l?" index":""}`,value:D(i)}]}else for(let s=1;s<=t.length;s++){const c=it(t.slice(t.length-s,t.length).join("/"),n);for(const t of c){i=`//${e}/${o}::${te(t)}`;const s=v(i,n,r);if(1===s){if(t.split(We).length>1||/\[\d+\]/.test(t)){const t=et(e,o,n,r);if(t)return[{key:`dynamic ${o}`,value:D(t)}]}return[{key:`dynamic ${o}`,value:D(i)}]}if(s>1){const t=Qe(e,o,n,_e(n,n.ownerDocument,!1,!1)||[],r);if(t)return[{key:`dynamic ${o}`,value:D(t)}];const c=et(e,o,n,r);if(c)return[{key:`dynamic ${o}`,value:D(c)}];if(l&&(i=x(i,a[a.length-1],r,s),i))return[{key:`dynamic ${o}${l?" index":""}`,value:D(i)}]}}}},it=(e,t)=>{const n=t.getAttribute("class")||"",a=f(t,n,t.getRootNode?.()??t.ownerDocument);if(!a.length)return[e];const r=`${t.tagName}[@class=${N(n)}]`;return e.endsWith(r)?a.map(n=>{const a=`${t.tagName}[${n}]`;return`${e.slice(0,-r.length)}${a}`}):[e]},ct={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?Ve([e,t],n,a,r,o,s,l)||[]:qe(e,t,o,a,r,s,l)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,o);return i},getDescendantXpath:Ve,getAncestorBridgeXpath:lt,getXpathRelationExpression:qe,getTraverseXpathExpression:st,getReferenceElementXpath:e=>{let t=[];t=_e(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=_e(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:b(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=_e(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:b(e.value)}:{key:"",value:e.value});t?.length||(t=[{key:"",value:L(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:L(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:b(e.value)}:{key:"",value:e.value}));const a=Array.from(e.children||[]).map(t=>{const n=$(t)?.trim();if(!n||n!==$(e)?.trim())return null;const a=k(t,n),r=a||(/\s/.test(n)?`normalize-space(.)=${N(w(n))}`:`.=${N(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 ut=[];const ft=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},mt=(e,t="single")=>{const n=[],a=e.getRootNode();try{const r=dt(e);if(r&&ft(r,e,a)&&(n.push({key:"cssSelector by id",value:r}),"single"===t))return n;const o=$t(e);o&&ft(o,e,a)&&n.push({key:"cssSelector by class",value:o});const l=pt(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},dt=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&&!h(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(" > ")},gt=new Set(["id","class","style"]);function ht(e){return Array.from(e.attributes).filter(e=>!gt.has(e?.name?.toLowerCase())&&e.value&&!h(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const pt=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=ht(e);for(const t of r){const r=`${a}${t}`;if(ft(r,e,n))return r}},$t=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||h(e.className)||ut?.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(" > ")},yt={parseCssSelectors:mt,getIdCssPath:dt,getAttributeCssPath:pt,getClassCssPath:$t,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(" > ")}},vt=(e,t,n)=>{const a=ae(e);if(Rt(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},Nt=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Et(e.body,t)},bt=(e,t,n)=>Nt(t,e)===n,xt=e=>e.name?.toLowerCase().includes("cssselector")??!1,Et=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:a}=n[e];if(a){const e=Et(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},wt=e=>e?.id||null,kt=e=>e.className||null,St=e=>e.textContent?.trim()||null,Ct=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},At=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Rt(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 Ot(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 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 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(xt(t))return Nt(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=Rt(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=Et(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=>xt(e)&&e.value);for(const e of n)vt(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of a)bt(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=wt(c);if(m&&!f("id",m)&&!h(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 g=St(c);if(g&&!h(g)){const n=e.locators.find(e=>"linkText"===e.name);se(t,"linkText",g,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const p=Ct(c);if(p&&!f("name",p)&&!h(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 $=kt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!h($)){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:$}))}mt(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=_e(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!vt(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 At)if(a.value.includes(e)){const r=Ot(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:wt(c)},{name:"name",value:Ct(c)},{name:"className",value:kt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:St(c)}];for(const n of e){if(r.length>4)break;const{name:e,value:a}=n;a&&(h(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&&mt(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 Dt={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," "),h(l))continue;const s=`//${r}[@${e}="${l}"]`;let i=0;try{i=v(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&&!h(n))){a.push(`@${l}="${n}"`);const o=`//*[${a.join(" and ")}]`;let s;r.push(`${l} == "${n}"`);try{s=v(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}},Pt=()=>({xpath:Ie,referenceXpaths:ct,xpathUtils:ie,getElementsFromHTML:Tt,cssSelectors:yt,iosSelectors:Dt});e.createXPathAPI=Pt,e.default=Pt,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
1
+ !function(e){"use strict";const t=/^[\S]+( [\S]+)*$/i;let n=new WeakMap;const a=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=>{n.delete(e)}):n=new WeakMap},r=(e,t)=>{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}})(t);let o=n.get(r);o||(o=new Map,n.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 o,l=new Map,s=[];const i=new Set(["marked-element-temp","removePointers"]),c=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!i.has(e)).sort(),u=e=>/\d/.test(e||""),f=(e,t,n,a=!1)=>{const r=c(t),o=r.filter(e=>!!a||!u(e));return o.length?1===r.length&&1===o.length?[`@class=${N(o[0])}`]:o.map(t=>{const a=p(`contains(@class,${N(t)})`,T(e),e.tagName.toLowerCase());return{token:t,count:F(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,${N(e)})`):[]},m=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),d=(e,t)=>t?"class"===e||"className"===e?c(t).join(" "):t.replace("removePointers","").trim():"",g=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(T(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=c(e.oldValue),n=c(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},h=e=>/\d/.test(e),p=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,$=e=>{const t=e?.textContent;return t},y=e=>e?.childNodes[0]?.nodeValue||"",v=(e,t,n,a=!1)=>{try{if(R(n)){const{owner:r,contextNode:o,cloneElement:l,cloneElements:s}=O(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:o,second:l}=r(e,n);if(!o)return 0;if(!l)return o===t?1:0;if(a&&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}},N=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},b=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},E=(e,t,n,a)=>{try{const r=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===v(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===v(`(${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===v(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===v(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},x=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(),w=e=>e?e.replace(/\s\s+/g," ").trim():e,k=(e,t)=>{const n=w((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(.),${N(a)})`:""},S=e=>{const t=w((e||"").trim());if(!t||!u(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),a=n.split(/[^a-zA-Z]+/).map(e=>w(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:""}},A=e=>S(e).fragment,C=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},R=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,O=(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=d(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=s?.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,(!m.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(l))&&("class"===e.name||!u(a)))));var o,l},T=e=>e instanceof SVGElement,P=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,X=(e,n,a,r,o,l)=>{if(r){const{tagName:s}=e;let i,c="";const m=[];let d;const g=a.startsWith("@"),$="."===a||"text()"===a,y=$?".":a,b=$&&/\s/.test(r.trim()),E=$?A(r):r,x=$&&u(r)?E:r,S=$?k(e,x):"";if("@class"===a){for(const t of f(e,r,n))if(d=p(t,T(e),e.tagName.toLowerCase()),i=v(d,e,n),1===i&&!o)return d;return}if($&&u(r)&&!E)return;if(r&&(!g||!h(r))&&(d=S?p(S,T(e),e.tagName.toLowerCase()):b?p(`normalize-space(${y})=${N(w(x)).trim()}`,T(e),e.tagName.toLowerCase()):t.test(r)?`//${s}[${a}=${N(x)}]`:p(`normalize-space(${a})=${N(w(x)).trim()}`,T(e),e.tagName.toLowerCase()),i=v(d,e,n),1===i&&!o))return d;if(g&&u(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]&&w(u[0].trim())?.length>1&&r.startsWith(u[0])&&(c=t.test(u[0])?`starts-with(${a},${N(u[0]).trim()})`:`starts-with(${a},${N(w(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&w(u[u.length-1].trim())?.length>1&&r.endsWith(u[u.length-1])&&(c=t.test(u[u.length-1])?`ends-with(${a},${N(u[u.length-1]).trim()})`:`ends-with(${a},${N(w(u[u.length-1])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d}else{const u=l.length%2==0?l.length/2:l.length%2,f=l.slice(0,u).join(" ");let m=[...new Set(f.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&w(m[0].trim())?.length&&r.startsWith(m[0])&&(c=t.test(m[0])?`starts-with(${a},${N(m[0]).trim()})`:`starts-with(${a},${N(w(m[0])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d;const g=l.slice(u,l.length-1).join(" ");if(m=[...new Set(g.match(/([^0-9]+)/g))],m?.length&&m[0]&&w(m[0].trim())?.length>3&&r.endsWith(m[0])&&(c=t.test(m[0])?`ends-with(${a},${N(m[0]).trim()})`:`ends-with(${a},${N(w(m[0])).trim()})`),c?.length&&(d=T(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=v(d,e,n),1===i&&!o))return d}}if(r&&l&&h(r)){const l=[...new Set(r.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&w(l[e].trim())?.length>1&&(t.test(l[e])?m.push(`contains(${a},${N(l[e].trim()).trim()})`):m.push(`contains(${a},${N(w(l[e])).trim()})`));if(m?.length&&(d=T(e)?`//*[local-name()='${s}' and ${m.join(" and ")}]`:`//${s}[${m.join(" and ")}]`,i=v(d,e,n),1===i&&!o))return d}if(d=T(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=v(d,e,n),1===i&&!o)return d}},_=(e,t)=>{try{if(!e)return"";let n=T(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 _(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},L=(e,t,n,a=!1,r)=>{try{if(l.has(e))return l.get(e);const o=[];let s=e;for(;s;){let l="",i=!1,c=e===s?r??s.attributes:s.attributes;for(const e of Array.from(c))if(D(e,s)){const a=d(e.name,e.nodeValue),r=e.name;for(const e of te(s,r,a)){l=e;let a=0;if(a=v(l,s,t),1===a){o.unshift(P(l)),i=!0;break}if(a>1&&n&&(l=E(l,s,t,a),l)){o.unshift(P(l)),i=!0;break}}}if(s.textContent)if(!a||a&&!h(s.textContent)){let e=new RegExp(/^[\S]+( [\S]+)*$/gi);const a=y(s),r=k(s,a);l=r?p(r,T(s),s.tagName||"*"):e.test(s.textContent)?T(s)?`//*[local-name()='${s.tagName}' and .=${N(a)}]`:`//${s.tagName||"*"}[.=${N(a)}]`:T(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${N(a)}]`:`//${s.tagName||"*"}[normalize-space(.)=${N(a)}]`;let o=v(l,s,t);if(1===o)return l;if(o>1&&n)return l=E(l,s,t,o),l}else{let e=[];const a=[...new Set(y(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]&&w(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${N(a[t].trim()).trim()})`):e.push(`contains(.,${N(w(a[t])).trim()})`));if(e?.length){l=T(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=v(l,s,t);if(1===a)return l;if(a>1&&n)return l=E(l,s,t,a),l}}if(i)break;{let e=T(s)?`/*[local-name()='${s.tagName}']`:`/${s.tagName}`;if(s.parentElement){const t=Array.from(s.parentElement.children).filter(e=>e.tagName===s.tagName);if(t.length>1){e+=`[${t.indexOf(s)+1}]`}}o.unshift(e)}s=s.parentElement}const i=`${o.join("")}`;return l.set(e,i),i}catch(e){return console.log(e),null}},I=(e,n)=>{const a=[];let r="";if(e&&"function"!=typeof e.nodeValue){if("class"===e.name){const t=n.getRootNode?.()??n.ownerDocument,a=f(n,e.value,t);for(const e of a)if(r=T(n)?`//*[local-name()='${n.tagName}' and ${e}]`:`//${n.tagName}[${e}]`,r)return r;return}if(h(e.value))return;const o=[...new Set(e.value.match(/([^0-9]+)/g))];if(o?.length)for(let n=0;n<o?.length;n++)o[n]&&w(o[n].trim())?.length>2&&(t.test(o[n])?a.push(`contains(@${e.name},${N(o[n].trim())})`):a.push(`contains(@${e.name},${N(w(o[n])).trim()})`));if(a?.length)return r=T(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,r}},z=(e,n,a,r)=>{try{const r=a.filter(t=>D(t,e)),o=a=>{const r=d(a.name,a.nodeValue);return r?"class"===a.name?f(e,r,n):u(r)?[]:t.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=w($(e)?.trim()||""),a=A(n);if(u(n))return a?[`contains(normalize-space(.),${N(a)})`]:[];if(!n||n.length>80||/^\d+$/.test(n)){const t=k(e,n);return t?[t]:[]}const r=new Set,o=k(e,n);return o?(r.add(o),Array.from(r)):(t.test(n)&&n.length<=40&&!n.includes(" ")&&r.add(`text()=${N(n)}`),n.includes(" ")&&r.add(`normalize-space(.)=${N(w(n))}`),r.add(`contains(text(),${N(n)})`),Array.from(r))},c=(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},m=t=>T(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,g=()=>{if(!(r.length<2))for(let t=2;t<=r.length;t++){const a=c(r,t);for(const t of a){const a=s(t);for(const t of a){if(t.length<2)continue;const a=m(t);let r;try{r=v(a,e,n)}catch{continue}if(1===r)return a}}}},h=g();if(h)return h;const p=i();if(!p.length||!r.length)return;for(let t=1;t<=r.length;t++){const a=c(r,t);for(const t of a){const a=s(t);for(const t of a)if(t.length)for(const a of p){const r=[...t,a],o=m(r);try{if(1===v(o,e,n))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},M=(e,t,n)=>j(e,t)[0]||"",j=(e,n,a)=>{let r=T(e),o="";if(D(n,e)){let a=d(n.name,n.value);const l=n.name;if("class"===l){const t=e.getRootNode?.()??e.ownerDocument;return f(e,a,t).map(t=>r?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName||"*"}[${t}]`)}if(u(a))return[];o=t.test(a)?r?`*[local-name()='${e.tagName}' and @${l}=${N(a)}]`:`${e.tagName||"*"}[@${l}=${N(a)}]`:r?`*[local-name()='${e.tagName}' and normalize-space(@${l})=${N(a)}]`:`${e.tagName||"*"}[normalize-space(@${l})=${N(a)}]`}return o?[o]:[]},Y=(e,n)=>{if(!e.textContent)return"";const a=y(e),r=A(a);if(u(a)&&!r)return"";const o=u(a)?r:a,l=k(e,o);let s;return s=l?p(l,T(e),e.tagName||"*"):u(a)?p(`contains(normalize-space(.),${N(o)})`,T(e),e.tagName||"*"):!t.test(a)||/\s/.test(a.trim())?p(`normalize-space(.)=${N(o)}`,T(e),e.tagName||"*"):T(e)?`//*[local-name()='${e.tagName}' and .=${N(o)}]`:`//${e.tagName||"*"}[.=${N(o)}]`,s},V=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=S(n);return t?p(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return p(`normalize-space(${t})=${N(w(n)).trim()}`,T(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{prefix:t,fragment:a}=S(n),r=t||a;return r?p(`starts-with(normalize-space(.),${N(r)})`,T(e),e.tagName.toLowerCase()):""}return p(`starts-with(${t},${N(w(n)).trim()})`,T(e),e.tagName.toLowerCase())},W=(e,t,n)=>{if(("."===t||"text()"===t)&&u(n)){const{fragment:t}=S(n);return t?p(`contains(normalize-space(.),${N(t)})`,T(e),e.tagName.toLowerCase()):""}return p(`contains(${t},${N(w(n)).trim()})`,T(e),e.tagName.toLowerCase())},U=(e,n)=>{const a=n.flatMap(n=>(n=>{const a=d(n.name,n.value);if(!a)return[];if("class"===n.name){const t=e.getRootNode?.()??e.ownerDocument;return f(e,a,t)}return u(a)?[]:t.test(a)?[`@${n.name}=${N(a)}`]:[`normalize-space(@${n.name})=${N(a)}`]})(n)).filter(Boolean);if(a.length>=2)return p(`${a[0]} or ${a[1]}`,T(e),e.tagName.toLowerCase());const r=(()=>{const n=w($(e)?.trim()||""),a=A(n);if(u(n))return a?`contains(normalize-space(.),${N(a)})`:null;const r=k(e,n);return r||(!n||n.length>80||/^\d+$/.test(n)?null:t.test(n)&&n.length<=40&&!n.includes(" ")?`text()=${N(n)}`:n.includes(" ")?`normalize-space(.)=${N(n)}`:`contains(text(),${N(n)})`)})();return 1===a.length&&r?p(`${a[0]} or ${r}`,T(e),e.tagName.toLowerCase()):""},F=(e,t,n)=>{try{return v(e,t,n)}catch(e){return 0}},H=(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)&&J(r,e,t)&&(a.add(r),n.push(r))};l.forEach(t=>{if(D(t,e))for(const n of te(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=Y(e);t&&s(t)}if(r.length>1){const n=z(e,t,r);n&&s(n)}return n},G=(e,t)=>{const n=[];let a=t;for(;a&&a!==e;)n.unshift(K(a)),a=a.parentElement;return a===e?n.join("/"):""},B=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),a=K(e),r=T(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const r=H(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=F(r,e,n);if(console.log(`Match count: ${l}`),1===l&&Z(r,n)===e)return console.log(`Selected XPath: ${r}`),r;const s=G(t,e);if(s){const t=`${o}/${s}`;console.log(`Trying descendant XPath: ${t}`);const a=F(t,e,n);if(console.log(`Match count: ${a}`),1===a&&Z(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${r}`);const o=F(r,e,n);return console.log(`Match count: ${o}`),1===o&&Z(r,n)===e?(console.log(`Selected XPath: ${r}`),r):(console.log("Selected XPath: "),"")},Z=(e,t)=>{try{if(R(t)){const{owner:n,contextNode:a,cloneElement:r}=O(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}},J=(e,t,n)=>{try{const{first:a,second:o}=r(e,n);return!!a&&!o&&a===t}catch{return!1}},K=e=>T(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),Q=(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 te(e,a.name,a.value))n&&J(n,e,t)&&l(`anchor by ${a.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const a of te(e,n.name,n.value))a&&J(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=Y(e);n&&J(n,e,t)&&l("anchor by text",n)}if(o.length>1){const n=z(e,t,o);n&&J(n,e,t)&&l("anchor by combination",n)}const c=B(e,t);return c&&J(c,e,t)&&l("anchor by tag",c),r},ee=e=>{const t=$(e)?.trim(),n=A(t);if(t&&u(t))return n?`contains(normalize-space(.),${N(n)})`:void 0;const a=k(e,t);if(a)return a;const r=t?N(x(t)):t;return r?r!==`'${t}'`?`contains(.,${r})`:/\s/.test(t)?`normalize-space(.)='${w(t)}'`:`normalize-space(.)='${t}'`:void 0},te=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let r="";if(n=d(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return f(e,n,t).map(t=>T(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(u(n))return[];r=a.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 r?[r]:[]},ne=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,ae=(e,n,a)=>{let r;const o=[];if(e.textContent&&a&&h(e.textContent)){const{prefix:t,fragment:n}=S($(e)),a=[t?`starts-with(normalize-space(.),${N(t)})`:"",n?`contains(normalize-space(.),${N(n)})`:""].filter((e,t,n)=>e&&n.indexOf(e)===t);for(const t of a)r=T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`,o.push({key:"getReferenceElementsXpath",value:r})}if(e.textContent&&(!a||a&&!h(e.textContent)))if(t.test(e.textContent)){const t=$(e),n=k(e,t),a=n||(/\s/.test(t.trim())?`normalize-space(.)=${N(w(t))}`:`.=${N(t)}`);r=T(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}else{const t=ee(e);t&&(r=T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`,o.push({key:"getReferenceElementsXpath",value:r}))}if(e.attributes){const t="IMG"===e.tagName?Array.from(e.attributes).sort((e,t)=>"alt"===e.name?-1:"alt"===t.name?1:0):Array.from(e.attributes);for(const a of t)if(D(a,e)){let t=a.nodeValue;if(t){t=d(a.name,t);const l=a.name;if("class"!==l&&u(t))continue;if("class"===l){const a=f(e,t,n);if(!a.length)continue;for(const t of a)r=T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`,o.push({key:"getReferenceElementsXpath",value:r});continue}r=T(e)?`*[local-name()='${e.tagName}' and @${l}=${N(t)}]`:`${e.tagName}[@${l}=${N(t)}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}}}if(!o?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=z(e,n,Array.prototype.slice.call(e.attributes));t&&o.push({key:"getReferenceElementsXpath",value:t})}}if(!o?.length){const t=[];let n;const r=e.tagName;if(e.textContent&&a&&h(e.textContent)){const a=w($(e)).trim();a?.length>1&&t.push(`contains(text(),${N(a)})`),t?.length&&(n=T(e)?`*[local-name()='${r}' and ${t.join(" and ")}]`:`${r}[${t.join(" and ")}]`,n&&o.push({key:"getReferenceElementsXpath",value:n}))}}if(!o?.length){const t=((e,t)=>{const n=Array.prototype.slice.call(e),a=[];try{n.map(e=>{if(D(e,t)){const n=I(e,t);n&&a.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return a})(e.attributes,e);t?.length&&o.concat(t)}return o},re=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"),oe=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function le(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 se(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function ie(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(`#${se(n)}`).length;case"name":return 1===o(`[name="${se(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 ce={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:ae,getAbsoluteXPath:_,getRelativeXPath:L,getCombinationXpath:I,getAttributeCombinationXpath:z,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:T,findXpathWithIndex:E,isNumberExist:h,getTextContent:$,getCountOfXPath:v,normalizeXPath:re,getShadowRoot:C,escapeCharacters:N,removeParenthesis:b,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:oe,deleteGarbageFromInnerText:x,replaceTempAttributes:P,createObserver:e=>{o=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!g(t))&&a(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(g(t)||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||s.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{o?.observe(e,t)},stopObserver:()=>{o?.disconnect()},modifiedElementAttributes:s,cspEnabled:!1,getXPathPattern:le,getNormalizedPropertyXPath:V,getStartsWithPropertyXPath:q,getContainsPropertyXPath:W,getOrAttributesXPath:U,getTagOnlyXPath:B,getFirstMatchedNode:Z,isExactUniqueXpath:J,getAxisNodeTest:K,getUniqueNodeAnchorXpaths:Q,escapeAttrValue:se,isUniqueInDOM:ie,sanitizeAttributeValue:d,getClassTokenCondition:(e,t,n,a=!1)=>f(e,t,n,a)[0]||null,getClassTokenConditions:f,getXpathStrings:te,intermediateXpathSteps:j,getContainerTextCondition:k};let ue=[],fe=[],me=new Map,de=new Map;const ge=new Map,he={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},pe=e=>he[e]||e,$e=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),ye=(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)),ve=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",Ne=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},be=(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},Ee=(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:()=>Ne(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},xe=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},we=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},ke=(e,t,n,a,r,o,l)=>{const s=K(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(xe(e))continue;const f=[()=>Q(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=W(e,`@${a.name}`,n);r&&t.push({key:"contains",value:r});const o=q(e,`@${a.name}`,n);o&&t.push({key:"starts-with",value:o})}return t},()=>[{key:"tag",value:B(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(J(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=v(r.value,e,a);for(let e=1;e<=Math.min(l,3);e++){const l=`(${r.value})[${e}]/${t}::${s}`;if(J(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(xe(r))continue;const e=Q(r,a);for(const r of e.slice(0,5)){const e=`${r.value}/${t}::${s}`;if(J(e,n,a)){if(i.push({key:o,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},Se=(e,t)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.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""},Ce=(e,t)=>{const n=[];for(let a=e;a&&a!==t;a=a.parentElement){const e=a.parentElement;if(!e)return"";n.push(`/parent::${K(e)}`)}return n.join("")},Re=(e,t)=>{const n=K(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Oe=(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=[be(n,"previous").slice(0,4),be(n,"next").slice(0,4)];for(const t of e)for(const e of t){a(e);let t=0;for(const n of Ne(e).sort((e,t)=>we(t)-we(e))){if(t++>=8)break;a(n)}}}return t.sort((e,t)=>we(t)-we(e)).slice(0,20)})(e),l=Se(e.parentElement,3);for(const n of o){const o=Q(n,t).filter(e=>"anchor by tag"!==e.key).slice(0,2);if(!o.length)continue;const s=Se(n,3);for(const i of o)for(const o of s){const s=Ce(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}::${K(n)}`;for(const o of Re(n,e)){const n=`${i.value}${s}${c}${o}`;if(!r.has(n)&&(r.add(n),J(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(K(a));if(!n.length)return"";const a=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${a}`},Te=(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 Q(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)||!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 a=W(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,a)}),o},Pe=(e,t,n,a)=>{const r=[];for(let t=e.parentElement;t;t=t.parentElement)r.push(t);const o=Ne(e),l=be(e,"previous"),s=be(e,"next"),i=Ee(e,"previous"),c=Ee(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=Te(n,t,0,a);for(const n of s.slice(0,3)){const a=`${n.value}${l}`;if(!o.has(a)&&(o.add(a),J(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=ke(r.nodes,r.axis,e,t,0,r.key,a);if(n.length>0)return n}return Oe(e,t)||[]},Xe=(e,t,n,a,r)=>{const o=pe(a);return"text"===o?$e(a,((e,t,n)=>{if(!ve(e))return[];if("text"===n){const n=Y(e)||We(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?$e(a,((e,t,n)=>{const a=[],r=Array.from(e.attributes||[]).filter(t=>t?.value&&D(t,e)),o=ve(e),l="contains"===n?W:"startsWith"===n?q:"normalizeSpace"===n?V: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)?$e(a,((e,t,n,a)=>{const r=Array.from(e.attributes||[]).filter(t=>t?.value&&D(t,e));if("and"===a){const n=z(e,t,r);return n?[{key:"xpath by combination",value:n}]:[]}if("or"===a&&r.length>=1){const t=U(e,r);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,0,o)):"axes"===o?$e(a,Pe(e,t,0,!1)):"index"===o?$e(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?te(o,"id",o.id):te(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?$e(a,[{key:"xpath till tag",value:B(e,t)}]):[]},_e=(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){me?.get(e)||me.set(e,v(e,n,a));const t=me?.get(e);if(1===t)return e;if(t>1&&(fe.length?t<fe[0].count&&(fe.pop(),fe.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})):fe.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})),t>1&&r&&!ue.length){const o=E(e,n,a,t);o&&1===v(o,n,a)&&ue.push({key:"relative xpath by unique parent "+(r?"index":""),value:o})}}}return null},Le=(e,n,a,r,o,l)=>{try{if(ge.has(e))return ge.get(e);const s=[];let i=e;for(;i&&1===i.nodeType;){const e=!1;for(const e of Array.from(i.attributes))if(D(e,i)){const t=d(e.name,e.nodeValue),r=e.name;for(const e of te(i,r,t)){let t;try{t=_e(e,o,a,n,l,"parent")}catch(e){continue}if(t)return t}}if(i.textContent&&!i.textContent)if(!r||r&&!h(i.textContent)){let e;e=t.test(i.textContent)?T(i)?`//*[local-name()='${i.tagName}' and .=${N(y(i))}]`:`//${i.tagName||"*"}[.=${N(y(i))}]`:T(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${N(y(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${N(y(i))}]`;const r=_e(e,o,a,n,l,"parent");if(r)return r}else{const e=[],t=[...new Set(y(i).match(/([^0-9]+)/g))],r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&w(t[n].trim())&&(r.test(t[n])?e.push(`contains(.,${N(t[n].trim()).trim()})`):e.push(`contains(.,${N(w(t[n])).trim()})`));if(e?.length){const t=T(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,r=_e(t,o,a,n,l,"parent");if(r)return r}}if(!e){const e=T(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const c=s.join("")+o;if(1===v(c,e,n))return ge.set(e,c),c}catch(e){return console.error(e),null}},Ie=(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=d(n.name,n.nodeValue),r=n.name;for(const n of te(l,r,a)){let a;try{a=v(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=Y(l);if(n){if(1===v(n,l,t)){e=!0,o.unshift(n);break}}}if(e)break;{const e=T(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}},ze=(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=d(n.name,n.nodeValue),l=n.name;for(const n of te(r,l,o)){let o;try{o=v(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=Y(r);if(n){if(1===v(n,r,t)){e=!0,a.push(n);break}}}if(e)break;{const e=T(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 de.set(e,l),l}catch(e){return console.log(e),null}},Me=(e,t,n,a)=>{try{const r=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==r;o=o.nextElementSibling)je(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==r;o=o.previousElementSibling)je(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},je=(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=v(t,e,n);if(1===o)return void ue.push({key:`xpath by ${r}`,value:t});o>1&&(fe.length?o<fe[0].count&&(fe.pop(),fe.push({key:`relative xpath by ${r}`,value:t,count:o})):fe.push({key:`relative xpath by ${r}`,value:t,count:o}))}}if(!o){let t;if(t=M(e,{name:"text",value:e.textContent}),t){const a=v(t,e,n);if(1===a)return void ue.push({key:`xpath by ${r}`,value:t});a>1&&(fe.length?a<fe[0].count&&(fe.pop(),fe.push({key:`relative xpath by ${r}`,value:t,count:a})):fe.push({key:`relative xpath by ${r}`,value:t,count:a}))}}}catch(e){console.log(`${r} xpath-error`,e)}};function Ye(e,t,n,a){const{tagName:r}=t,o=t.textContent.trim();if(!o)return;const l=w(o),s=A(l);if(u(l)&&!s)return;const i=u(l)?s:l,c=k(t,i);for(const a of e)if(D(a,t)){let e=d(a.name,a.nodeValue);const s=`//${r}[@${a.name}='${e}' and ${c||(u(l)?`contains(normalize-space(.),${N(i)})`:/\s/.test(o)?`normalize-space(.)=${N(i)}`:`text()=${N(i)}`)}]`;if(s){if(1==v(s,t,n))return s}}}const Ve=(e,t,n,a,r)=>{let o;if(o=e.name,D(e,t))return X(t,n,`@${o}`,e.value,a,r)},qe=(e,t,n,a)=>{let r=e.className;if("string"!=typeof r&&(r=""),r=r?.replace("flndisabled","disabled"),r=d("class",r),r=r?.trim(),r&&D({name:"class",value:r},e))return X(e,t,"@class",r,n,a)},We=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const r=$(e);if(r)return X(e,t,".",r,n,a)}},Ue=(e,t,n,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&D(e,t)){const o=Ve(e,t,n,a,r);o&&ue.push({key:`xpath by ${e.name}${a?" index":""}`,value:o})}});const l=We(t,n,a,r);if(l&&ue.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=qe(t,n,a,r);e&&ue.push({key:"xpath by class",value:e})}if(!ue.length&&o.length>1){const e=z(t,n,o);e&&ue.push({key:"xpath by combination",value:e})}if(!ue.length){const a=Ye(e,t,n);a&&ue.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},Fe=(e,t,n,a,r=[],o=[])=>{ue=[],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(Ue(m,l,c,n,a),o.length){const e=n||((e=[])=>e.some(e=>"index"===pe(e)))(o),t=o.flatMap(e=>Xe(l,c,0,e));return ue=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(t.filter(e=>1===v(e.value,l,c))),ye(ue,e)}if(ue.length){const t=ue.length;for(let n=0;n<t;n++){let t=ue[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===v(t,e,c)&&ue.push({key:`${ue[n].key} regex`,value:t})}}return ue.length||i||(ue=Pe(l,c,0,n)),ye(ue,n)},He={parseDOM:Fe,getTextXPath:We,getUniqueClassName:qe,attributesBasedXPath:Ve,addAllXPathAttributes:Ue,addRelativeXpaths:(e,t,n,a,r)=>{try{let o,l,s=[];if(ue=[],console.log(r),r)for(const t of r){const n=j(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=M(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(!ue.length){if(Me(e,t,a,s[r]),!ue.length&&(o||(o=Ie(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=v(a,e,t);if(1===l)ue.push({key:"relative xpath by relative parent",value:a});else if(l>1&&n){const r=E(a,e,t,l);r&&1===v(r,e,t)&&ue.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(!ue.length&&(l||(l=ze(e,t,e)),l&&(l.includes("@")||l.includes("text()")||l.includes(".=")))){const a=l.replace(/^\/+/,""),o=`/${s[r]}/${a}`,i=v(o,e,t);if(1===i)ue.push({key:"relative xpath by relative child",value:o});else if(i>1&&n){const a=E(o,e,t,i);a&&1===v(a,e,t)&&ue.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===ue?.length&&ue?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=We(e,t,n,!1);a&&ue.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!ue.length){let o=Le(e.parentElement,t,e,a,s[r],n);o&&ue.push({key:"xpath by unique parent",value:o})}}return ue}catch(e){console.log(e)}},getXPathUsingAttributeAndText:Ye,getSiblingRelativeXPath:Me,getChildRelativeXpath:ze,getParentRelativeXpath:Ie,getUniqueParentXpath:Le,checkRelativeXpathRelation:_e,buildAxesStrategyXpaths:Pe};let Ge=[],Be=[];const Ze=/^[\S]+( [\S]+)*$/gi,Je=(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=xt(`${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}::${ne(t,e[e.length-1])}`;let o=v(c,e[e.length-1],a);if(1===o)return[{key:`dynamic ${n}`,value:P(c)}];if(o>1&&r&&(c=E(c,e[e.length-1],a,o),c&&(o=v(c,e[e.length-1],a),1===o)))return[{key:`dynamic ${n} ${r?" index":""}`,value:P(c)}]}},Ke=(e,t,n,a,r,o=!1,l=!1)=>{const s=e[e.length-2],i=e[e.length-1],c=C(i)??i.ownerDocument,u=n.find(e=>e?.key?.includes("absolute"))?.value||_(s,s.ownerDocument),f=[],m=[];u.split("/").map(e=>f.push(e)),f.map(e=>m.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||_(i,i.ownerDocument),h=[],p=[];g.split("/").map(e=>h.push(e)),h.map(e=>p.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var y=0;y<f.length&&f[y]==h[y];y++);const v=[];for(let e=y-1;e<f.length;e++)f[e]&&v.push(m[e]);const b=[];for(let e="descendant"===r?y:y-1;e<h.length;e++)h[e]&&(b.length?b.push(p[e]):b.push(p[e].replace(/\[([0-9]+)\]/gm,"")));let E;if(Be=(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(Ze.test(e[e.length-2].textContent)){const t=e[e.length-2],n=$(t),a=k(t,n),r=a||(/\s/.test(n.trim())?`normalize-space(.)=${N(w(n))}`:`.=${N(n)}`);E=T(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${r}]`:`${e[e.length-2].tagName}[${r}]`}else E=T(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${ee(e[e.length-2])})]`:`${e[e.length-2].tagName}[${ee(e[e.length-2])}]`;v[v.length-1]=E;const n=v.join("["),a=v.length-1,s=n;for(let n=0;n<Be.length;n++){let i;if(i=Be[n].value.startsWith("//")?Be[n].value.substring(Be[n].value.indexOf("//")+2):Be[n].value,i){const n=Je(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=d(n.name,a);const s=n.name;E=T(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${N(a)}]`:`${e[e.length-2].tagName}[@${s}=${N(a)}]`,v[v.length-1]=E;const i=v.join("["),u=v.length-1,f=i;for(let n=0;n<Be.length;n++){let a;a=Be[n].value.startsWith("//")?Be[n].value.substring(Be[n].value.indexOf("//")+2):Be[n].value;const s=Je(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=d(n.name,a);const s=I(n,e[e.length-2]);if(s){E=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,v[v.length-1]=E;const n=v.join("["),a=v.length-1,i=n;for(let n=0;n<Be.length;n++){let s;s=Be[n].value.startsWith("//")?Be[n].value.substring(Be[n].value.indexOf("//")+2):Be[n].value;const u=Je(e,s,r,c||t,o,b,i,a,l);if(u?.length)return u}}}}}const x=v.join("["),S=v.length-1,A=xt(`${x+(S?"]".repeat(S):"")}`,b,e[e.length-1],e,t,r,o,l);if(A)return A},Qe=(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=>yt(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=st(s[a].value,e);let f=`//${u}/${n}::${ne(l)}`;console.log("getXpathRelationExpression",f);const m=v(f,t,t.ownerDocument);if(m>1){const a=gt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=dt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:P(r)}),c;const l=ht(u,n,t,i,t.ownerDocument);if(l)return c.push({key:`dynamic ${n}`,value:P(l)}),c;if(o){if(f=E(f,t,t.ownerDocument,m),f)return c.push({key:`dynamic ${n}${o?" index":""}`,value:P(f)}),c}else m>1&&(Ge.length?m<Ge[0].count&&(Ge.pop(),Ge.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m})):Ge.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m}))}else if(1===m){if(lt(l)){const a=gt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=dt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:P(r)}),c}return c.push({key:`dynamic ${n}`,value:P(f)}),c}}if(!c.length){const a=gt(e,t,n,s,i);if(a.length)return c.push(...a),c;for(let a=0;a<s.length;a++){const r=st(s[a].value,e),o=dt(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:P(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=st(s[a].value,e),f=dt(r,e,t,n,i);if(f)return c.push({key:`dynamic ${n} bridge`,value:P(f)}),c;const m=xt(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},et=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,tt=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,nt=(e,t)=>at(e,t)[0]||"",at=(e,t)=>{const n=[];let a="";const r=e=>{e&&!n.includes(e)&&n.push(e)};for(const n of t){const t=tt(n.value);if(t&&1===t.split(et).length){if(t===e.tagName||t===e.tagName.toLowerCase()){a=t;continue}r(ne(t))}}for(const t of rt){const n=e.getAttribute(t);if(!n)continue;const a=ot(t,n);a&&r(T(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`)}if(e.textContent){const t=ee(e);t&&r(T(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`)}const o=f(e,e.getAttribute("class"),e.getRootNode?.()??e.ownerDocument,!1);for(const t of o)r(T(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(T(e)?`*[local-name()='${e.tagName}' and @${t.name}=${N(d(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${N(d(t.name,t.nodeValue))}]`);return a&&r(a),r(T(e)?`*[local-name()='${e.tagName}']`:e.tagName),n},rt=["aria-labelledby","aria-label","role","name","data-testid","data-test","data-qa","data-id","id"],ot=(e,t)=>{const n=d(e,t);return n?/\d/.test(n)?"":`@${e}=${N(n)}`:""},lt=e=>e.split(et).length>1||/\[\d+\]/.test(e),st=(e,t)=>0!==e.indexOf("//")?ne(e):ne(e.substring(e.indexOf("//")+2)),it=e=>{const t=[];for(const n of rt){const a=e.getAttribute(n);if(!a)continue;const r=ot(n,a);if(r){t.push(T(e)?`*[local-name()='${e.tagName}' and ${r}]`:`${e.tagName}[${r}]`);break}}return t},ct=(e,t=6)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},ut=(e,t)=>{const n=ot(e,t);if(n)return n;const a=d(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},${N(o)})`},ft=(e,t,n,a,r,o,l)=>{let s=n.parentElement,i=0;for(;s&&s!==a&&i<6;){i++;for(const t of rt){const a=s.getAttribute(t);if(!a)continue;const i=ot(t,a);if(!i)continue;const c=T(s)?`*[local-name()='${s.tagName}' and ${i}]`:`${s.tagName}[${i}]`,u=`//${ne(e)}/${r}::${o}/descendant::${c}/descendant::${ne(l)}`;if(1===v(u,n,n.ownerDocument))return u}s=s.parentElement}return""},mt=["title",...rt],dt=(e,t,n,a,r)=>((e,t,n,a,r)=>{if("following"!==a&&"preceding"!==a)return"";const o=at(n,r);if(!o.length)return"";const l=$t(`//${ne(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 mt){const r=s.getAttribute(t);if(!r)continue;const l=ot(t,r);if(!l)continue;const i=T(s)?`*[local-name()='${s.tagName}' and ${l}]`:`${s.tagName}[${l}]`;for(const t of o){const r=`//${ne(e)}/${a}::${i}/descendant::${ne(t)}`;if(1===v(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=at(n,r);if(!o.length)return"";const l=ct(t),s=ct(n);for(const t of l){const r=it(t);if(r.length)for(const l of s){const s=it(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=`//${ne(e)}/ancestor-or-self::${t}/${a}::${r}/descendant-or-self::${ne(l)}`;if(1===v(o,n,n.ownerDocument))return o}}}return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("child"!==a)return"";const o=at(n,r);if(!o.length)return"";const l=ct(n).filter(e=>e.parentElement===t);for(const t of l){const a=it(t);if(a.length)for(const t of a)for(const a of o){const r=`//${ne(e)}/child::${t}/descendant-or-self::${ne(a)}`;if(1===v(r,n,n.ownerDocument))return r}}return""})(e,t,n,a,r),gt=(e,t,n,a,r)=>"ancestor"!==n&&"ancestor-or-self"!==n?[]:Et(e,t,n,a,r,!1),ht=(e,t,n,a,r)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";for(const o of a){const a=tt(o.value);if(!a||a.split(et).length>1||/\[\d+\]/.test(a))continue;const l=`//${e}/${t}::${ne(a)}`;if(1===v(l,n,r))return l}return""},pt=(e,t,n,a)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";const r=at(n,[...Fe(n,n.ownerDocument,!1,!1)||[],...ae(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 rt){const s=o.getAttribute(l);if(!s)continue;const i=ut(l,s);if(!i)continue;const c=T(o)?`*[local-name()='${o.tagName}' and ${i}]`:`${o.tagName}[${i}]`;for(const o of r){const r=`//${e}/${t}::${c}/descendant::${ne(o)}`;if(1===v(r,n,a))return r}}o=o.parentElement}return""},$t=(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}},yt=(e,t)=>{const n=tt(e);if(!n)return!1;try{const e=t.ownerDocument.evaluate(`//${ne(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},vt=e=>{const t=e.getAttribute("fill"),n=e.getAttribute("stroke");if(/\d/.test(t||"")||/\d/.test(n||""))return"";const a=t?`@fill=${N(t)}`:n?`@stroke=${N(n)}`:"";return a?`*[local-name()='${e.tagName.toLowerCase()}' and ${a}]`:""},Nt=(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},bt=(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,f(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=vt(t);if(o&&Nt(a,t,n))for(const t of l)return`//${ne(e)}/${r}::${t}/descendant::${o}/ancestor::${n.tagName.toLowerCase()}`}return""},Et=(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=T(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let r=t;for(;r&&r!==e;){const e=r===t?nt(t,n):T(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(et).length>1?nt(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 rt){const t=n.getAttribute(e);if(!t)continue;const l=ot(e,t);if(!l)continue;const s=T(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=tt(e.value);if(!a)continue;if(f){const e=`//${ne(a)}/${n}::${f}/descendant::${ne(u)}`;if(1===v(e,t,t.ownerDocument))return l.push({key:`dynamic ${n} bridge`,value:P(e)}),l}let r=u?`//${ne(a)}/${n}::${i}/descendant::${ne(u)}`:`//${ne(a)}/${n}::${i}/${c}`,m=v(r,t,t.ownerDocument);const d=bt(a,0,t,s,n);if(d)return l.push({key:`dynamic ${n} icon bridge`,value:P(d)}),l;if(1===m)return l.push({key:`dynamic ${n} bridge`,value:P(r)}),l;if(u&&m>1){const e=ft(a,0,t,s,n,i,u);if(e)return l.push({key:`dynamic ${n} bridge`,value:P(e)}),l;if(r=`//${ne(a)}/${n}::${i}/${c}`,m=v(r,t,t.ownerDocument),1===m)return l.push({key:`dynamic ${n} bridge`,value:P(r)}),l}if(m>1&&o&&(r=E(r,t,t.ownerDocument,m),m=r?v(r,t,t.ownerDocument):0,r&&1===m))return l.push({key:`dynamic ${n} bridge index`,value:P(r)}),l}return l},xt=(e,t,n,a,r,o,l,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${o}::${ne(s)}`;const c=v(i,n,r);if(1===c)return[{key:`dynamic ${o}`,value:P(i)}];if(c>1&&l&&(i=E(i,a[a.length-1],r,c),i))return[{key:`dynamic ${o}${l?" index":""}`,value:P(i)}]}else for(let s=1;s<=t.length;s++){const c=wt(t.slice(t.length-s,t.length).join("/"),n);for(const t of c){i=`//${e}/${o}::${ne(t)}`;const s=v(i,n,r);if(1===s){if(t.split(et).length>1||/\[\d+\]/.test(t)){const t=pt(e,o,n,r);if(t)return[{key:`dynamic ${o}`,value:P(t)}]}return[{key:`dynamic ${o}`,value:P(i)}]}if(s>1){const t=ht(e,o,n,Fe(n,n.ownerDocument,!1,!1)||[],r);if(t)return[{key:`dynamic ${o}`,value:P(t)}];const c=pt(e,o,n,r);if(c)return[{key:`dynamic ${o}`,value:P(c)}];if(l&&(i=E(i,a[a.length-1],r,s),i))return[{key:`dynamic ${o}${l?" index":""}`,value:P(i)}]}}}},wt=(e,t)=>{const n=t.getAttribute("class")||"",a=f(t,n,t.getRootNode?.()??t.ownerDocument);if(!a.length)return[e];const r=`${t.tagName}[@class=${N(n)}]`;return e.endsWith(r)?a.map(n=>{const a=`${t.tagName}[${n}]`;return`${e.slice(0,-r.length)}${a}`}):[e]},kt={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?Ke([e,t],n,a,r,o,s,l)||[]:Qe(e,t,o,a,r,s,l)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,o);return i},getDescendantXpath:Ke,getAncestorBridgeXpath:Et,getXpathRelationExpression:Qe,getTraverseXpathExpression:xt,getReferenceElementXpath:e=>{let t=[];t=Fe(e,e.ownerDocument,!1,!1);const n=ae(e,e.ownerDocument,!1);if(n?.length&&(t=t?.length?t.concat(n):n),t?.length){let n=Fe(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&oe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:b(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Fe(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&oe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:b(e.value)}:{key:"",value:e.value});t?.length||(t=[{key:"",value:L(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:L(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&oe(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:b(e.value)}:{key:"",value:e.value}));const a=Array.from(e.children||[]).map(t=>{const n=$(t)?.trim();if(!n||n!==$(e)?.trim())return null;const a=k(t,n),r=a||(/\s/.test(n)?`normalize-space(.)=${N(w(n))}`:`.=${N(n)}`);return{key:"reference child text",value:`${t.tagName}[${r}]`}}).filter(e=>!!e);a.length&&(t=a.concat(t));const r=_(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 St=[];const At=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},Ct=(e,t="single")=>{const n=[],a=e.getRootNode();try{const r=Rt(e);if(r&&At(r,e,a)&&(n.push({key:"cssSelector by id",value:r}),"single"===t))return n;const o=Pt(e);o&&At(o,e,a)&&n.push({key:"cssSelector by class",value:o});const l=Tt(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},Rt=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&&!h(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(" > ")},Ot=new Set(["id","class","style"]);function Dt(e){return Array.from(e.attributes).filter(e=>!Ot.has(e?.name?.toLowerCase())&&e.value&&!h(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Tt=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(At(r,e,n))return r}},Pt=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||h(e.className)||St?.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(" > ")},Xt={parseCssSelectors:Ct,getIdCssPath:Rt,getAttributeCssPath:Tt,getClassCssPath:Pt,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(" > ")}},_t=(e,t,n)=>{const a=re(e);if(Ut(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},Lt=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Mt(e.body,t)},It=(e,t,n)=>Lt(t,e)===n,zt=e=>e.name?.toLowerCase().includes("cssselector")??!1,Mt=(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=Mt(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},jt=e=>e?.id||null,Yt=e=>e.className||null,Vt=e=>e.textContent?.trim()||null,qt=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Wt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Ut(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 Ft(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 Ht=(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(zt(t))return Lt(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+se(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=se(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=Ut(e,re(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=Mt(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=>zt(e)&&e.value);for(const e of n)_t(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of a)It(e.value,t,c)&&o(e,{isSelfHealed:null});const l=r.filter(e=>"xpath"===e.name&&e.value),s=new Set(l.map(e=>le(e.value))),u=[],m=jt(c);if(m&&!f("id",m)&&!h(m)){const n=e.locators.find(e=>"id"===e.name);ie(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);ie(t,"tagName",d,c)&&(u.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const g=Vt(c);if(g&&!h(g)){const n=e.locators.find(e=>"linkText"===e.name);ie(t,"linkText",g,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const p=qt(c);if(p&&!f("name",p)&&!h(p)){const n=e.locators.find(e=>"name"===e.name);ie(t,"name",p,c)&&(u.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=Yt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!h($)){const n=e.locators.find(e=>"className"===e.name);ie(t,"className",$,c)&&(u.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}Ct(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=Fe(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!_t(e.value,t,c));let a=0;for(const t of e){if(a>=e.length)break;const n=le(t.value);if(s.has(n))continue;const r=v.find(e=>e.value&&le(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=le(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 Wt)if(a.value.includes(e)){const r=Ft(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:jt(c)},{name:"name",value:qt(c)},{name:"className",value:Yt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Vt(c)}];for(const n of e){if(r.length>4)break;const{name:e,value:a}=n;a&&(h(a)||f(e,a)||"className"===e&&a.includes(" ")||ie(t,e,a,c)&&o(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}r.length<5&&Ct(c,"multiple").forEach(e=>{r.length>4||e.value&&(f("cssSelector",e.value)||ie(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 Gt={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," "),h(l))continue;const s=`//${r}[@${e}="${l}"]`;let i=0;try{i=v(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&&!h(n))){a.push(`@${l}="${n}"`);const o=`//*[${a.join(" and ")}]`;let s;r.push(`${l} == "${n}"`);try{s=v(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}},Bt=()=>({xpath:He,referenceXpaths:kt,xpathUtils:ce,getElementsFromHTML:Ht,cssSelectors:Xt,iosSelectors:Gt});e.createXPathAPI=Bt,e.default=Bt,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
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)})`,S(e),e.tagName.toLowerCase());return{token:t,count:A(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{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:""}},N=e=>v(e).fragment,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(null);return{owner:n,contextNode:r,cloneElement:l,cloneElements:o}},E=(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},S=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 x=r.startsWith("@"),E="."===r||"text()"===r,w=E?".":r,b=E&&/\s/.test(a.trim()),k=E?N(a):a,R=E&&i(a)?k:a,T=E?y(e,R):"";if("@class"===r){for(const n of c(e,a,t))if(v=d(n,S(e),e.tagName.toLowerCase()),u=g(v,e,t),1===u&&!o)return v;return}if(E&&i(a)&&!k)return;if(a&&(!x||!m(a))&&(v=T?d(T,S(e),e.tagName.toLowerCase()):b?d(`normalize-space(${w})=${p($(R)).trim()}`,S(e),e.tagName.toLowerCase()):n.test(a)?`//${s}[${r}=${p(R)}]`:d(`normalize-space(${r})=${p($(R)).trim()}`,S(e),e.tagName.toLowerCase()),u=g(v,e,t),1===u&&!o))return v;if(x&&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=S(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=S(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=S(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=S(e)?`//*[local-name()='${s}' and ${h.join(" and ")}]`:`//${s}[${h.join(" and ")}]`,u=g(v,e,t),1===u&&!o))return v}if(v=S(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,u=g(v,e,t),1===u&&!o)return v}},b=(e,t,r,a)=>{try{const a=r.filter(t=>E(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=()=>{const t=$(h(e)?.trim()||""),r=N(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))},s=(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},u=t=>S(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=s(a,n);for(const n of r){let r=[];for(const e of n){const t=o(e);t.length&&r.push(...t)}if(r.length<2)continue;const a=u(r);let l;try{l=g(a,e,t)}catch{continue}if(1===l)return a}}})();if(m)return m;const d=l();if(!d.length||!a.length)return;for(let n=1;n<=a.length;n++){const r=s(a,n);for(const n of r){let r=[];for(const e of n)r.push(...o(e));if(r.length)for(const n of d){const a=[...r,n],o=u(a);try{if(1===g(o,e,t))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},k=(e,t)=>{if(!e.textContent)return"";const r=(a=e,a?.childNodes[0]?.nodeValue||"");var a;const o=N(r);if(i(r)&&!o)return"";const l=i(r)?o:r,s=y(e,l);let c;return c=s?d(s,S(e),e.tagName||"*"):i(r)?d(`contains(normalize-space(.),${p(l)})`,S(e),e.tagName||"*"):!n.test(r)||/\s/.test(r.trim())?d(`normalize-space(.)=${p(l)}`,S(e),e.tagName||"*"):S(e)?`//*[local-name()='${e.tagName}' and .=${p(l)}]`:`//${e.tagName||"*"}[.=${p(l)}]`,c},R=(e,t,n)=>{if(("."===t||"text()"===t)&&i(n)){const{fragment:t}=v(n);return t?d(`contains(normalize-space(.),${p(t)})`,S(e),e.tagName.toLowerCase()):""}return d(`normalize-space(${t})=${p($(n)).trim()}`,S(e),e.tagName.toLowerCase())},T=(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)})`,S(e),e.tagName.toLowerCase()):""}return d(`starts-with(${t},${p($(n)).trim()})`,S(e),e.tagName.toLowerCase())},C=(e,t,n)=>{if(("."===t||"text()"===t)&&i(n)){const{fragment:t}=v(n);return t?d(`contains(normalize-space(.),${p(t)})`,S(e),e.tagName.toLowerCase()):""}return d(`contains(${t},${p($(n)).trim()})`,S(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]}`,S(e),e.tagName.toLowerCase());const a=(()=>{const t=$(h(e)?.trim()||""),r=N(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}`,S(e),e.tagName.toLowerCase()):""},A=(e,t,n)=>{try{return g(e,t,n)}catch(e){return 0}},D=(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)&&_(a,e,t)&&(r.add(a),n.push(a))};l.forEach(t=>{if(E(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=k(e);t&&s(t)}if(a.length>1){const n=b(e,t,a);n&&s(n)}return n},P=(e,t)=>{const n=[];let r=t;for(;r&&r!==e;)n.unshift(Y(r)),r=r.parentElement;return r===e?n.join("/"):""},z=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),r=Y(e),a=S(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const a=D(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=A(a,e,n);if(console.log(`Match count: ${l}`),1===l&&O(a,n)===e)return console.log(`Selected XPath: ${a}`),a;const s=P(t,e);if(s){const t=`${o}/${s}`;console.log(`Trying descendant XPath: ${t}`);const r=A(t,e,n);if(console.log(`Match count: ${r}`),1===r&&O(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${a}`);const o=A(a,e,n);return console.log(`Match count: ${o}`),1===o&&O(a,n)===e?(console.log(`Selected XPath: ${a}`),a):(console.log("Selected XPath: "),"")},O=(e,t)=>{try{if(n=t,n?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in n){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}var n},_=(e,t,n)=>{try{const{first:r,second:o}=a(e,n);return!!r&&!o&&r===t}catch{return!1}},Y=e=>S(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),X=(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))&&E(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&&_(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&&_(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=k(e);n&&_(n,e,t)&&l("anchor by text",n)}if(o.length>1){const n=b(e,t,o);n&&_(n,e,t)&&l("anchor by combination",n)}const c=z(e,t);return c&&_(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=>S(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(i(n))return[];a=r.test(n)?S(e)?`//*[local-name()='${e.tagName}' and @${t}=${p(n)}]`:`//${e.tagName||"*"}[@${t}=${p(n)}]`:S(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`}return a?[a]:[]},j=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 H(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 I=[];const W={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},F=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),G=(e,t)=>t?e:e.filter(e=>{return t=e.value,!(/(?:^|\/)[^/\[]+\[\d+\](?=\/|$)/.test(t)||/^\(.+\)\[\d+\]$/.test(t));var t}),B=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",Z=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},U=(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},J=(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:()=>Z(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},K=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},Q=(e,t,n,r,a,o,l)=>{const s=Y(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(K(e))continue;const f=[()=>X(e,r),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&E(t,e));for(const r of n){const n=r.value;if(!n)continue;const a=C(e,`@${r.name}`,n);a&&t.push({key:"contains",value:a});const o=T(e,`@${r.name}`,n);o&&t.push({key:"starts-with",value:o})}return t},()=>[{key:"tag",value:z(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(_(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(_(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(K(a))continue;const e=X(a,r);for(const a of e.slice(0,5)){const e=`${a.value}/${t}::${s}`;if(_(e,n,r)){if(i.push({key:o,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},ee=(e,t,n,r)=>{const a=[];for(let t=e.parentElement;t;t=t.parentElement)a.push(t);const o=Z(e),l=U(e,"previous"),s=U(e,"next"),i=J(e,"previous"),c=J(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"}]];for(const n of f)for(const a of n){const n=Q(a.nodes,a.axis,e,t,0,a.key,r);if(n.length>0)return n}return[]},te=(e,t,n,r,a)=>{const o=(e=>W[e]||e)(r);return"text"===o?F(r,((e,t,n)=>{if(!B(e))return[];if("text"===n){const n=k(e)||ne(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?F(r,((e,t,n)=>{const r=[],a=Array.from(e.attributes||[]).filter(t=>t?.value&&E(t,e)),o=B(e),l="contains"===n?C:"startsWith"===n?T:"normalizeSpace"===n?R: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)?F(r,((e,t,n,r)=>{const a=Array.from(e.attributes||[]).filter(t=>t?.value&&E(t,e));if("and"===r){const n=b(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?F(r,ee(e,t,0,!1)):"index"===o?F(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?F(r,[{key:"xpath till tag",value:z(e,t)}]):[]};const ne=(e,t,n,r)=>{if(""!=(e.textContent??"").trim()){const a=h(e);if(a)return w(e,t,".",a,n,r)}},re=(e,t,n,r,a)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&E(e,t)){const o=((e,t,n,r,a)=>{let o;if(o=e.name,E(e,t))return w(t,n,`@${o}`,e.value,r,a)})(e,t,n,r,a);o&&I.push({key:`xpath by ${e.name}${r?" index":""}`,value:o})}});const l=ne(t,n,r,a);if(l&&I.push({key:"xpath by text"+(r?" index":""),value:l}),o.find(e=>"className"===e.name)&&E(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&&E({name:"class",value:a},e))return w(e,t,"@class",a,n,r)})(t,n,r,a);e&&I.push({key:"xpath by class",value:e})}if(!I.length&&o.length>1){const e=b(t,n,o);e&&I.push({key:"xpath by combination",value:e})}if(!I.length){const r=function(e,t,n){const{tagName:r}=t,a=t.textContent.trim();if(!a)return;const o=$(a),l=N(o);if(i(o)&&!l)return;const s=i(o)?l:o,c=y(t,s);for(const l of e)if(E(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&&I.push({key:"xpath by textAttribute",value:r})}}catch(e){console.log(e)}},ae=(e,t,n,r,a=[],o=[])=>{I=[],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(re(m,l,c,n,r),o.length){const e=o.flatMap(e=>te(l,c,0,e));return I=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(e.filter(e=>1===g(e.value,l,c))),G(I,n)}if(I.length){const t=I.length;for(let n=0;n<t;n++){let t=I[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===g(t,e,c)&&I.push({key:`${I[n].key} regex`,value:t})}}return I.length||i||(I=ee(l,c,0,n)),G(I,n)};let oe=[];const le=(e,t,n)=>{try{const r=n.querySelectorAll(e);return 1===r.length&&r[0]===t}catch{return!1}},se=(e,t="single")=>{const n=[],r=e.getRootNode();try{const a=ie(e);if(a&&le(a,e,r)&&(n.push({key:"cssSelector by id",value:a}),"single"===t))return n;const o=me(e);o&&le(o,e,r)&&n.push({key:"cssSelector by class",value:o});const l=fe(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},ie=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(" > ")},ce=new Set(["id","class","style"]);function ue(e){return Array.from(e.attributes).filter(e=>!ce.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 fe=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=ue(e);for(const t of a){const a=`${r}${t}`;if(le(a,e,n))return a}},me=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const r=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||m(e.className)||oe?.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(" > ")},de=(e,t,n)=>{const r=j(e);if(Se(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},he=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return $e(e.body,t)},ge=(e,t,n)=>he(t,e)===n,pe=e=>e.name?.toLowerCase().includes("cssselector")??!1,$e=(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=$e(r,t);if(e)return e;if(r&&!t.includes("dynamic"))return r.querySelector(t)}}}catch(e){console.log(e)}return null},ye=e=>e?.id||null,ve=e=>e.className||null,Ne=e=>e.textContent?.trim()||null,xe=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Ee=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Se(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 we(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 be=(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(pe(t))return he(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=Se(e,j(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=$e(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=>pe(e)&&e.value);for(const e of n)de(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of r)ge(e.value,t,c)&&o(e,{isSelfHealed:null});const l=a.filter(e=>"xpath"===e.name&&e.value),s=new Set(l.map(e=>H(e.value))),u=[],d=ye(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=Ne(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=xe(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 $=ve(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:$}))}se(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=ae(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!de(e.value,t,c));let r=0;for(const t of e){if(r>=e.length)break;const n=H(t.value);if(s.has(n))continue;const a=v.find(e=>e.value&&H(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=H(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 Ee)if(r.value.includes(e)){const a=we(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:ye(c)},{name:"name",value:xe(c)},{name:"className",value:ve(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Ne(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&&se(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 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 ke(){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=>be(e,o.document)}}}}export{ke 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 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};
2
2
  //# sourceMappingURL=xpath.mjs.map