ff-dom 3.0.0-beta.1 → 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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/i;let t=new WeakMap;const n=e=>{e?(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const a=e.getRootNode?.();return(a instanceof Document||a instanceof ShadowRoot)&&n(a),n(e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument),t})(e).forEach(e=>{t.delete(e)}):t=new WeakMap},a=(e,n)=>{const{owner:a,contextNode:l}=(e=>{const t=9===e.nodeType?e:e.ownerDocument||document;return{owner:t,contextNode:1===e.nodeType||9===e.nodeType||11===e.nodeType?e:t}})(n);let r=t.get(l);r||(r=new Map,t.set(l,r));const o=r.get(e);if(o)return o;const s=a.evaluate(e,l,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return r.set(e,i),i};let l,r=new Map,o=[];const s=new Set(["marked-element-temp","removePointers"]),i=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!s.has(e)).sort(),c=(e,t)=>t?"class"===e||"className"===e?i(t).join(" "):t.replace("removePointers","").trim():"",u=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(w(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=i(e.oldValue),n=i(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},f=e=>/\d/.test(e),m=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,h=e=>{const t=e?.textContent;return t},d=e=>e?.childNodes[0]?.nodeValue||"",g=(e,t,n,l=!1)=>{try{const{first:r,second:o}=a(e,n);if(!r)return 0;if(!o)return r===t?1:0;if(l&&Array.isArray(t)){let a=0;if(t.includes(r)&&a++,t.includes(o)&&a++,2===a)return 2;const l=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=l.iterateNext();)if(t.includes(s)&&(a++,2===a))return 2;return 0}return 2}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},p=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},$=e=>{const t=e.split("");let n=t.length;const a=[];for(;"["!==t[n-2];)a.push(t[n-2]),n--;a.reverse();let l="";for(let e=0;e<a.length;e++)l+=a[e];const r=l.length+2;let o=e.slice(0,e.length-r);return o=o.startsWith("(")&&o.endsWith(")")?o.slice(1,-1):e,o},y=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===g(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===g(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const o=l.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=o.iterateNext();)if(r++,s.isSameNode(t))return 1===g(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===g(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},v=e=>(e=(e=(e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(e)).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim()).split("/")[0].trim(),N=e=>e?e.replace(/\s\s+/g," ").trim():e,x=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},b=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),a=n.createElement("div");a.innerHTML=e.innerHTML,n.body.appendChild(a);const l=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let a=t;for(;a&&a.parentElement;){const e=a.parentElement;n.unshift(Array.from(e.children).indexOf(a)),a=e}return a&&a.parentNode===e?(n.unshift(Array.from(e.children).indexOf(a)),n):null})(e,t);return n?((e,t)=>{let n=e;for(const e of t){const t=n.children.item(e);if(!t)return null;n=t}return n})(a,n):null},r=Array.isArray(t)?t.map(e=>l(e)).filter(Boolean):[],o=Array.isArray(t)?null:l(null);return{owner:n,contextNode:a,cloneElement:o,cloneElements:r}},E=(e,t,n)=>{const a=c(e.name,e.value);if(!a||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(e=>e===a))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const l=o?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!l&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(!n||!f(a))))},w=e=>e instanceof SVGElement,S=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,k=(t,n,a,l,r,o)=>{if(l){const{tagName:s}=t;let i,c="";const u=[];let h;if(l&&(!o||!f(l))&&(h=e.test(l)?`//${s}[${a}=${p(l)}]`:m(`normalize-space(${a})=${p(N(l)).trim()}`,w(t),t.tagName.toLowerCase()),i=g(h,t,n),1===i&&!r))return h;if(l&&o){const o=l.split(" ");if(o?.length)if(1===o.length){const u=[...new Set(o[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&N(u[0].trim())?.length>1&&l.startsWith(u[0])&&(c=e.test(u[0])?`starts-with(${a},${p(u[0]).trim()})`:`starts-with(${a},${p(N(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&N(u[u.length-1].trim())?.length>1&&l.endsWith(u[u.length-1])&&(c=e.test(u[u.length-1])?`ends-with(${a},${p(u[u.length-1]).trim()})`:`ends-with(${a},${p(N(u[u.length-1])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h}else{const u=o.length%2==0?o.length/2:o.length%2,f=o.slice(0,u).join(" ");let m=[...new Set(f.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&N(m[0].trim())?.length&&l.startsWith(m[0])&&(c=e.test(m[0])?`starts-with(${a},${p(m[0]).trim()})`:`starts-with(${a},${p(N(m[0])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h;const d=o.slice(u,o.length-1).join(" ");if(m=[...new Set(d.match(/([^0-9]+)/g))],m?.length&&m[0]&&N(m[0].trim())?.length>3&&l.endsWith(m[0])&&(c=e.test(m[0])?`ends-with(${a},${p(m[0]).trim()})`:`ends-with(${a},${p(N(m[0])).trim()})`),c?.length&&(h=w(t)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=g(h,t,n),1===i&&!r))return h}}if(l&&o&&f(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let t=0;t<o?.length;t++)o[t]&&N(o[t].trim())?.length>1&&(e.test(o[t])?u.push(`contains(${a},${p(o[t].trim()).trim()})`):u.push(`contains(${a},${p(N(o[t])).trim()})`));if(u?.length&&(h=w(t)?`//*[local-name()='${s}' and ${u.join(" and ")}]`:`//${s}[${u.join(" and ")}]`,i=g(h,t,n),1===i&&!r))return h}if(h=w(t)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=g(h,t,n),1===i&&!r)return h}},C=(e,t)=>{try{if(!e)return"";let n=w(e)?`/*[local-name()='${e.tagName}']`:`/${e.tagName}`;if(e.parentElement){const t=Array.prototype.slice.call(e.parentElement.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}else if(e instanceof HTMLElement&&e.offsetParent){const t=Array.prototype.slice.call(e.offsetParent.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}return C(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},R=(e,t,n,a=!1,l)=>{try{if(r.has(e))return r.get(e);const o=[];let s=e;for(;s;){let r="",i=!1,u=e===s?l??s.attributes:s.attributes;for(const e of Array.from(u))if(E(e,s,a)){const a=c(e.name,e.nodeValue),l=e.name;r=H(s,l,a);let u=0;if(r&&(u=g(r,s,t),1===u)){o.unshift(S(r)),i=!0;break}if(u>1&&n&&(r=y(r,s,t,u),r)){o.unshift(S(r)),i=!0;break}}if(s.textContent)if(!a||a&&!f(s.textContent)){r=new RegExp(/^[\S]+( [\S]+)*$/gi).test(s.textContent)?w(s)?`//*[local-name()='${s.tagName}' and .=${p(d(s))}]`:`//${s.tagName||"*"}[.=${p(d(s))}]`:w(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${p(d(s))}]`:`//${s.tagName||"*"}[normalize-space(.)=${p(d(s))}]`;let e=g(r,s,t);if(1===e)return r;if(e>1&&n)return r=y(r,s,t,e),r}else{let e=[];const a=[...new Set(d(s).match(/([^0-9]+)/g))];let l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&N(a[t].trim())&&(l.test(a[t])?e.push(`contains(.,${p(a[t].trim()).trim()})`):e.push(`contains(.,${p(N(a[t])).trim()})`));if(e?.length){r=w(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=g(r,s,t);if(1===a)return r;if(a>1&&n)return r=y(r,s,t,a),r}}if(i)break;{let e=w(s)?`/*[local-name()='${s.tagName}']`:`/${s.tagName}`;if(s.parentElement){const t=Array.from(s.parentElement.children).filter(e=>e.tagName===s.tagName);if(t.length>1){e+=`[${t.indexOf(s)+1}]`}}o.unshift(e)}s=s.parentElement}const i=`${o.join("")}`;return r.set(e,i),i}catch(e){return console.log(e),null}},O=(t,n)=>{const a=[];let l="";if(t&&!f(t.value)&&"function"!=typeof t.nodeValue){const r=[...new Set(t.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&N(r[n].trim())?.length>2&&(e.test(r[n])?a.push(`contains(@${t.name},${p(r[n].trim())})`):a.push(`contains(@${t.name},${p(N(r[n])).trim()})`));if(a?.length)return l=w(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},T=(t,n,a,l)=>{try{const r=a.filter(e=>E(e,t,l)),o=a=>{const l=c(a.name,a.nodeValue);if(!l)return[];if("class"===a.name){const e=l.split(/\s+/).map(e=>e.trim()).filter(Boolean);if(!e.length)return[];const a=e.map(e=>{const a=m(`contains(@class,${p(e)})`,w(t),t.tagName.toLowerCase());return{token:e,count:I(a,t,n)}}).sort((e,t)=>e.count!==t.count?e.count-t.count:t.token.length-e.token.length);return a[0]?.token?[`contains(@class,${p(a[0].token)})`]:[]}return e.test(l)?[`@${a.name}="${l}"`]:[`normalize-space(@${a.name})="${l}"`]},s=()=>{const n=N(h(t)?.trim()||"");if(!n||n.length>80||/^\d+$/.test(n))return[];const a=new Set;return e.test(n)&&n.length<=40&&a.add(`text()=${p(n)}`),n.includes(" ")&&a.add(`normalize-space(text())=${p(N(n))}`),a.add(`contains(text(),${p(n)})`),Array.from(a)},i=(e,t)=>{const n=[],a=(l,r)=>{if(r.length!==t)for(let t=l;t<e.length;t++)r.push(e[t]),a(t+1,r),r.pop();else n.push([...r])};return a(0,[]),n},u=e=>w(t)?`//*[local-name()='${t.tagName}' and ${e.join(" and ")}]`:`//${t.tagName}[${e.join(" and ")}]`,f=()=>{if(!(r.length<2))for(let e=2;e<=r.length;e++){const a=i(r,e);for(const e of a){let a=[];for(const t of e){const e=o(t);e.length&&a.push(...e)}if(a.length<2)continue;const l=u(a);let r;try{r=g(l,t,n)}catch{continue}if(1===r)return l}}},d=f();if(d)return d;const $=s();if(!$.length||!r.length)return;for(let e=1;e<=r.length;e++){const a=i(r,e);for(const e of a){let a=[];for(const t of e)a.push(...o(t));if(a.length)for(const e of $){const l=[...a,e],r=u(l);try{if(1===g(r,t,n))return r}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},A=(t,n,a)=>{let l=w(t),r="";if(E(n,t,a)){let a=c(n.name,n.value);const o=n.name;r=e.test(a)?l?`*[local-name()='${t.tagName}' and @${o}=${p(a)}]`:`${t.tagName||"*"}[@${o}=${p(a)}]`:l?`*[local-name()='${t.tagName}' and normalize-space(@${o})=${p(a)}]`:`${t.tagName||"*"}[normalize-space(@${o})=${p(a)}]`}return r},D=(t,n)=>{if(!t.textContent)return"";const a=d(t);let l;return l=e.test(a)?w(t)?`//*[local-name()='${t.tagName}' and .=${p(a)}]`:`//${t.tagName||"*"}[.=${p(a)}]`:w(t)?`//*[local-name()='${t.tagName}' and normalize-space(.)=${p(a)}]`:`//${t.tagName||"*"}[normalize-space(.)=${p(a)}]`,l},P=(e,t,n)=>m(`normalize-space(${t})=${p(N(n)).trim()}`,w(e),e.tagName.toLowerCase()),X=(e,t,n)=>m(`starts-with(${t},${p(N(n)).trim()})`,w(e),e.tagName.toLowerCase()),_=(e,t,n)=>m(`contains(${t},${p(N(n)).trim()})`,w(e),e.tagName.toLowerCase()),L=(t,n)=>{const a=n.map(n=>(n=>{const a=c(n.name,n.value);if(!a)return null;if("class"===n.name){const e=a.split(/\s+/).map(e=>e.trim()).filter(Boolean),n=t.getRootNode?.()??t.ownerDocument,l=e.map(e=>{const a=m(`contains(@class,${p(e)})`,w(t),t.tagName.toLowerCase());return{token:e,count:I(a,t,n)}}).sort((e,t)=>e.count!==t.count?e.count-t.count:t.token.length-e.token.length)[0]?.token;return l?`contains(@class,${p(l)})`:null}return e.test(a)?`@${n.name}=${p(a)}`:`normalize-space(@${n.name})=${p(a)}`})(n)).filter(Boolean);if(a.length>=2)return m(`${a[0]} or ${a[1]}`,w(t),t.tagName.toLowerCase());const l=(()=>{const n=N(h(t)?.trim()||"");return!n||n.length>80||/^\d+$/.test(n)?null:e.test(n)&&n.length<=40?`text()=${p(n)}`:n.includes(" ")?`normalize-space(text())=${p(n)}`:`contains(text(),${p(n)})`})();return 1===a.length&&l?m(`${a[0]} or ${l}`,w(t),t.tagName.toLowerCase()):""},I=(e,t,n)=>{try{return g(e,t,n)}catch(e){return 0}},M=(e,t)=>{const n=[],a=new Set,l=Array.from(e.attributes||[]),r=["id","data-testid","data-test","data-qa","name","aria-label","role"],o=[...r.map(e=>l.find(t=>t.name===e)).filter(Boolean),...l.filter(e=>!r.includes(e.name))],s=l=>{l&&!a.has(l)&&V(l,e,t)&&(a.add(l),n.push(l))};o.forEach(t=>{if(!E(t,e,!1))return;const n="id"===t.name?`//*[@id=${p(c(t.name,t.value))}]`:H(e,t.name,t.value);n&&s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=D(e);t&&s(t)}if(l.length>1){const n=T(e,t,l,!1);n&&s(n)}return n},j=(e,t)=>{const n=[];let a=t;for(;a&&a!==e;)n.unshift(q(a)),a=a.parentElement;return a===e?n.join("/"):""},Y=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),a=q(e),l=w(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const l=M(t,n);for(const r of l){console.log(`Trying ancestor XPath: ${r}`);const l=`${r}/descendant::${a}`;console.log(`Trying descendant XPath: ${l}`);const o=I(l,e,n);if(console.log(`Match count: ${o}`),1===o&&z(l,n)===e)return console.log(`Selected XPath: ${l}`),l;const s=j(t,e);if(s){const t=`${r}/${s}`;console.log(`Trying descendant XPath: ${t}`);const a=I(t,e,n);if(console.log(`Match count: ${a}`),1===a&&z(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${l}`);const r=I(l,e,n);return console.log(`Match count: ${r}`),1===r&&z(l,n)===e?(console.log(`Selected XPath: ${l}`),l):(console.log("Selected XPath: "),"")},z=(e,t)=>{try{if(n=t,n?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in n){const{owner:n,contextNode:a,cloneElement:l}=b(t);return n.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||l}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}var n},V=(e,t,n)=>{try{const{first:l,second:r}=a(e,n);return!!l&&!r&&l===t}catch{return!1}},q=e=>w(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),W=(e,t,n)=>{if(!(e instanceof Element))return[];const a=new Set,l=[],r=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(a=t.value,!/\d/.test(a))&&E(t,e,n);var a}),o=(e,t)=>{t&&!a.has(t)&&(a.add(t),l.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","aria-label","role"];s.forEach(n=>{const a=r.find(e=>e.name===n);if(!a)return;const l="id"===n?`//*[@id='${a.value}']`:H(e,a.name,a.value);l&&V(l,e,t)&&o(`anchor by ${a.name}`,l)}),r.forEach(n=>{if(s.includes(n.name))return;const a=H(e,n.name,n.value);a&&V(a,e,t)&&o(`anchor by ${n.name}`,a)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=D(e);n&&V(n,e,t)&&o("anchor by text",n)}if(r.length>1){const a=T(e,t,r,n);a&&V(a,e,t)&&o("anchor by combination",a)}const c=Y(e,t);return c&&V(c,e,t)&&o("anchor by tag",c),l},U=e=>{const t=h(e)?.trim(),n=t?p(v(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},H=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return(n=c(t,n))&&(l=a.test(n)?"class"===t?w(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`:w(e)?`//*[local-name()='${e.tagName}' and @${t}=${p(n)}]`:`//${e.tagName||"*"}[@${t}=${p(n)}]`:w(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${p(n)})]`:`//${e.tagName||"*"}[contains(@${t},${p(n)})]`),l},F=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,B=(t,n,a)=>{let l;const r=[];if(t.textContent&&(!a||a&&!f(t.textContent))&&(e.test(t.textContent)?(l=w(t)?`*[local-name()='${t.tagName}' and .=${p(h(t))}]`:`${t.tagName}[.=${p(h(t))}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})):(l=w(t)?`*[local-name()='${t.tagName}' and ${U(t)})]`:`${t.tagName}[${U(t)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))),t.attributes)for(const e of Array.from(t.attributes))if(E(e,t,a)){let n=e.nodeValue;if(n){n=c(e.name,n);const a=e.name;l="class"===a?w(t)?`*[local-name()='${t.tagName}' and contains(@${a},${p(n)})]`:`${t.tagName}[contains(@${a},${p(n)})]`:w(t)?`*[local-name()='${t.tagName}' and @${a}=${p(n)}]`:`${t.tagName}[@${a}=${p(n)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})}}if(!r?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=T(t,n,Array.prototype.slice.call(t.attributes),a);e&&r.push({key:"getReferenceElementsXpath",value:e})}}if(!r?.length){const n=[];let l;const o=w(t);if(t.textContent&&a&&f(t.textContent)){const a=[...new Set(t.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&N(a[t].trim())?.length>1&&(e.test(a[t])?n.push(`contains(.,${p(a[t]).trim()})`):n.push(`contains(.,${p(N(a[t])).trim()})`));n?.length&&(l=o?`//*[local-name()='${o}' and ${n.join(" and ")}]`:`//${o}[${n.join(" and ")}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))}}if(!r?.length){const e=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(E(e,t,a)){const n=O(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(t.attributes,t,0,a);e?.length&&r.concat(e)}return r},G=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1"),J=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function Z(e){const t=function(e){return e.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e),n=function(e){const t=e.toLowerCase(),n=t.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=n?.[1]??"none",l=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:l?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function K(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function Q(e,t,n,a){const l=a?.getRootNode?.()??e,r=e=>{try{return Array.from(l.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===r(`#${K(n)}`).length;case"name":return 1===r(`[name="${K(n)}"]`).length;case"className":return 1===r(`.${n}`).length;case"tagName":case"cssSelector":return 1===r(n).length;case"linkText":return 1===r("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===r("a").filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const ee={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:B,getAbsoluteXPath:C,getRelativeXPath:R,getCombinationXpath:O,getAttributeCombinationXpath:T,getElementFromXpath:(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const l=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?l.evaluate(e,a,null,XPathResult.ANY_TYPE,null):l.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},isSvg:w,findXpathWithIndex:y,isNumberExist:f,getTextContent:h,getCountOfXPath:g,normalizeXPath:G,getShadowRoot:x,escapeCharacters:p,removeParenthesis:$,checkBlockedAttributes:E,getRelationship:(e,t)=>{let n=e.compareDocumentPosition(t);return 2===n?"preceding":4===n?"following":8===n?"ancestor":16===n?"descendant":32===n?"self":""},findMatchingParenthesis:J,deleteGarbageFromInnerText:v,replaceTempAttributes:S,createObserver:e=>{l=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!u(t))&&n(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(u(t)||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||o.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{l?.observe(e,t)},stopObserver:()=>{l?.disconnect()},modifiedElementAttributes:o,cspEnabled:!1,getXPathPattern:Z,getNormalizedPropertyXPath:P,getStartsWithPropertyXPath:X,getContainsPropertyXPath:_,getOrAttributesXPath:L,getTagOnlyXPath:Y,getFirstMatchedNode:z,isExactUniqueXpath:V,getAxisNodeTest:q,getUniqueNodeAnchorXpaths:W,escapeAttrValue:K,isUniqueInDOM:Q,sanitizeAttributeValue:c};let te=[],ne=[],ae=new Map,le=new Map;const re=new Map,oe={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},se=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),ie=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ce=e=>{if(!(e&&e instanceof Element))return[];const t=[],n=Array.from(e.children||[]);for(;n.length;){const e=n.shift();e.classList?.contains("flntooltip")||(t.push(e),n.push(...Array.from(e.children||[])))}return t},ue=(e,t)=>{const n=[];let a="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;a;)a.classList?.contains("flntooltip")||n.push(a),a="previous"===t?a.previousElementSibling:a.nextElementSibling;return n},fe=(e,t)=>{const n=[];for(let a=e;a?.parentElement;a=a.parentElement){let e="previous"===t?a.previousElementSibling:a.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>ce(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},me=e=>{if(!(e instanceof Element))return!0;const t=e.textContent?.trim();return!e.id&&!e.className&&0===e.attributes.length&&(!t||t.length>60)&&e.children.length>2},he=(e,t,n,a,l,r,o)=>{const s=q(n),i=[];let c=0;const u=t.includes("descendant")?10:20;for(const f of e){if(c++>u)break;if(i.length>=5)break;const e="node"in f?f.node:f;if(!(e instanceof Element))continue;if(me(e))continue;const m=[()=>W(e,a,l),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&!/\d/.test(t.value)&&E(t,e,l));for(const a of n){const n=a.value;if(!n)continue;const l=_(e,`@${a.name}`,n);l&&t.push({key:"contains",value:l});const r=X(e,`@${a.name}`,n);r&&t.push({key:"starts-with",value:r})}return t},()=>[{key:"tag",value:Y(e,a)}]];for(let l=0;l<m.length;l++){let c=m[l]();if(!c.length)continue;o||(c=c.filter(e=>!/\[\d+\]/.test(e.value)));const u=new Set;c=c.filter(e=>!u.has(e.value)&&(u.add(e.value),!0)),c=c.slice(0,5);for(const e of c){const l=`${e.value}/${t}::${s}`;if(V(l,n,a)){if(i.push({key:r,value:l}),i.length>=2)return i;if(i.length>=5)return i}}if(o&&l===m.length-1)for(const l of c){const o=g(l.value,e,a);for(let e=1;e<=Math.min(o,3);e++){const o=`(${l.value})[${e}]/${t}::${s}`;if(V(o,n,a)){if(i.push({key:r,value:o}),i.length>=2)return i;if(i.length>=5)return i}}}}if("expand"in f&&f.expand){const e=f.expand();let o=0;for(const c of e){if(o++>15)break;if(i.length>=5)break;if(!(c instanceof Element))continue;if(me(c))continue;const e=W(c,a,l);for(const l of e.slice(0,5)){const e=`${l.value}/${t}::${s}`;if(V(e,n,a)){if(i.push({key:r,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},de=(e,t,n,a)=>{const l=[];for(let t=e.parentElement;t;t=t.parentElement)l.push(t);const r=ce(e),o=ue(e,"previous"),s=ue(e,"next"),i=fe(e,"previous"),c=fe(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(s),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(o),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(l),axis:"child",key:"child"},{nodes:u(r,15),axis:"parent",key:"parent"}],[{nodes:u(l),axis:"descendant",key:"descendant"},{nodes:u(l),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(r,10),axis:"ancestor",key:"ancestor"},{nodes:u(r,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]];for(const l of f)for(const r of l){const l=he(r.nodes,r.axis,e,t,n,r.key,a);if(l.length>0)return l}return[]},ge=(e,t,n,a,l)=>{const r=(e=>oe[e]||e)(a);return"text"===r?se(a,((e,t,n)=>{if(!ie(e))return[];if("text"===n){const n=D(e)||Se(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,r)):["contains","startsWith","normalizeSpace"].includes(r)?se(a,((e,t,n)=>{const a=[],l=Array.from(e.attributes||[]).filter(n=>n?.value&&E(n,e,t)),r=ie(e),o="contains"===n?_:"startsWith"===n?X:"normalizeSpace"===n?P:null;if(!o)return a;if(l.forEach(t=>{const l=o(e,`@${t.name}`,t.value);l&&a.push({key:`xpath by ${n} ${t.name}`,value:l})}),r){const t=o(e,".",r);t&&a.push({key:`xpath by ${n} text`,value:t})}return a})(e,n,r)):["and","or"].includes(r)?se(a,((e,t,n,a)=>{const l=Array.from(e.attributes||[]).filter(t=>t?.value&&E(t,e,n));if("and"===a){const a=T(e,t,l,n);return a?[{key:"xpath by combination",value:a}]:[]}if("or"===a&&l.length>=1){const t=L(e,l);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,n,r)):"axes"===r?se(a,de(e,t,n,!1)):"index"===r?se(a,((e,t)=>{const n=[],a=e.tagName.toLowerCase(),l=Array.from(t.querySelectorAll(a)).indexOf(e)+1;if(l<=0)return[];n.push({key:"xpath by index",value:`(//${a})[${l}]`});let r=e.parentElement;for(;r&&r!==t.body;){if(r.id||r.className){const t=r.className?.toString().split(" ").map(e=>e.trim()).find(Boolean),l=r.id?`//${r.tagName.toLowerCase()}[@id='${r.id}']`:t?`//${r.tagName.toLowerCase()}[contains(@class,'${t}')]`:"";if(!l){r=r.parentElement;continue}const o=Array.from(r.querySelectorAll(a)).indexOf(e)+1;if(o>0){n.push({key:"xpath by index",value:`(${l}//${a})[${o}]`});break}}r=r.parentElement}return n})(e,t)):"tag"===r?se(a,[{key:"xpath till tag",value:Y(e,t)}]):[]},pe=(e,t,n,a,l,r)=>{if(e){let o;o="parent"===r?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of o){ae?.get(e)||ae.set(e,g(e,n,a));const t=ae?.get(e);if(1===t)return e;if(t>1&&(ne.length?t<ne[0].count&&(ne.pop(),ne.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):ne.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!te.length){const r=y(e,n,a,t);r&&1===g(r,n,a)&&te.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},$e=(t,n,a,l,r,o)=>{try{if(re.has(t))return re.get(t);const s=[];let i=t;for(;i&&1===i.nodeType;){const t=!1;for(const e of Array.from(i.attributes))if(E(e,i,l)){const t=c(e.name,e.nodeValue),l=e.name,s=H(i,l,t);let u;try{u=pe(s,r,a,n,o,"parent")}catch(e){continue}if(u)return u}if(i.textContent&&!i.textContent)if(!l||l&&!f(i.textContent)){let t;t=e.test(i.textContent)?w(i)?`//*[local-name()='${i.tagName}' and .=${p(d(i))}]`:`//${i.tagName||"*"}[.=${p(d(i))}]`:w(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${p(d(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${p(d(i))}]`;const l=pe(t,r,a,n,o,"parent");if(l)return l}else{const e=[],t=[...new Set(d(i).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&N(t[n].trim())&&(l.test(t[n])?e.push(`contains(.,${p(t[n].trim()).trim()})`):e.push(`contains(.,${p(N(t[n])).trim()})`));if(e?.length){const t=w(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,l=pe(t,r,a,n,o,"parent");if(l)return l}}if(!t){const e=w(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const u=s.join("")+r;if(1===g(u,t,n))return re.set(t,u),u}catch(e){return console.error(e),null}},ye=(e,t,n,a)=>{const l=new Map;if(l.has(e))return l.get(e);const r=[];let o=e;try{for(;o&&1===o.nodeType;){if(!o.tagName)return"";let e=!1;for(const n of Array.from(o.attributes))if(E(n,o,a)){const a=c(n.name,n.nodeValue),l=n.name,s=H(o,l,a);let i;try{i=g(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=D(o);if(n){if(1===g(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=w(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}const s=r.join("");return l.set(e,s),s}catch(e){return console.log(e),null}},ve=(e,t,n)=>{const a=[];let l;const r=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?r.unshift(e.firstElementChild):null!=e.nextElementSibling&&r.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&r.unshift(t.nextElementSibling);try{do{let e=!1;for(l=r.pop();null!==l;){for(const n of Array.from(l.attributes))if(E(n,l,!0)){const r=c(n.name,n.nodeValue),o=n.name,s=H(l,o,r);let i;try{i=g(s,l,t)}catch(e){continue}if(1===i){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=D(l);if(n){if(1===g(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=w(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;a.push(e),null!=l.firstElementChild?(r.push(l.nextElementSibling),l=l.firstElementChild):l=l.nextElementSibling}}}while(r.length>0);const o=a.join("");return le.set(e,o),o}catch(e){return console.log(e),null}},Ne=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)xe(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)xe(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},xe=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=A(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=g(o,e,n);if(1===t)return void te.push({key:`xpath by ${l}`,value:o});t>1&&(ne.length?t<ne[0].count&&(ne.pop(),ne.push({key:`relative xpath by ${l}`,value:o,count:t})):ne.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=A(e,{name:"text",value:e.textContent},r),t){const a=g(t,e,n);if(1===a)return void te.push({key:`xpath by ${l}`,value:t});a>1&&(ne.length?a<ne[0].count&&(ne.pop(),ne.push({key:`relative xpath by ${l}`,value:t,count:a})):ne.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};function be(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();if(r)for(const o of e)if(E(o,t,a)){let e=c(o.name,o.nodeValue);const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==g(a,t,n))return a}}}const Ee=(e,t,n,a,l)=>{let r;return r=e.name,k(t,n,`@${r}`,e.value,a,l)},we=(e,t,n,a)=>{let l=e.className;if("string"!=typeof l&&(l=""),l=l?.replace("flndisabled","disabled"),l=c("class",l),l=l?.trim(),l)return k(e,t,"@class",l,n,a)},Se=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const l=h(e);if(l)return k(e,t,".",l,n,a)}},ke=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&E(e,t,l)){const r=Ee(e,t,n,a,l);r&&te.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=Se(t,n,a,l);if(o&&te.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&E(r?.find(e=>"className"===e.name),t,l)){let e=we(t,n,a,l);e&&te.push({key:"xpath by class",value:e})}if(!te.length&&r.length>1){const e=T(t,n,r,l);e&&te.push({key:"xpath by combination",value:e})}if(!te.length){const a=be(e,t,n,l);a&&te.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},Ce=(e,t,n,a,l=[],r=[])=>{te=[],console.log(e);const o=e,s=o?.getRootNode?.(),i=s?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,c=i?s:o?.ownerDocument||t,u=o.tagName,{attributes:f}=o,m=l.length>0?l:Array.from(f);if(ke(m,o,c,n,a),r.length){const e=r.flatMap(e=>ge(o,c,a,e));return te=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(e.filter(e=>1===g(e.value,o,c))),te}if(te.length){const t=te.length;for(let n=0;n<t;n++){let t=te[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===g(t,e,c)&&te.push({key:`${te[n].key} regex`,value:t})}}return te.length||i||(te=de(o,c,a,n)),te},Re={parseDOM:Ce,getTextXPath:Se,getUniqueClassName:we,attributesBasedXPath:Ee,addAllXPathAttributes:ke,addRelativeXpaths:(e,t,n,a,l)=>{try{let r,o,s=[];if(te=[],console.log(l),l)for(const t of l){let n=A(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=A(e,{name:"text",value:e.textContent},a);console.log(t),t&&s.push(t)}if(s.push(e.tagName),s?.length)for(let l=0;l<s.length;l++)if(!te.length){if(Ne(e,t,a,s[l]),!te.length&&(r||(r=ye(e.parentElement,t,e,a)),console.log(r),r&&(r.includes("@")||r.includes("text()")||r.includes(".="))&&r.match(/\//g)?.length-2<5)){const a=r+`/${s[l]}`,o=g(a,e,t);if(1===o)te.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=y(a,e,t,o);l&&1===g(l,e,t)&&te.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!te.length&&(o||(o=ve(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=g(a,e,t);if(1===r)te.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=y(a,e,t,r);l&&1===g(l,e,t)&&te.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===te?.length&&te?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=Se(e,t,n,!1);a&&te.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!te.length){let r=$e(e.parentElement,t,e,a,s[l],n);r&&te.push({key:"xpath by unique parent",value:r})}}return te}catch(e){console.log(e)}},getXPathUsingAttributeAndText:be,getSiblingRelativeXPath:Ne,getChildRelativeXpath:ve,getParentRelativeXpath:ye,getUniqueParentXpath:$e,checkRelativeXpathRelation:pe,buildAxesStrategyXpaths:de};let Oe=[],Te=[];const Ae=/^[\S]+( [\S]+)*$/gi,De=(e,t,n,a,l,r,o,s=0,i=!1)=>{let c="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)c.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const f=je(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,l,i);if(f)return f}else{c=`//${o+(s?"]".repeat(s):"")}/${n}::${F(t,e[e.length-1])}`;let r=g(c,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:S(c)}];if(r>1&&l&&(c=y(c,e[e.length-1],a,r),c&&(r=g(c,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:S(c)}]}},Pe=(e,t,n,a,l,r=!1,o=!1)=>{const s=e[e.length-2],i=e[e.length-1],u=x(i)??i.ownerDocument,f=n.find(e=>e?.key?.includes("absolute"))?.value||C(s,s.ownerDocument),m=[],d=[];f.split("/").map(e=>m.push(e)),m.map(e=>d.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||C(i,i.ownerDocument),$=[],y=[];g.split("/").map(e=>$.push(e)),$.map(e=>y.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var v=0;v<m.length&&m[v]==$[v];v++);const N=[];for(let e=v-1;e<m.length;e++)m[e]&&N.push(d[e]);const b=[];for(let e="descendant"===l?v:v-1;e<$.length;e++)$[e]&&(b.length?b.push(y[e]):b.push(y[e].replace(/\[([0-9]+)\]/gm,"")));let S;if(Te=a,e[e.length-2].textContent){S=Ae.test(e[e.length-2].textContent)?w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${p(h(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${p(h(e[e.length-2]))}]`:w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${U(e[e.length-2])})]`:`${e[e.length-2].tagName}[${U(e[e.length-2])}]`,N[N.length-1]=S;const n=N.join("["),a=N.length-1,s=n;for(let n=0;n<Te.length;n++){let i;if(i=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,i)return De(e,i,l,u||t,r,b,s,a,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(E(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=c(n.name,a);const s=n.name;S=w(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${p(a)}]`:`${e[e.length-2].tagName}[@${s}=${p(a)}]`,N[N.length-1]=S;const i=N.join("["),f=N.length-1,m=i;for(let n=0;n<Te.length;n++){let a;return a=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,De(e,a,l,u||t,r,b,m,f,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(E(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=c(n.name,a);const s=O(n,e[e.length-2]);if(s){S=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,N[N.length-1]=S;const n=N.join("["),a=N.length-1,i=n;for(let n=0;n<Te.length;n++){let s;return s=Te[n].value.startsWith("//")?Te[n].value.substring(Te[n].value.indexOf("//")+2):Te[n].value,De(e,s,l,u||t,r,b,i,a,o)}}}}}const k=N.join("["),R=N.length-1,T=je(`${k+(R?"]".repeat(R):"")}`,b,e[e.length-1],e,t,l,r,o);if(T)return T},Xe=(e,t,n,a,l,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const c=[];try{if(s=a.filter(e=>!e?.key?.includes("absolute")),i=l.filter(e=>!e?.key?.includes("absolute")),"ancestor"===n||"ancestor-or-self"===n){const a=Me(e,t,n,s,i,r);if(a.length)return a}for(let e=0;e<s.length;e++)for(let a=0;a<i.length;a++){let l=`//${0!==s[e].value.indexOf("//")?F(s[e].value):F(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[a].value.indexOf("//")?F(i[a].value):F(i[a].value.substring(i[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=g(l,t,t.ownerDocument);if(o>1)if(r){if(l=y(l,t,t.ownerDocument,o),l)return c.push({key:`dynamic ${n}${r?" index":""}`,value:S(l)}),c}else o>1&&(Oe.length?o<Oe[0].count&&(Oe.pop(),Oe.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):Oe.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return c.push({key:`dynamic ${n}`,value:S(l)}),c}if(!c.length)for(let a=0;a<s.length;a++)for(let l=0;l<i.length;l++){const u=`${0!==i[l].value.indexOf("//")?i[l].value:i[l].value.substring(i[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(u.length>1){const l=je(`${0!==s[a].value.indexOf("//")?F(s[a].value):F(s[a].value.substring(s[a].value.indexOf("//")+2))}`,u,t,[e,t],t.ownerDocument,n,r,o);if(console.log("getXpathRelationExpression traverseXpath",l),l)return c.push(...l),c}}}catch(e){console.log(e)}return c},_e=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,Le=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,Ie=(e,t)=>{for(const e of t){const t=Le(e.value);if(t&&1===t.split(_e).length)return F(t)}if(e.textContent){const t=U(e);if(t)return w(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`}if(e.attributes)for(const t of Array.from(e.attributes))if(E(t,e,!1)&&t.nodeValue)return w(e)?`*[local-name()='${e.tagName}' and @${t.name}=${p(c(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${p(c(t.name,t.nodeValue))}]`;return w(e)?`*[local-name()='${e.tagName}']`:e.tagName},Me=(e,t,n,a,l,r)=>{const o=[],s=((e,t)=>{let n=e;for(;n;){if(n.contains(t))return n;n=n.parentElement}return null})(e,t);if(!s||s===t)return o;const i=w(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let l=t;for(;l&&l!==e;){const e=l===t?Ie(t,n):w(l)?`*[local-name()='${l.tagName}']`:l.tagName;a.unshift(e),l=l.parentElement}return l===e?a.join("/"):""})(s,t,l);if(!c)return o;for(const e of a){const a=Le(e.value);if(!a)continue;let l=`//${F(a)}/${n}::${i}/${c}`,s=g(l,t,t.ownerDocument);if(1===s)return o.push({key:`dynamic ${n} bridge`,value:S(l)}),o;if(s>1&&r&&(l=y(l,t,t.ownerDocument,s),s=l?g(l,t,t.ownerDocument):0,l&&1===s))return o.push({key:`dynamic ${n} bridge index`,value:S(l)}),o}return o},je=(e,t,n,a,l,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${F(s)}`;const c=g(i,n,l);if(1===c)return[{key:`dynamic ${r}`,value:S(i)}];if(c>1&&o&&(i=y(i,a[a.length-1],l,c),i))return[{key:`dynamic ${r}${o?" index":""}`,value:S(i)}]}else for(let s=1;s<=t.length;s++){const c=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${F(c)}`;const u=g(i,n,l);if(1===u)return[{key:`dynamic ${r}`,value:S(i)}];if(u>1&&o&&(i=y(i,a[a.length-1],l,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:S(i)}]}},Ye={findRelativeXpath:(e,t,n,a,l,r,o=!1,s=null)=>{let i=[];const c=s||[],u=(r,s)=>{let c=[];c="descendant"===r||"descendant-or-self"===r?Pe([e,t],n,a,l,r,s,o)||[]:Xe(e,t,r,a,l,s,o)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,r);return i},getDescendantXpath:Pe,getAncestorBridgeXpath:Me,getXpathRelationExpression:Xe,getTraverseXpathExpression:je,getReferenceElementXpath:e=>{let t=[];if(t=Ce(e,e.ownerDocument,!1,!1),t?.length){let n=Ce(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Ce(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value});if(t?.length||(t=[{key:"",value:R(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:R(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&J(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:$(e.value)}:{key:"",value:e.value})),t?.length){const n=B(e,e.ownerDocument,!1);n?.length&&(t=t.concat(n))}else t=B(e,e.ownerDocument,!1);const n=C(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t},getSmartRelations:(e,t)=>{const n=e.compareDocumentPosition(t),a=[],l=[],r=[];n&Node.DOCUMENT_POSITION_CONTAINS&&a.push("ancestor","ancestor-or-self","parent"),n&Node.DOCUMENT_POSITION_CONTAINED_BY&&a.push("child"),e.parentElement===t.parentElement&&a.push("following-sibling","preceding-sibling"),n&Node.DOCUMENT_POSITION_FOLLOWING&&l.push("following"),n&Node.DOCUMENT_POSITION_PRECEDING&&l.push("preceding"),r.push("descendant","descendant-or-self");const o=[...a,...l,...r];return[...new Set(o)]}};let ze=[];const Ve=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},qe=(e,t="single")=>{const n=[],a=e.getRootNode();try{const l=We(e);if(l&&Ve(l,e,a)&&(n.push({key:"cssSelector by id",value:l}),"single"===t))return n;const r=Be(e);r&&Ve(r,e,a)&&n.push({key:"cssSelector by class",value:r});const o=Fe(e);o&&n.push({key:"cssSelector by name",value:o})}catch(e){console.error(e)}return n},We=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!f(e.id)){t+=`#${CSS.escape(e.id)}`,a.unshift(t);break}{let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}a.unshift(t),e=e.parentElement}return a.join(" > ")},Ue=new Set(["id","class","style"]);function He(e){return Array.from(e.attributes).filter(e=>!Ue.has(e?.name?.toLowerCase())&&e.value&&!f(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Fe=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.getRootNode(),a=e.tagName.toLowerCase();if("style"===a||"script"===a)return;const l=He(e);for(const t of l){const l=`${a}${t}`;if(Ve(l,e,n))return l}},Be=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||f(e.className)||ze?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,a.unshift(t);break}a.unshift(t),e=e.parentElement}return a.join(" > ")},Ge={parseCssSelectors:qe,getIdCssPath:We,getAttributeCssPath:Fe,getClassCssPath:Be,getAbsoluteCssPath:e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=[];for(;e&&e.nodeType===Node.ELEMENT_NODE;){const t=e.tagName.toLowerCase();if("style"===t||"script"===t)return;let a=t;const l=e.parentNode;if(l){const t=Array.from(l.children).filter(t=>t.tagName===e.tagName);t.length>1&&(a+=`:nth-of-type(${t.indexOf(e)+1})`)}n.unshift(a),e=e.parentElement}return n.join(" > ")}},Je=(e,t,n)=>{const a=G(e);if(ot(t,a)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(a)){const e=t.evaluate(a,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},Ze=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return et(e.body,t)},Ke=(e,t,n)=>Ze(t,e)===n,Qe=e=>e.name?.toLowerCase().includes("cssselector")??!1,et=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:a}=n[e];if(a){const e=et(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},tt=e=>e?.id||null,nt=e=>e.className||null,at=e=>e.textContent?.trim()||null,lt=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},rt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function ot(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function st(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),l=n.defaultView;if(!l)return null;if(!e.includes("dynamic")){const t=new l.XPathEvaluator;if(t.evaluate(a,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,l.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(a=e,a):(console.error("Complete Locator is Invalid:",e),a=e,a)}console.error("Source Locator Not Found:",a)}}return null}const it=(e,t)=>{const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const a=new Set;let l=[];function r(e,t={}){const n=e?.value,r=t.value??e?.value,o={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;o.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(o.name,n,r),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(o)}function o(e,t,n){if(Qe(t))return Ze(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+K(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=K(n);return e.querySelector(`[name="${t}"]`)}if("tagName"===t.name)return e.querySelector(n);if("linkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null;if("partialLinkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null;if(!t.name.includes("xpath")&&!n.startsWith("//")||t.type.match("dynamic"))return e.querySelector(n);{const a=ot(e,G(n));return a&&r(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),a}}function s(e,t,n){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const l=o(a,t,n);if(l)return l}catch{continue}return null}const i=(e,t,n)=>{if(!e)return null;let a=e.trim();return a&&"null"!==a.toLowerCase()?(a=a.replace(/\\"/g,'"').replace(/\\'/g,"'"),a=a.replace(/^['"](.+?)['"]$/,"$1"),a=a.replace(/''/g,"'"),a=a.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(a=a.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!a||/^['"]{2}$/.test(a)?null:a:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const c=e.locators.filter(e=>"N"===e.isRecorded);if(c.length>0)for(const e of c)r(e);const u=String(n.value||n.type||"");if(u.includes("dynamic")||u.match("dynamic")||u.includes("{")||u.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let c=null;const u=n.value.split(">>>");for(const e of u){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(c=o(t,n,a),c||(c=s(t,n,a)),c||(c=et(t.body,a)),!c){console.error("Element not found at:",a);break}}const m=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(c){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),a=e.locators.filter(e=>Qe(e)&&e.value);for(const e of n)Je(e.value,t,c)&&r(e,{isSelfHealed:null});for(const e of a)Ke(e.value,t,c)&&r(e,{isSelfHealed:null});const o=l.filter(e=>"xpath"===e.name&&e.value),s=new Set(o.map(e=>Z(e.value))),u=[],h=tt(c);if(h&&!m("id",h)&&!f(h)){const n=e.locators.find(e=>"id"===e.name);Q(t,"id",h,c)&&(u.push("id"),r(n,{name:"id",type:"static",isRecorded:"Y",value:h}))}const d=c.tagName;if(d&&!m("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);Q(t,"tagName",d,c)&&(u.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const g=at(c);if(g&&!f(g)){const n=e.locators.find(e=>"linkText"===e.name);Q(t,"linkText",g,c)&&(u.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:g}))}const p=lt(c);if(p&&!m("name",p)&&!f(p)){const n=e.locators.find(e=>"name"===e.name);Q(t,"name",p,c)&&(u.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=nt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!m("className",$)&&!f($)){const n=e.locators.find(e=>"className"===e.name);Q(t,"className",$,c)&&(u.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}qe(c,"single").forEach(e=>{e.value&&!m("cssSelector",e.value)&&r(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const y=Array.from(c.attributes).filter(e=>!u.includes(e.name));let v=[];try{v=Ce(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Je(e.value,t,c));let a=0;for(const t of e){if(a>=e.length)break;const n=Z(t.value);if(s.has(n))continue;const l=v.find(e=>e.value&&Z(e.value)===n);l?.value&&(r(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}if(a<e.length)for(const t of v){if(a>=e.length)break;if(!t.value)continue;const n=Z(t.value);s.has(n)||(r(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of rt)if(a.value.includes(e)){const l=st(a.value,e,t);if(l){r(a,{name:"xpath",value:l,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(l.length<5){const e=[{name:"id",value:tt(c)},{name:"name",value:lt(c)},{name:"className",value:nt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:at(c)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(f(a)||m(e,a)||"className"===e&&a.includes(" ")||Q(t,e,a,c)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&qe(c,"multiple").forEach(e=>{l.length>4||e.value&&(m("cssSelector",e.value)||Q(t,"cssSelector",e.value,c)&&r(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=l.map(e=>({...e,value:i(e.value,e.name,e.isRecorded)})),x=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:N.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return x}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};const ct={getOptimalClassChain:function e(t,n,a){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const l=n.tagName,r=["name","label","value"];for(const e of r){const r=a.find(t=>t.name===e);if(!r)continue;let o=r.value;if(!o)continue;if(o=o.trim().replace(/\s+/g," "),f(o))continue;const s=`//${l}[@${e}="${o}"]`;let i=0;try{i=g(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(o);if(1===i)return c?`/${l}[\`${e} CONTAINS "${o}"\`]`:`/${l}[\`${e} == "${o}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===l).indexOf(n)+1;return c?`/${l}[\`${e} CONTAINS "${o}"\`][${t}]`:`/${l}[\`${e} == "${o}"\`][${t}]`}}let o=`/${l}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===l);if(e.length>1){o+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,a)+o}catch(e){return console.log(`Unable to generate optimal -ios class chain : ${JSON.stringify(e)}`),null}},getOptimalPredicateString:function(e,t,n){try{if(!t?.tagName||1!==t?.nodeType||"XCUIElementTypeApplication"===t?.tagName)return"";let a=[],l=[];for(let r of n){const n=r.value,o=r.name;if(0!==n.length&&(n&&!f(n))){a.push(`@${o}="${n}"`);const r=`//*[${a.join(" and ")}]`;let s;l.push(`${o} == "${n}"`);try{s=g(r,t,e)}catch(e){console.log(e);continue}if(1===s)return l.join(" AND ")}}}catch(e){console.log(`The most optimal '-ios predicate string' could not be determined because an error was thrown: '${JSON.stringify(e,null,2)}'`)}return null}},ut=()=>({xpath:Re,referenceXpaths:Ye,xpathUtils:ee,getElementsFromHTML:it,cssSelectors:Ge,iosSelectors:ct});exports.createXPathAPI=ut,exports.default=ut;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const e=/^[\S]+( [\S]+)*$/i;let t=new WeakMap;const n=e=>{e?(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const a=e.getRootNode?.();return(a instanceof Document||a instanceof ShadowRoot)&&n(a),n(e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument),t})(e).forEach(e=>{t.delete(e)}):t=new WeakMap},a=(e,n)=>{const{owner:a,contextNode:r}=(e=>{const t=9===e.nodeType?e:e.ownerDocument||document;return{owner:t,contextNode:1===e.nodeType||9===e.nodeType||11===e.nodeType?e:t}})(n);let o=t.get(r);o||(o=new Map,t.set(r,o));const l=o.get(e);if(l)return l;const s=a.evaluate(e,r,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let r,o=new Map,l=[];const s=new Set(["marked-element-temp","removePointers"]),i=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!s.has(e)).sort(),c=e=>/\d/.test(e||""),u=(e,t,n,a=!1)=>{const r=i(t),o=r.filter(e=>!!a||!c(e));return o.length?1===r.length&&1===o.length?[`@class=${v(o[0])}`]:o.map(t=>{const a=h(`contains(@class,${v(t)})`,D(e),e.tagName.toLowerCase());return{token:t,count:U(a,e,n)}}).sort((e,t)=>e.token.length!==t.token.length?e.token.length-t.token.length:e.count-t.count).map(({token:e})=>`contains(@class,${v(e)})`):[]},f=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),m=(e,t)=>t?"class"===e||"className"===e?i(t).join(" "):t.replace("removePointers","").trim():"",d=e=>{if("attributes"!==e.type||"class"!==e.attributeName||!(e.target instanceof Element))return!1;if(D(e.target)&&e.oldValue?.trim()===e.target.classList.value?.trim())return!0;const t=i(e.oldValue),n=i(e.target.getAttribute("class"));return t.join(" ")===n.join(" ")},g=e=>/\d/.test(e),h=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,p=e=>{const t=e?.textContent;return t},$=e=>e?.childNodes[0]?.nodeValue||"",y=(e,t,n,r=!1)=>{try{if(C(n)){const{owner:a,contextNode:o,cloneElement:l,cloneElements:s}=R(n,t),i=a.evaluate(e,o,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),c=i.iterateNext(),u=i.iterateNext();if(!c)return 0;if(!u)return c===l?1:0;if(r&&Array.isArray(t)){let e,t=0;if(s.includes(c)&&t++,s.includes(u)&&t++,2===t)return 2;for(;e=i.iterateNext();)if(s.includes(e)&&(t++,2===t))return 2;return 0}return 2}const{first:o,second:l}=a(e,n);if(!o)return 0;if(!l)return o===t?1:0;if(r&&Array.isArray(t)){let a=0;if(t.includes(o)&&a++,t.includes(l)&&a++,2===a)return 2;const r=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=r.iterateNext();)if(t.includes(s)&&(a++,2===a))return 2;return 0}return 2}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},v=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},N=e=>{const t=e.split("");let n=t.length;const a=[];for(;"["!==t[n-2];)a.push(t[n-2]),n--;a.reverse();let r="";for(let e=0;e<a.length;e++)r+=a[e];const o=r.length+2;let l=e.slice(0,e.length-o);return l=l.startsWith("(")&&l.endsWith(")")?l.slice(1,-1):e,l},b=(e,t,n,a)=>{try{const r=9===n.nodeType?n:n.ownerDocument;let o=0;if(a){if(1===y(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===y(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const l=r.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=l.iterateNext();)if(o++,s.isSameNode(t))return 1===y(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===y(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},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(),E=e=>e?e.replace(/\s\s+/g," ").trim():e,w=(e,t)=>{const n=E((t||"").trim());if(!e.children.length||n.length<=50)return"";const a=n.split(/\s+/).slice(0,3).join(" ");return a.length>2?`contains(normalize-space(.),${v(a)})`:""},k=e=>{const t=E((e||"").trim());if(!t||!c(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),a=n.split(/[^a-zA-Z]+/).map(e=>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:a.length>2?a:""}},S=e=>k(e).fragment,A=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},C=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,R=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),a=n.createElement("div");a.innerHTML=e.innerHTML,n.body.appendChild(a);const r=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let a=t;for(;a&&a.parentElement;){const e=a.parentElement;n.unshift(Array.from(e.children).indexOf(a)),a=e}return a&&a.parentNode===e?(n.unshift(Array.from(e.children).indexOf(a)),n):null})(e,t);return n?((e,t)=>{let n=e;for(const e of t){const t=n.children.item(e);if(!t)return null;n=t}return n})(a,n):null},o=Array.isArray(t)?t.map(e=>r(e)).filter(Boolean):[],l=Array.isArray(t)?null:r(t??null);return{owner:n,contextNode:a,cloneElement:l,cloneElements:o}},O=(e,t,n)=>{const a=m(e.name,e.value);if(!a||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay"].some(e=>e===a))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const r=l?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!r&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(o=e.name,s=a,(!f.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(s))&&("class"===e.name||!c(a)))));var o,s},D=e=>e instanceof SVGElement,T=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,P=(t,n,a,r,o,l)=>{if(r){const{tagName:s}=t;let i,f="";const m=[];let d;const p=a.startsWith("@"),$="."===a||"text()"===a,N=$?".":a,b=$&&/\s/.test(r.trim()),x=$?S(r):r,k=$&&c(r)?x:r,A=$?w(t,k):"";if("@class"===a){for(const e of u(t,r,n))if(d=h(e,D(t),t.tagName.toLowerCase()),i=y(d,t,n),1===i&&!o)return d;return}if($&&c(r)&&!x)return;if(r&&(!p||!g(r))&&(d=A?h(A,D(t),t.tagName.toLowerCase()):b?h(`normalize-space(${N})=${v(E(k)).trim()}`,D(t),t.tagName.toLowerCase()):e.test(r)?`//${s}[${a}=${v(k)}]`:h(`normalize-space(${a})=${v(E(k)).trim()}`,D(t),t.tagName.toLowerCase()),i=y(d,t,n),1===i&&!o))return d;if(p&&c(r))return;if(r&&l){const l=r.split(" ");if(l?.length)if(1===l.length){const c=[...new Set(l[0].match(/([^0-9]+)/g))];if(c?.length>=1&&c[0]&&E(c[0].trim())?.length>1&&r.startsWith(c[0])&&(f=e.test(c[0])?`starts-with(${a},${v(c[0]).trim()})`:`starts-with(${a},${v(E(c[0])).trim()})`),c?.length>1&&c[c.length-1]&&E(c[c.length-1].trim())?.length>1&&r.endsWith(c[c.length-1])&&(f=e.test(c[c.length-1])?`ends-with(${a},${v(c[c.length-1]).trim()})`:`ends-with(${a},${v(E(c[c.length-1])).trim()})`),f?.length&&(d=D(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d}else{const c=l.length%2==0?l.length/2:l.length%2,u=l.slice(0,c).join(" ");let m=[...new Set(u.match(/([^0-9]+)/g))];if(m?.length&&m[0]&&E(m[0].trim())?.length&&r.startsWith(m[0])&&(f=e.test(m[0])?`starts-with(${a},${v(m[0]).trim()})`:`starts-with(${a},${v(E(m[0])).trim()})`),f?.length&&(d=D(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d;const g=l.slice(c,l.length-1).join(" ");if(m=[...new Set(g.match(/([^0-9]+)/g))],m?.length&&m[0]&&E(m[0].trim())?.length>3&&r.endsWith(m[0])&&(f=e.test(m[0])?`ends-with(${a},${v(m[0]).trim()})`:`ends-with(${a},${v(E(m[0])).trim()})`),f?.length&&(d=D(t)?`//*[local-name()='${s}' and ${f}]`:`//${s}[${f}]`,i=y(d,t,n),1===i&&!o))return d}}if(r&&l&&g(r)){const l=[...new Set(r.match(/([^0-9]+)/g))];if(l?.length)for(let t=0;t<l?.length;t++)l[t]&&E(l[t].trim())?.length>1&&(e.test(l[t])?m.push(`contains(${a},${v(l[t].trim()).trim()})`):m.push(`contains(${a},${v(E(l[t])).trim()})`));if(m?.length&&(d=D(t)?`//*[local-name()='${s}' and ${m.join(" and ")}]`:`//${s}[${m.join(" and ")}]`,i=y(d,t,n),1===i&&!o))return d}if(d=D(t)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=y(d,t,n),1===i&&!o)return d}},X=(e,t)=>{try{if(!e)return"";let n=D(e)?`/*[local-name()='${e.tagName}']`:`/${e.tagName}`;if(e.parentElement){const t=Array.prototype.slice.call(e.parentElement.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}else if(e instanceof HTMLElement&&e.offsetParent){const t=Array.prototype.slice.call(e.offsetParent.children,0).filter(t=>t.tagName===e.tagName);if(t.length>1){n+=`[${t.indexOf(e)+1}]`}}return X(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},_=(e,t,n,a=!1,r)=>{try{if(o.has(e))return o.get(e);const l=[];let s=e;for(;s;){let o="",i=!1,c=e===s?r??s.attributes:s.attributes;for(const e of Array.from(c))if(O(e,s)){const a=m(e.name,e.nodeValue),r=e.name;for(const e of ee(s,r,a)){o=e;let a=0;if(a=y(o,s,t),1===a){l.unshift(T(o)),i=!0;break}if(a>1&&n&&(o=b(o,s,t,a),o)){l.unshift(T(o)),i=!0;break}}}if(s.textContent)if(!a||a&&!g(s.textContent)){let e=new RegExp(/^[\S]+( [\S]+)*$/gi);const a=$(s),r=w(s,a);o=r?h(r,D(s),s.tagName||"*"):e.test(s.textContent)?D(s)?`//*[local-name()='${s.tagName}' and .=${v(a)}]`:`//${s.tagName||"*"}[.=${v(a)}]`:D(s)?`//*[local-name()='${s.tagName}' and normalize-space(.)=${v(a)}]`:`//${s.tagName||"*"}[normalize-space(.)=${v(a)}]`;let l=y(o,s,t);if(1===l)return o;if(l>1&&n)return o=b(o,s,t,l),o}else{let e=[];const a=[...new Set($(s).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&E(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${v(a[t].trim()).trim()})`):e.push(`contains(.,${v(E(a[t])).trim()})`));if(e?.length){o=D(s)?`//*[local-name()='${s.tagName}' and ${e.join(" and ")}]`:`//${s.tagName||"*"}[${e.join(" and ")}]`;let a=y(o,s,t);if(1===a)return o;if(a>1&&n)return o=b(o,s,t,a),o}}if(i)break;{let e=D(s)?`/*[local-name()='${s.tagName}']`:`/${s.tagName}`;if(s.parentElement){const t=Array.from(s.parentElement.children).filter(e=>e.tagName===s.tagName);if(t.length>1){e+=`[${t.indexOf(s)+1}]`}}l.unshift(e)}s=s.parentElement}const i=`${l.join("")}`;return o.set(e,i),i}catch(e){return console.log(e),null}},L=(t,n)=>{const a=[];let r="";if(t&&"function"!=typeof t.nodeValue){if("class"===t.name){const e=n.getRootNode?.()??n.ownerDocument,a=u(n,t.value,e);for(const e of a)if(r=D(n)?`//*[local-name()='${n.tagName}' and ${e}]`:`//${n.tagName}[${e}]`,r)return r;return}if(g(t.value))return;const o=[...new Set(t.value.match(/([^0-9]+)/g))];if(o?.length)for(let n=0;n<o?.length;n++)o[n]&&E(o[n].trim())?.length>2&&(e.test(o[n])?a.push(`contains(@${t.name},${v(o[n].trim())})`):a.push(`contains(@${t.name},${v(E(o[n])).trim()})`));if(a?.length)return r=D(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,r}},I=(t,n,a,r)=>{try{const r=a.filter(e=>O(e,t)),o=a=>{const r=m(a.name,a.nodeValue);return r?"class"===a.name?u(t,r,n):c(r)?[]:e.test(r)?[`@${a.name}="${r}"`]:[`normalize-space(@${a.name})="${r}"`]:[]},l=e=>{const t=o(e);return"class"===e.name?t.map(e=>[e]):t.length?[t]:[]},s=e=>e.reduce((e,t)=>{const n=l(t);return n.length?e.flatMap(e=>n.map(t=>[...e,...t])):[]},[[]]),i=()=>{const n=E(p(t)?.trim()||""),a=S(n);if(c(n))return a?[`contains(normalize-space(.),${v(a)})`]:[];if(!n||n.length>80||/^\d+$/.test(n)){const e=w(t,n);return e?[e]:[]}const r=new Set,o=w(t,n);return o?(r.add(o),Array.from(r)):(e.test(n)&&n.length<=40&&!n.includes(" ")&&r.add(`text()=${v(n)}`),n.includes(" ")&&r.add(`normalize-space(.)=${v(E(n))}`),r.add(`contains(text(),${v(n)})`),Array.from(r))},f=(e,t)=>{const n=[],a=(r,o)=>{if(o.length!==t)for(let t=r;t<e.length;t++)o.push(e[t]),a(t+1,o),o.pop();else n.push([...o])};return a(0,[]),n},d=e=>D(t)?`//*[local-name()='${t.tagName}' and ${e.join(" and ")}]`:`//${t.tagName}[${e.join(" and ")}]`,g=()=>{if(!(r.length<2))for(let e=2;e<=r.length;e++){const a=f(r,e);for(const e of a){const a=s(e);for(const e of a){if(e.length<2)continue;const a=d(e);let r;try{r=y(a,t,n)}catch{continue}if(1===r)return a}}}},h=g();if(h)return h;const $=i();if(!$.length||!r.length)return;for(let e=1;e<=r.length;e++){const a=f(r,e);for(const e of a){const a=s(e);for(const e of a)if(e.length)for(const a of $){const r=[...e,a],o=d(r);try{if(1===y(o,t,n))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},z=(e,t,n)=>M(e,t)[0]||"",M=(t,n,a)=>{let r=D(t),o="";if(O(n,t)){let a=m(n.name,n.value);const l=n.name;if("class"===l){const e=t.getRootNode?.()??t.ownerDocument;return u(t,a,e).map(e=>r?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName||"*"}[${e}]`)}if(c(a))return[];o=e.test(a)?r?`*[local-name()='${t.tagName}' and @${l}=${v(a)}]`:`${t.tagName||"*"}[@${l}=${v(a)}]`:r?`*[local-name()='${t.tagName}' and normalize-space(@${l})=${v(a)}]`:`${t.tagName||"*"}[normalize-space(@${l})=${v(a)}]`}return o?[o]:[]},j=(t,n)=>{if(!t.textContent)return"";const a=$(t),r=S(a);if(c(a)&&!r)return"";const o=c(a)?r:a,l=w(t,o);let s;return s=l?h(l,D(t),t.tagName||"*"):c(a)?h(`contains(normalize-space(.),${v(o)})`,D(t),t.tagName||"*"):!e.test(a)||/\s/.test(a.trim())?h(`normalize-space(.)=${v(o)}`,D(t),t.tagName||"*"):D(t)?`//*[local-name()='${t.tagName}' and .=${v(o)}]`:`//${t.tagName||"*"}[.=${v(o)}]`,s},Y=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{fragment:t}=k(n);return t?h(`contains(normalize-space(.),${v(t)})`,D(e),e.tagName.toLowerCase()):""}return h(`normalize-space(${t})=${v(E(n)).trim()}`,D(e),e.tagName.toLowerCase())},V=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{prefix:t,fragment:a}=k(n),r=t||a;return r?h(`starts-with(normalize-space(.),${v(r)})`,D(e),e.tagName.toLowerCase()):""}return h(`starts-with(${t},${v(E(n)).trim()})`,D(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if(("."===t||"text()"===t)&&c(n)){const{fragment:t}=k(n);return t?h(`contains(normalize-space(.),${v(t)})`,D(e),e.tagName.toLowerCase()):""}return h(`contains(${t},${v(E(n)).trim()})`,D(e),e.tagName.toLowerCase())},W=(t,n)=>{const a=n.flatMap(n=>(n=>{const a=m(n.name,n.value);if(!a)return[];if("class"===n.name){const e=t.getRootNode?.()??t.ownerDocument;return u(t,a,e)}return c(a)?[]:e.test(a)?[`@${n.name}=${v(a)}`]:[`normalize-space(@${n.name})=${v(a)}`]})(n)).filter(Boolean);if(a.length>=2)return h(`${a[0]} or ${a[1]}`,D(t),t.tagName.toLowerCase());const r=(()=>{const n=E(p(t)?.trim()||""),a=S(n);if(c(n))return a?`contains(normalize-space(.),${v(a)})`:null;const r=w(t,n);return r||(!n||n.length>80||/^\d+$/.test(n)?null:e.test(n)&&n.length<=40&&!n.includes(" ")?`text()=${v(n)}`:n.includes(" ")?`normalize-space(.)=${v(n)}`:`contains(text(),${v(n)})`)})();return 1===a.length&&r?h(`${a[0]} or ${r}`,D(t),t.tagName.toLowerCase()):""},U=(e,t,n)=>{try{return y(e,t,n)}catch(e){return 0}},F=(e,t)=>{const n=[],a=new Set,r=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","aria-label","role"],l=[...o.map(e=>r.find(t=>t.name===e)).filter(Boolean),...r.filter(e=>!o.includes(e.name))],s=r=>{r&&!a.has(r)&&Z(r,e,t)&&(a.add(r),n.push(r))};l.forEach(t=>{if(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=D(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const r=F(t,n);for(const o of r){console.log(`Trying ancestor XPath: ${o}`);const r=`${o}/descendant::${a}`;console.log(`Trying descendant XPath: ${r}`);const l=U(r,e,n);if(console.log(`Match count: ${l}`),1===l&&B(r,n)===e)return console.log(`Selected XPath: ${r}`),r;const s=H(t,e);if(s){const t=`${o}/${s}`;console.log(`Trying descendant XPath: ${t}`);const a=U(t,e,n);if(console.log(`Match count: ${a}`),1===a&&B(t,n)===e)return console.log(`Selected XPath: ${t}`),t}}}console.log(`Trying descendant XPath: ${r}`);const o=U(r,e,n);return console.log(`Match count: ${o}`),1===o&&B(r,n)===e?(console.log(`Selected XPath: ${r}`),r):(console.log("Selected XPath: "),"")},B=(e,t)=>{try{if(C(t)){const{owner:n,contextNode:a,cloneElement:r}=R(t);return n.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||r}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},Z=(e,t,n)=>{try{const{first:r,second:o}=a(e,n);return!!r&&!o&&r===t}catch{return!1}},J=e=>D(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=p(e)?.trim(),n=S(t);if(t&&c(t))return n?`contains(normalize-space(.),${v(n)})`:void 0;const a=w(e,t);if(a)return a;const r=t?v(x(t)):t;return r?r!==`'${t}'`?`contains(.,${r})`:/\s/.test(t)?`normalize-space(.)='${E(t)}'`:`normalize-space(.)='${t}'`:void 0},ee=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let r="";if(n=m(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return u(e,n,t).map(t=>D(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(c(n))return[];r=a.test(n)?D(e)?`//*[local-name()='${e.tagName}' and @${t}=${v(n)}]`:`//${e.tagName||"*"}[@${t}=${v(n)}]`:D(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${v(n)})]`:`//${e.tagName||"*"}[contains(@${t},${v(n)})]`}return r?[r]:[]},te=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,ne=(t,n,a)=>{let r;const o=[];if(t.textContent&&a&&g(t.textContent)){const{prefix:e,fragment:n}=k(p(t)),a=[e?`starts-with(normalize-space(.),${v(e)})`:"",n?`contains(normalize-space(.),${v(n)})`:""].filter((e,t,n)=>e&&n.indexOf(e)===t);for(const e of a)r=D(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r})}if(t.textContent&&(!a||a&&!g(t.textContent)))if(e.test(t.textContent)){const e=p(t),n=w(t,e),a=n||(/\s/.test(e.trim())?`normalize-space(.)=${v(E(e))}`:`.=${v(e)}`);r=D(t)?`*[local-name()='${t.tagName}' and ${a}]`:`${t.tagName}[${a}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}else{const e=Q(t);e&&(r=D(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r}))}if(t.attributes){const e="IMG"===t.tagName?Array.from(t.attributes).sort((e,t)=>"alt"===e.name?-1:"alt"===t.name?1:0):Array.from(t.attributes);for(const a of e)if(O(a,t)){let e=a.nodeValue;if(e){e=m(a.name,e);const l=a.name;if("class"!==l&&c(e))continue;if("class"===l){const a=u(t,e,n);if(!a.length)continue;for(const e of a)r=D(t)?`*[local-name()='${t.tagName}' and ${e}]`:`${t.tagName}[${e}]`,o.push({key:"getReferenceElementsXpath",value:r});continue}r=D(t)?`*[local-name()='${t.tagName}' and @${l}=${v(e)}]`:`${t.tagName}[@${l}=${v(e)}]`,r&&o.push({key:"getReferenceElementsXpath",value:r})}}}if(!o?.length){const e=Array.prototype.slice.call(t.attributes);if(e?.length>1){const e=I(t,n,Array.prototype.slice.call(t.attributes));e&&o.push({key:"getReferenceElementsXpath",value:e})}}if(!o?.length){const e=[];let n;const r=t.tagName;if(t.textContent&&a&&g(t.textContent)){const a=E(p(t)).trim();a?.length>1&&e.push(`contains(text(),${v(a)})`),e?.length&&(n=D(t)?`*[local-name()='${r}' and ${e.join(" and ")}]`:`${r}[${e.join(" and ")}]`,n&&o.push({key:"getReferenceElementsXpath",value:n}))}}if(!o?.length){const e=((e,t)=>{const n=Array.prototype.slice.call(e),a=[];try{n.map(e=>{if(O(e,t)){const n=L(e,t);n&&a.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return a})(t.attributes,t);e?.length&&o.concat(e)}return o},ae=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1"),re=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function oe(e){const t=function(e){return e.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e),n=function(e){const t=e.toLowerCase(),n=t.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=n?.[1]??"none",r=t.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:r?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function le(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function se(e,t,n,a){const r=a?.getRootNode?.()??e,o=e=>{try{return Array.from(r.querySelectorAll(e))}catch{return[]}};try{switch(t){case"id":return 1===o(`#${le(n)}`).length;case"name":return 1===o(`[name="${le(n)}"]`).length;case"className":return 1===o(`.${n}`).length;case"tagName":case"cssSelector":return 1===o(n).length;case"linkText":return 1===o("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===o("a").filter(e=>e.textContent?.includes(n)).length;default:return!1}}catch{return!1}}const ie={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:ne,getAbsoluteXPath:X,getRelativeXPath:_,getCombinationXpath:L,getAttributeCombinationXpath:I,getElementFromXpath:(e,t,n=!1)=>{let a=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(a=t.host??t);const r=a.nodeType===Node.DOCUMENT_NODE?a:a.ownerDocument;return n?r.evaluate(e,a,null,XPathResult.ANY_TYPE,null):r.evaluate(e,a,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},isSvg:D,findXpathWithIndex:b,isNumberExist:g,getTextContent:p,getCountOfXPath:y,normalizeXPath:ae,getShadowRoot:A,escapeCharacters:v,removeParenthesis:N,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:x,replaceTempAttributes:T,createObserver:e=>{r=new MutationObserver(t=>{t.forEach(t=>{("childList"===t.type||"characterData"===t.type||"attributes"===t.type&&"flndisabled"!==t.attributeName&&!d(t))&&n(t.target),t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&(d(t)||"attributes"!==t?.type||["flndisabled"].includes(t.attributeName)||l.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{r?.observe(e,t)},stopObserver:()=>{r?.disconnect()},modifiedElementAttributes:l,cspEnabled:!1,getXPathPattern:oe,getNormalizedPropertyXPath:Y,getStartsWithPropertyXPath:V,getContainsPropertyXPath:q,getOrAttributesXPath:W,getTagOnlyXPath:G,getFirstMatchedNode:B,isExactUniqueXpath:Z,getAxisNodeTest:J,getUniqueNodeAnchorXpaths:K,escapeAttrValue:le,isUniqueInDOM:se,sanitizeAttributeValue:m,getClassTokenCondition:(e,t,n,a=!1)=>u(e,t,n,a)[0]||null,getClassTokenConditions:u,getXpathStrings:ee,intermediateXpathSteps:M,getContainerTextCondition:w};let ce=[],ue=[],fe=new Map,me=new Map;const de=new Map,ge={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},he=e=>ge[e]||e,pe=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),$e=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const a=e[n];if(t){a===t&&(t=null);continue}if("'"===a||'"'===a){t=a;continue}if("["!==a)continue;const r=e.indexOf("]",n+1);if(-1===r)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,r)))return!0}return!1})(e.value)),ye=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ve=e=>{if(!(e&&e instanceof Element))return[];const t=[],n=Array.from(e.children||[]);for(;n.length;){const e=n.shift();e.classList?.contains("flntooltip")||(t.push(e),n.push(...Array.from(e.children||[])))}return t},Ne=(e,t)=>{const n=[];let a="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;a;)a.classList?.contains("flntooltip")||n.push(a),a="previous"===t?a.previousElementSibling:a.nextElementSibling;return n},be=(e,t)=>{const n=[];for(let a=e;a?.parentElement;a=a.parentElement){let e="previous"===t?a.previousElementSibling:a.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>ve(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},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},Ee=e=>{let t=0;e.id&&(t+=100),e.getAttribute("data-testid")&&(t+=90),e.className&&(t+=50),0===e.children.length&&(t+=30);const n=e.textContent?.trim();return n&&n.length<40&&(t+=40),t},we=(e,t,n,a,r,o,l)=>{const s=J(n),i=[];let c=0;const u=t.includes("descendant")?10:20;for(const r of e){if(c++>u)break;if(i.length>=5)break;const e="node"in r?r.node:r;if(!(e instanceof Element))continue;if(xe(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=y(r.value,e,a);for(let e=1;e<=Math.min(l,3);e++){const l=`(${r.value})[${e}]/${t}::${s}`;if(Z(l,n,a)){if(i.push({key:o,value:l}),i.length>=2)return i;if(i.length>=5)return i}}}}if("expand"in r&&r.expand){const e=r.expand();let l=0;for(const r of e){if(l++>15)break;if(i.length>=5)break;if(!(r instanceof Element))continue;if(xe(r))continue;const e=K(r,a);for(const r of e.slice(0,5)){const e=`${r.value}/${t}::${s}`;if(Z(e,n,a)){if(i.push({key:o,value:e}),i.length>=2)return i;if(i.length>=5)return i}}}}}return i},ke=(e,t)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},Se=(e,t)=>{for(let n=e.nextElementSibling;n;n=n.nextElementSibling)if(n===t)return"following-sibling";for(let n=e.previousElementSibling;n;n=n.previousElementSibling)if(n===t)return"preceding-sibling";return""},Ae=(e,t)=>{const n=[];for(let a=e;a&&a!==t;a=a.parentElement){const e=a.parentElement;if(!e)return"";n.push(`/parent::${J(e)}`)}return n.join("")},Ce=(e,t)=>{const n=J(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Re=(e,t,n)=>{const a=[],r=new Set,o=(e=>{const t=[],n=new Set,a=a=>{a&&a!==e&&!n.has(a)&&(a.contains(e)||e.contains(a)||(n.add(a),t.push(a)))};for(let n=e.parentElement,r=0;n&&r<4&&t.length<20;n=n.parentElement,r++){const e=[Ne(n,"previous").slice(0,4),Ne(n,"next").slice(0,4)];for(const t of e)for(const e of t){a(e);let t=0;for(const n of ve(e).sort((e,t)=>Ee(t)-Ee(e))){if(t++>=8)break;a(n)}}}return t.sort((e,t)=>Ee(t)-Ee(e)).slice(0,20)})(e),l=ke(e.parentElement,3);for(const n of o){const o=K(n,t).filter(e=>"anchor by tag"!==e.key).slice(0,2);if(!o.length)continue;const s=ke(n,3);for(const i of o)for(const o of s){const s=Ae(n,o);if(o===n||s)for(const n of l){if(!n||!n.contains(e))continue;const l=Se(o,n);if(!l)continue;const c=`/${l}::${J(n)}`;for(const o of Ce(n,e)){const n=`${i.value}${s}${c}${o}`;if(!r.has(n)&&(r.add(n),Z(n,e,t)&&(a.push({key:"chained axes fallback",value:n}),a.length>=2)))return a}}}}return a},Oe=(e,t)=>{const n=[];for(let a=t;a&&a!==e;a=a.parentElement)n.unshift(J(a));if(!n.length)return"";const a=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${a}`},De=(e,t,n,a)=>{const r=new Set,o=[],l=(e,t)=>{t&&!r.has(t)&&(!a&&/\[\d+\]/.test(t)||(r.add(t),o.push({key:e,value:t})))};return K(e,t).filter(e=>"anchor by tag"!==e.key).forEach(e=>l(e.key,e.value)),Array.from(e.attributes||[]).forEach(t=>{if(!(e=>!(!e?.value||["style","locator-data-tooltip","value"].includes(e.name)||0===e.name.indexOf("on")&&e.name.length>3))(t)||!c(t.value)||"class"===t.name)return;const n=(e=>{const t=(e.split(/\d/)[0]||"").replace(/[-_:\s.]+$/g,"").trim();return t.length>2&&/[a-zA-Z]/.test(t)?t:""})(t.value);if(!n)return;const a=q(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,a)}),o},Te=(e,t,n,a)=>{const r=[];for(let t=e.parentElement;t;t=t.parentElement)r.push(t);const o=ve(e),l=Ne(e,"previous"),s=Ne(e,"next"),i=be(e,"previous"),c=be(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(s),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(l),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(r),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(r),axis:"descendant",key:"descendant"},{nodes:u(r),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(o,10),axis:"ancestor",key:"ancestor"},{nodes:u(o,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]],m=((e,t,n,a)=>{const r=[],o=new Set;for(let n=e.parentElement,l=0;n&&l<8;n=n.parentElement,l++){const l=Oe(n,e);if(!l)continue;const s=De(n,t,0,a);for(const n of s.slice(0,3)){const a=`${n.value}${l}`;if(!o.has(a)&&(o.add(a),Z(a,e,t)&&(r.push({key:"child chain",value:a}),r.length>=2)))return r}}return r})(e,t,0,a);if(m.length)return m;for(const n of f)for(const r of n){const n=we(r.nodes,r.axis,e,t,0,r.key,a);if(n.length>0)return n}return Re(e,t)||[]},Pe=(e,t,n,a,r)=>{const o=he(a);return"text"===o?pe(a,((e,t,n)=>{if(!ye(e))return[];if("text"===n){const n=j(e)||qe(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?pe(a,((e,t,n)=>{const a=[],r=Array.from(e.attributes||[]).filter(t=>t?.value&&O(t,e)),o=ye(e),l="contains"===n?q:"startsWith"===n?V:"normalizeSpace"===n?Y:null;if(!l)return a;if(r.forEach(t=>{const r=l(e,`@${t.name}`,t.value);r&&a.push({key:`xpath by ${n} ${t.name}`,value:r})}),o){const t=l(e,".",o);t&&a.push({key:`xpath by ${n} text`,value:t})}return a})(e,0,o)):["and","or"].includes(o)?pe(a,((e,t,n,a)=>{const r=Array.from(e.attributes||[]).filter(t=>t?.value&&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?pe(a,Te(e,t,0,!1)):"index"===o?pe(a,((e,t)=>{const n=[],a=e.tagName.toLowerCase(),r=Array.from(t.querySelectorAll(a)).indexOf(e)+1;if(r<=0)return[];n.push({key:"xpath by index",value:`(//${a})[${r}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?ee(o,"id",o.id):ee(o,"class",o.className.toString());for(const r of t){const t=Array.from(o.querySelectorAll(a)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${r}//${a})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?pe(a,[{key:"xpath till tag",value:G(e,t)}]):[]},Xe=(e,t,n,a,r,o)=>{if(e){let l;l="parent"===o?[`${e}/descendant-or-self::${t}`,`${e}/following::${t}`]:[`${e}/ancestor-or-self::${t}`,`${e}/preceding::${t}`];for(const e of l){fe?.get(e)||fe.set(e,y(e,n,a));const t=fe?.get(e);if(1===t)return e;if(t>1&&(ue.length?t<ue[0].count&&(ue.pop(),ue.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})):ue.push({key:"relative xpath by unique parent "+(r?"index":""),value:e,count:t})),t>1&&r&&!ce.length){const o=b(e,n,a,t);o&&1===y(o,n,a)&&ce.push({key:"relative xpath by unique parent "+(r?"index":""),value:o})}}}return null},_e=(t,n,a,r,o,l)=>{try{if(de.has(t))return de.get(t);const s=[];let i=t;for(;i&&1===i.nodeType;){const t=!1;for(const e of Array.from(i.attributes))if(O(e,i)){const t=m(e.name,e.nodeValue),r=e.name;for(const e of ee(i,r,t)){let t;try{t=Xe(e,o,a,n,l,"parent")}catch(e){continue}if(t)return t}}if(i.textContent&&!i.textContent)if(!r||r&&!g(i.textContent)){let t;t=e.test(i.textContent)?D(i)?`//*[local-name()='${i.tagName}' and .=${v($(i))}]`:`//${i.tagName||"*"}[.=${v($(i))}]`:D(i)?`//*[local-name()='${i.tagName}' and normalize-space(.)=${v($(i))}]`:`//${i.tagName||"*"}[normalize-space(.)=${v($(i))}]`;const r=Xe(t,o,a,n,l,"parent");if(r)return r}else{const e=[],t=[...new Set($(i).match(/([^0-9]+)/g))],r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&E(t[n].trim())&&(r.test(t[n])?e.push(`contains(.,${v(t[n].trim()).trim()})`):e.push(`contains(.,${v(E(t[n])).trim()})`));if(e?.length){const t=D(i)?`//*[local-name()='${i.tagName}' and ${e.join(" and ")}]`:`//${i.tagName||"*"}[${e.join(" and ")}]`,r=Xe(t,o,a,n,l,"parent");if(r)return r}}if(!t){const e=D(i)?`/*[local-name()='${i.tagName}']`:`/${i.tagName}`;s.unshift(e)}i=i.parentElement}const c=s.join("")+o;if(1===y(c,t,n))return de.set(t,c),c}catch(e){return console.error(e),null}},Le=(e,t,n,a)=>{const r=new Map;if(r.has(e))return r.get(e);const o=[];let l=e;try{for(;l&&1===l.nodeType;){if(!l.tagName)return"";let e=!1;for(const n of Array.from(l.attributes)){if(O(n,l)){const a=m(n.name,n.nodeValue),r=n.name;for(const n of ee(l,r,a)){let a;try{a=y(n,l,t)}catch(e){continue}if(1===a){o.unshift(n),e=!0;break}}}if(e)break}if(!e&&l.textContent&&!n.textContent){const n=j(l);if(n){if(1===y(n,l,t)){e=!0,o.unshift(n);break}}}if(e)break;{const e=D(l)?`/*[local-name()='${l.tagName}']`:`/${l.tagName}`;o.unshift(e)}l=l.parentElement}const a=o.join("");return r.set(e,a),a}catch(e){return console.log(e),null}},Ie=(e,t,n)=>{const a=[];let r;const o=[];null!=e.firstElementChild&&e.firstElementChild.classList.contains("flntooltip")?o.unshift(e.firstElementChild):null!=e.nextElementSibling&&o.unshift(e.nextElementSibling);for(let t=e.parentElement;null!=t&&1===t.nodeType;t=t.parentElement)t.nextElementSibling&&o.unshift(t.nextElementSibling);try{do{let e=!1;for(r=o.pop();null!==r;){for(const n of Array.from(r.attributes)){if(O(n,r)){const o=m(n.name,n.nodeValue),l=n.name;for(const n of ee(r,l,o)){let o;try{o=y(n,r,t)}catch(e){continue}if(1===o){e=!0,a.push(n);break}}}if(e)break}if(!e&&r.textContent&&!n.textContent){const n=j(r);if(n){if(1===y(n,r,t)){e=!0,a.push(n);break}}}if(e)break;{const e=D(r)?`/*[local-name()='${r.tagName}']`:`/${r.tagName}`;a.push(e),null!=r.firstElementChild?(o.push(r.nextElementSibling),r=r.firstElementChild):r=r.nextElementSibling}}}while(o.length>0);const l=a.join("");return me.set(e,l),l}catch(e){return console.log(e),null}},ze=(e,t,n,a)=>{try{const r=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==r;o=o.nextElementSibling)Me(o,e,t,a,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==r;o=o.previousElementSibling)Me(o,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},Me=(e,t,n,a,r,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){const l=M(e,{name:t.name,value:t.value},o);for(let t of l){t+=`/${r}::${a}`;const o=y(t,e,n);if(1===o)return void ce.push({key:`xpath by ${r}`,value:t});o>1&&(ue.length?o<ue[0].count&&(ue.pop(),ue.push({key:`relative xpath by ${r}`,value:t,count:o})):ue.push({key:`relative xpath by ${r}`,value:t,count:o}))}}if(!o){let t;if(t=z(e,{name:"text",value:e.textContent}),t){const a=y(t,e,n);if(1===a)return void ce.push({key:`xpath by ${r}`,value:t});a>1&&(ue.length?a<ue[0].count&&(ue.pop(),ue.push({key:`relative xpath by ${r}`,value:t,count:a})):ue.push({key:`relative xpath by ${r}`,value:t,count:a}))}}}catch(e){console.log(`${r} xpath-error`,e)}};function je(e,t,n,a){const{tagName:r}=t,o=t.textContent.trim();if(!o)return;const l=E(o),s=S(l);if(c(l)&&!s)return;const i=c(l)?s:l,u=w(t,i);for(const a of e)if(O(a,t)){let e=m(a.name,a.nodeValue);const s=`//${r}[@${a.name}='${e}' and ${u||(c(l)?`contains(normalize-space(.),${v(i)})`:/\s/.test(o)?`normalize-space(.)=${v(i)}`:`text()=${v(i)}`)}]`;if(s){if(1==y(s,t,n))return s}}}const Ye=(e,t,n,a,r)=>{let o;if(o=e.name,O(e,t))return P(t,n,`@${o}`,e.value,a,r)},Ve=(e,t,n,a)=>{let r=e.className;if("string"!=typeof r&&(r=""),r=r?.replace("flndisabled","disabled"),r=m("class",r),r=r?.trim(),r&&O({name:"class",value:r},e))return P(e,t,"@class",r,n,a)},qe=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const r=p(e);if(r)return P(e,t,".",r,n,a)}},We=(e,t,n,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&O(e,t)){const o=Ye(e,t,n,a,r);o&&ce.push({key:`xpath by ${e.name}${a?" index":""}`,value:o})}});const l=qe(t,n,a,r);if(l&&ce.push({key:"xpath by text"+(a?" index":""),value:l}),o.find(e=>"className"===e.name)&&O(o?.find(e=>"className"===e.name),t)){let e=Ve(t,n,a,r);e&&ce.push({key:"xpath by class",value:e})}if(!ce.length&&o.length>1){const e=I(t,n,o);e&&ce.push({key:"xpath by combination",value:e})}if(!ce.length){const a=je(e,t,n);a&&ce.push({key:"xpath by textAttribute",value:a})}}catch(e){console.log(e)}},Ue=(e,t,n,a,r=[],o=[])=>{ce=[],console.log(e);const l=e,s=l?.getRootNode?.(),i=s?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,c=i?s:l?.ownerDocument||t,u=l.tagName,{attributes:f}=l,m=r.length>0?r:Array.from(f);if(We(m,l,c,n,a),o.length){const e=n||((e=[])=>e.some(e=>"index"===he(e)))(o),t=o.flatMap(e=>Pe(l,c,0,e));return ce=(e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value)||(t.add(e.value),0)))})(t.filter(e=>1===y(e.value,l,c))),$e(ce,e)}if(ce.length){const t=ce.length;for(let n=0;n<t;n++){let t=ce[n].value;t="//*"+t.substring(t.indexOf("//")+2+u.length);1===y(t,e,c)&&ce.push({key:`${ce[n].key} regex`,value:t})}}return ce.length||i||(ce=Te(l,c,0,n)),$e(ce,n)},Fe={parseDOM:Ue,getTextXPath:qe,getUniqueClassName:Ve,attributesBasedXPath:Ye,addAllXPathAttributes:We,addRelativeXpaths:(e,t,n,a,r)=>{try{let o,l,s=[];if(ce=[],console.log(r),r)for(const t of r){const n=M(e,{name:t.name,value:t.value},a);console.log(n[0]||"");for(const e of n)e&&s.push(e)}if(e.textContent){let t=z(e,{name:"text",value:e.textContent});console.log(t),t&&s.push(t)}if(s.push(e.tagName),s?.length)for(let r=0;r<s.length;r++)if(!ce.length){if(ze(e,t,a,s[r]),!ce.length&&(o||(o=Le(e.parentElement,t,e)),console.log(o),o&&(o.includes("@")||o.includes("text()")||o.includes(".="))&&o.match(/\//g)?.length-2<5)){const a=o+`/${s[r]}`,l=y(a,e,t);if(1===l)ce.push({key:"relative xpath by relative parent",value:a});else if(l>1&&n){const r=b(a,e,t,l);r&&1===y(r,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(!ce.length&&(l||(l=Ie(e,t,e)),l&&(l.includes("@")||l.includes("text()")||l.includes(".=")))){const a=l.replace(/^\/+/,""),o=`/${s[r]}/${a}`,i=y(o,e,t);if(1===i)ce.push({key:"relative xpath by relative child",value:o});else if(i>1&&n){const a=b(o,e,t,i);a&&1===y(a,e,t)&&ce.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===ce?.length&&ce?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=qe(e,t,n,!1);a&&ce.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!ce.length){let o=_e(e.parentElement,t,e,a,s[r],n);o&&ce.push({key:"xpath by unique parent",value:o})}}return ce}catch(e){console.log(e)}},getXPathUsingAttributeAndText:je,getSiblingRelativeXPath:ze,getChildRelativeXpath:Ie,getParentRelativeXpath:Le,getUniqueParentXpath:_e,checkRelativeXpathRelation:Xe,buildAxesStrategyXpaths:Te};let He=[],Ge=[];const Be=/^[\S]+( [\S]+)*$/gi,Ze=(e,t,n,a,r,o,l,s=0,i=!1)=>{let c="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=o.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=o.length;e++)c.unshift(e===o.length?o[o.length-e]:u[u.length-e]);const f=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}::${te(t,e[e.length-1])}`;let o=y(c,e[e.length-1],a);if(1===o)return[{key:`dynamic ${n}`,value:T(c)}];if(o>1&&r&&(c=b(c,e[e.length-1],a,o),c&&(o=y(c,e[e.length-1],a),1===o)))return[{key:`dynamic ${n} ${r?" index":""}`,value:T(c)}]}},Je=(e,t,n,a,r,o=!1,l=!1)=>{const s=e[e.length-2],i=e[e.length-1],c=A(i)??i.ownerDocument,u=n.find(e=>e?.key?.includes("absolute"))?.value||X(s,s.ownerDocument),f=[],d=[];u.split("/").map(e=>f.push(e)),f.map(e=>d.push(e.replace(/\[([0-9]+)\]/gm,"")));const g=a.find(e=>e?.key?.includes("absolute"))?.value||X(i,i.ownerDocument),h=[],$=[];g.split("/").map(e=>h.push(e)),h.map(e=>$.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var y=0;y<f.length&&f[y]==h[y];y++);const N=[];for(let e=y-1;e<f.length;e++)f[e]&&N.push(d[e]);const b=[];for(let e="descendant"===r?y:y-1;e<h.length;e++)h[e]&&(b.length?b.push($[e]):b.push($[e].replace(/\[([0-9]+)\]/gm,"")));let x;if(Ge=(e=>{const t=e=>{const t=e.value||"",n=/(?:contains\s*\(\s*normalize-space\s*\(\s*\.\s*\)|normalize-space\s*\(\s*\.\s*\)|contains\s*\(\s*text\s*\(\s*\)|text\s*\(\s*\)|\.\s*=)/.test(t),a=/@/.test(t);return n&&!a?0:n?1:2};return[...e].sort((e,n)=>t(e)-t(n))})(a),e[e.length-2].textContent){if(Be.test(e[e.length-2].textContent)){const t=e[e.length-2],n=p(t),a=w(t,n),r=a||(/\s/.test(n.trim())?`normalize-space(.)=${v(E(n))}`:`.=${v(n)}`);x=D(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${r}]`:`${e[e.length-2].tagName}[${r}]`}else x=D(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${Q(e[e.length-2])})]`:`${e[e.length-2].tagName}[${Q(e[e.length-2])}]`;N[N.length-1]=x;const n=N.join("["),a=N.length-1,s=n;for(let n=0;n<Ge.length;n++){let i;if(i=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value,i){const n=Ze(e,i,r,c||t,o,b,s,a,l);if(n?.length)return n}}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(O(n,e[e.length-2])){let a=n.nodeValue;if(a){a=m(n.name,a);const s=n.name;x=D(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${v(a)}]`:`${e[e.length-2].tagName}[@${s}=${v(a)}]`,N[N.length-1]=x;const i=N.join("["),u=N.length-1,f=i;for(let n=0;n<Ge.length;n++){let a;a=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value;const s=Ze(e,a,r,c||t,o,b,f,u,l);if(s?.length)return s}}}for(const n of Array.from(e[e.length-2].attributes))if(O(n,e[e.length-2])){let a=n.nodeValue;if(a){a=m(n.name,a);const s=L(n,e[e.length-2]);if(s){x=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,N[N.length-1]=x;const n=N.join("["),a=N.length-1,i=n;for(let n=0;n<Ge.length;n++){let s;s=Ge[n].value.startsWith("//")?Ge[n].value.substring(Ge[n].value.indexOf("//")+2):Ge[n].value;const u=Ze(e,s,r,c||t,o,b,i,a,l);if(u?.length)return u}}}}}const k=N.join("["),S=N.length-1,C=xt(`${k+(S?"]".repeat(S):"")}`,b,e[e.length-1],e,t,r,o,l);if(C)return C},Ke=(e,t,n,a,r,o,l)=>{let s,i;console.log("getXpathRelationExpression",n);const c=[];try{s=a.filter(e=>!e?.key?.includes("absolute")).filter(t=>$t(t.value,e)),i=r.filter(e=>!e?.key?.includes("absolute"));for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const l=0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2),u=lt(s[a].value,e);let f=`//${u}/${n}::${te(l)}`;console.log("getXpathRelationExpression",f);const m=y(f,t,t.ownerDocument);if(m>1){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=mt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:T(r)}),c;const l=gt(u,n,t,i,t.ownerDocument);if(l)return c.push({key:`dynamic ${n}`,value:T(l)}),c;if(o){if(f=b(f,t,t.ownerDocument,m),f)return c.push({key:`dynamic ${n}${o?" index":""}`,value:T(f)}),c}else m>1&&(He.length?m<He[0].count&&(He.pop(),He.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m})):He.push({key:"relative xpath by relative child "+(o?"index":""),value:f,count:m}))}else if(1===m){if(ot(l)){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;const r=mt(u,e,t,n,i);if(r)return c.push({key:`dynamic ${n} bridge`,value:T(r)}),c}return c.push({key:`dynamic ${n}`,value:T(f)}),c}}if(!c.length){const a=dt(e,t,n,s,i);if(a.length)return c.push(...a),c;for(let a=0;a<s.length;a++){const r=lt(s[a].value,e),o=mt(r,e,t,n,i);if(o)return c.push({key:`dynamic ${n} bridge`,value:T(o)}),c}for(let a=0;a<s.length;a++)for(let r=0;r<i.length;r++){const u=`${0!==i[r].value.indexOf("//")?i[r].value:i[r].value.substring(i[r].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(u.length>1){const r=lt(s[a].value,e),f=mt(r,e,t,n,i);if(f)return c.push({key:`dynamic ${n} bridge`,value:T(f)}),c;const m=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},Qe=/\/(?=(?:[^']*'[^']*')*[^']*$)/g,et=e=>0===e.indexOf("//")?e.substring(e.indexOf("//")+2):e,tt=(e,t)=>nt(e,t)[0]||"",nt=(e,t)=>{const n=[];let a="";const r=e=>{e&&!n.includes(e)&&n.push(e)};for(const n of t){const t=et(n.value);if(t&&1===t.split(Qe).length){if(t===e.tagName||t===e.tagName.toLowerCase()){a=t;continue}r(te(t))}}for(const t of at){const n=e.getAttribute(t);if(!n)continue;const a=rt(t,n);a&&r(D(e)?`*[local-name()='${e.tagName}' and ${a}]`:`${e.tagName}[${a}]`)}if(e.textContent){const t=Q(e);t&&r(D(e)?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName}[${t}]`)}const o=u(e,e.getAttribute("class"),e.getRootNode?.()??e.ownerDocument,!1);for(const t of o)r(D(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(D(e)?`*[local-name()='${e.tagName}' and @${t.name}=${v(m(t.name,t.nodeValue))}]`:`${e.tagName}[@${t.name}=${v(m(t.name,t.nodeValue))}]`);return a&&r(a),r(D(e)?`*[local-name()='${e.tagName}']`:e.tagName),n},at=["aria-labelledby","aria-label","role","name","data-testid","data-test","data-qa","data-id","id"],rt=(e,t)=>{const n=m(e,t);return n?/\d/.test(n)?"":`@${e}=${v(n)}`:""},ot=e=>e.split(Qe).length>1||/\[\d+\]/.test(e),lt=(e,t)=>0!==e.indexOf("//")?te(e):te(e.substring(e.indexOf("//")+2)),st=e=>{const t=[];for(const n of at){const a=e.getAttribute(n);if(!a)continue;const r=rt(n,a);if(r){t.push(D(e)?`*[local-name()='${e.tagName}' and ${r}]`:`${e.tagName}[${r}]`);break}}return t},it=(e,t=6)=>{const n=[];let a=e;for(;a&&n.length<t;)n.push(a),a=a.parentElement;return n},ct=(e,t)=>{const n=rt(e,t);if(n)return n;const a=m(e,t);if("id"!==e||!a)return"";const r=a.match(/^(.+?)-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),o=r?.[1]?.trim();return!o||o.length<=2||!/[a-zA-Z]/.test(o)?"":`contains(@${e},${v(o)})`},ut=(e,t,n,a,r,o,l)=>{let s=n.parentElement,i=0;for(;s&&s!==a&&i<6;){i++;for(const t of at){const a=s.getAttribute(t);if(!a)continue;const i=rt(t,a);if(!i)continue;const c=D(s)?`*[local-name()='${s.tagName}' and ${i}]`:`${s.tagName}[${i}]`,u=`//${te(e)}/${r}::${o}/descendant::${c}/descendant::${te(l)}`;if(1===y(u,n,n.ownerDocument))return u}s=s.parentElement}return""},ft=["title",...at],mt=(e,t,n,a,r)=>((e,t,n,a,r)=>{if("following"!==a&&"preceding"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=pt(`//${te(e)}`,t.ownerDocument)||t;let s=n.parentElement,i=0;for(;s&&i<6;)if(i++,l.compareDocumentPosition(s)&("following"===a?Node.DOCUMENT_POSITION_FOLLOWING:Node.DOCUMENT_POSITION_PRECEDING)){for(const t of ft){const r=s.getAttribute(t);if(!r)continue;const l=rt(t,r);if(!l)continue;const i=D(s)?`*[local-name()='${s.tagName}' and ${l}]`:`${s.tagName}[${l}]`;for(const t of o){const r=`//${te(e)}/${a}::${i}/descendant::${te(t)}`;if(1===y(r,n,n.ownerDocument))return r}}s=s.parentElement}else s=s.parentElement;return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("following-sibling"!==a&&"preceding-sibling"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=it(t),s=it(n);for(const t of l){const r=st(t);if(r.length)for(const l of s){const s=st(l);if(!s.length)continue;const i="following-sibling"===a?t.nextElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)>Array.from(t.parentElement?.children||[]).indexOf(t):t.previousElementSibling===l||Array.from(t.parentElement?.children||[]).indexOf(l)<Array.from(t.parentElement?.children||[]).indexOf(t);if(t.parentElement&&t.parentElement===l.parentElement&&i)for(const t of r)for(const r of s)for(const l of o){const o=`//${te(e)}/ancestor-or-self::${t}/${a}::${r}/descendant-or-self::${te(l)}`;if(1===y(o,n,n.ownerDocument))return o}}}return""})(e,t,n,a,r)||((e,t,n,a,r)=>{if("child"!==a)return"";const o=nt(n,r);if(!o.length)return"";const l=it(n).filter(e=>e.parentElement===t);for(const t of l){const a=st(t);if(a.length)for(const t of a)for(const a of o){const r=`//${te(e)}/child::${t}/descendant-or-self::${te(a)}`;if(1===y(r,n,n.ownerDocument))return r}}return""})(e,t,n,a,r),dt=(e,t,n,a,r)=>"ancestor"!==n&&"ancestor-or-self"!==n?[]:bt(e,t,n,a,r,!1),gt=(e,t,n,a,r)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";for(const o of a){const a=et(o.value);if(!a||a.split(Qe).length>1||/\[\d+\]/.test(a))continue;const l=`//${e}/${t}::${te(a)}`;if(1===y(l,n,r))return l}return""},ht=(e,t,n,a)=>{if("descendant"!==t&&"descendant-or-self"!==t)return"";const r=nt(n,[...Ue(n,n.ownerDocument,!1,!1)||[],...ne(n,n.ownerDocument,!0)||[],{key:"tag",value:n.tagName}]);if(!r.length)return"";let o=n.parentElement,l=0;for(;o&&l<10;){l++;for(const l of at){const s=o.getAttribute(l);if(!s)continue;const i=ct(l,s);if(!i)continue;const c=D(o)?`*[local-name()='${o.tagName}' and ${i}]`:`${o.tagName}[${i}]`;for(const o of r){const r=`//${e}/${t}::${c}/descendant::${te(o)}`;if(1===y(r,n,a))return r}}o=o.parentElement}return""},pt=(e,t)=>{try{const n=t.evaluate(e,t,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;return n instanceof Element?n:null}catch{return null}},$t=(e,t)=>{const n=et(e);if(!n)return!1;try{const e=t.ownerDocument.evaluate(`//${te(n)}`,t.ownerDocument,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let a=e.iterateNext();for(;a;){if(a===t)return!0;a=e.iterateNext()}}catch{return!1}return!1},yt=e=>{const t=e.getAttribute("fill"),n=e.getAttribute("stroke");if(/\d/.test(t||"")||/\d/.test(n||""))return"";const a=t?`@fill=${v(t)}`:n?`@stroke=${v(n)}`:"";return a?`*[local-name()='${e.tagName.toLowerCase()}' and ${a}]`:""},vt=(e,t,n)=>{const a=t.getAttribute("fill"),r=t.getAttribute("stroke"),o=Array.from(e.querySelectorAll(t.tagName.toLowerCase())).slice(0,30);let l=0;for(const e of o){if(a&&e.getAttribute("fill")!==a||!a&&r&&e.getAttribute("stroke")!==r)continue;const t=e.closest(n.tagName.toLowerCase());if(t&&(l++,t!==n||l>1))return!1}return 1===l},Nt=(e,t,n,a,r)=>{const o=Array.from(n.querySelectorAll("path,use,circle,rect,polygon,polyline,line")).slice(0,25);if(!o.length)return"";const l=[...(s=a,u(s,s.getAttribute("class"),s.getRootNode?.()??s.ownerDocument).map(e=>`${s.tagName.toLowerCase()}[${e}]`)),a.tagName];var s;for(const t of o){const o=yt(t);if(o&&vt(a,t,n))for(const t of l)return`//${te(e)}/${r}::${t}/descendant::${o}/ancestor::${n.tagName.toLowerCase()}`}return""},bt=(e,t,n,a,r,o)=>{const l=[],s=((e,t)=>{let n=e;for(;n;){if(n.contains(t))return n;n=n.parentElement}return null})(e,t);if(!s||s===t)return l;const i=D(s)?`*[local-name()='${s.tagName}']`:s.tagName,c=((e,t,n)=>{const a=[];let r=t;for(;r&&r!==e;){const e=r===t?tt(t,n):D(r)?`*[local-name()='${r.tagName}']`:r.tagName;a.unshift(e),r=r.parentElement}return r===e?a.join("/"):""})(s,t,r);if(!c)return l;const u=c.split(Qe).length>1?tt(t,r):"",f=u?((e,t)=>{let n=e,a=0;const r=[],o=new Set(["SECTION","FIELDSET","FORM","ARTICLE","MAIN"]);for(;n&&n.contains(t)&&a<6;){a++;for(const e of at){const t=n.getAttribute(e);if(!t)continue;const l=rt(e,t);if(!l)continue;const s=D(n)?`*[local-name()='${n.tagName}' and ${l}]`:`${n.tagName}[${l}]`,i=(o.has(n.tagName)?100:0)+("data-testid"===e?20:0)-a;r.push({nodeTest:s,score:i});break}n=n.parentElement}return r.sort((e,t)=>t.score-e.score)[0]?.nodeTest||""})(s,t):"";for(const e of a){const a=et(e.value);if(!a)continue;if(f){const e=`//${te(a)}/${n}::${f}/descendant::${te(u)}`;if(1===y(e,t,t.ownerDocument))return l.push({key:`dynamic ${n} bridge`,value:T(e)}),l}let r=u?`//${te(a)}/${n}::${i}/descendant::${te(u)}`:`//${te(a)}/${n}::${i}/${c}`,m=y(r,t,t.ownerDocument);const d=Nt(a,0,t,s,n);if(d)return l.push({key:`dynamic ${n} icon bridge`,value:T(d)}),l;if(1===m)return l.push({key:`dynamic ${n} bridge`,value:T(r)}),l;if(u&&m>1){const e=ut(a,0,t,s,n,i,u);if(e)return l.push({key:`dynamic ${n} bridge`,value:T(e)}),l;if(r=`//${te(a)}/${n}::${i}/${c}`,m=y(r,t,t.ownerDocument),1===m)return l.push({key:`dynamic ${n} bridge`,value:T(r)}),l}if(m>1&&o&&(r=b(r,t,t.ownerDocument,m),m=r?y(r,t,t.ownerDocument):0,r&&1===m))return l.push({key:`dynamic ${n} bridge index`,value:T(r)}),l}return l},xt=(e,t,n,a,r,o,l,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${o}::${te(s)}`;const c=y(i,n,r);if(1===c)return[{key:`dynamic ${o}`,value:T(i)}];if(c>1&&l&&(i=b(i,a[a.length-1],r,c),i))return[{key:`dynamic ${o}${l?" index":""}`,value:T(i)}]}else for(let s=1;s<=t.length;s++){const c=Et(t.slice(t.length-s,t.length).join("/"),n);for(const t of c){i=`//${e}/${o}::${te(t)}`;const s=y(i,n,r);if(1===s){if(t.split(Qe).length>1||/\[\d+\]/.test(t)){const t=ht(e,o,n,r);if(t)return[{key:`dynamic ${o}`,value:T(t)}]}return[{key:`dynamic ${o}`,value:T(i)}]}if(s>1){const t=gt(e,o,n,Ue(n,n.ownerDocument,!1,!1)||[],r);if(t)return[{key:`dynamic ${o}`,value:T(t)}];const c=ht(e,o,n,r);if(c)return[{key:`dynamic ${o}`,value:T(c)}];if(l&&(i=b(i,a[a.length-1],r,s),i))return[{key:`dynamic ${o}${l?" index":""}`,value:T(i)}]}}}},Et=(e,t)=>{const n=t.getAttribute("class")||"",a=u(t,n,t.getRootNode?.()??t.ownerDocument);if(!a.length)return[e];const r=`${t.tagName}[@class=${v(n)}]`;return e.endsWith(r)?a.map(n=>{const a=`${t.tagName}[${n}]`;return`${e.slice(0,-r.length)}${a}`}):[e]},wt={findRelativeXpath:(e,t,n,a,r,o,l=!1,s=null)=>{let i=[];const c=s||[],u=(o,s)=>{let c=[];c="descendant"===o||"descendant-or-self"===o?Je([e,t],n,a,r,o,s,l)||[]:Ke(e,t,o,a,r,s,l)||[],c.length&&(i=i.concat(c))};for(const e of c)u(e,o);return i},getDescendantXpath:Je,getAncestorBridgeXpath:bt,getXpathRelationExpression:Ke,getTraverseXpathExpression:xt,getReferenceElementXpath:e=>{let t=[];t=Ue(e,e.ownerDocument,!1,!1);const n=ne(e,e.ownerDocument,!1);if(n?.length&&(t=t?.length?t.concat(n):n),t?.length){let n=Ue(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=Ue(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value});t?.length||(t=[{key:"",value:_(e,e.ownerDocument,!1,!1,Array.from(e.attributes))}]),t?.length||(t=[{key:"",value:_(e,e.ownerDocument,!0,!1,Array.from(e.attributes))}],t=t?.map(e=>"("==e.value.charAt(0)&&re(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:N(e.value)}:{key:"",value:e.value}));const a=Array.from(e.children||[]).map(t=>{const n=p(t)?.trim();if(!n||n!==p(e)?.trim())return null;const a=w(t,n),r=a||(/\s/.test(n)?`normalize-space(.)=${v(E(n))}`:`.=${v(n)}`);return{key:"reference child text",value:`${t.tagName}[${r}]`}}).filter(e=>!!e);a.length&&(t=a.concat(t));const r=X(e,e.ownerDocument);return t=t.filter(e=>e.value!==r),t.push({key:"absolute xpath",value:r.slice(1)}),t},getSmartRelations:(e,t)=>{const n=e.compareDocumentPosition(t),a=[],r=[],o=[];n&Node.DOCUMENT_POSITION_CONTAINS&&a.push("ancestor","ancestor-or-self","parent"),n&Node.DOCUMENT_POSITION_CONTAINED_BY&&a.push("child"),e.parentElement===t.parentElement&&a.push("following-sibling","preceding-sibling"),n&Node.DOCUMENT_POSITION_FOLLOWING&&r.push("following"),n&Node.DOCUMENT_POSITION_PRECEDING&&r.push("preceding"),o.push("descendant","descendant-or-self");const l=[...a,...r,...o];return[...new Set(l)]}};let kt=[];const St=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},At=(e,t="single")=>{const n=[],a=e.getRootNode();try{const r=Ct(e);if(r&&St(r,e,a)&&(n.push({key:"cssSelector by id",value:r}),"single"===t))return n;const o=Tt(e);o&&St(o,e,a)&&n.push({key:"cssSelector by class",value:o});const l=Dt(e);l&&n.push({key:"cssSelector by name",value:l})}catch(e){console.error(e)}return n},Ct=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!g(e.id)){t+=`#${CSS.escape(e.id)}`,a.unshift(t);break}{let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}a.unshift(t),e=e.parentElement}return a.join(" > ")},Rt=new Set(["id","class","style"]);function Ot(e){return Array.from(e.attributes).filter(e=>!Rt.has(e?.name?.toLowerCase())&&e.value&&!g(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const Dt=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=Ot(e);for(const t of r){const r=`${a}${t}`;if(St(r,e,n))return r}},Tt=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.tagName.toLowerCase();if(n.includes("style")||n.includes("script"))return;const a=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||g(e.className)||kt?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,a=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&a++;1!==a&&(t+=`:nth-of-type(${a})`),1===a&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${a})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,a.unshift(t);break}a.unshift(t),e=e.parentElement}return a.join(" > ")},Pt={parseCssSelectors:At,getIdCssPath:Ct,getAttributeCssPath:Dt,getClassCssPath:Tt,getAbsoluteCssPath:e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=[];for(;e&&e.nodeType===Node.ELEMENT_NODE;){const t=e.tagName.toLowerCase();if("style"===t||"script"===t)return;let a=t;const r=e.parentNode;if(r){const t=Array.from(r.children).filter(t=>t.tagName===e.tagName);t.length>1&&(a+=`:nth-of-type(${t.indexOf(e)+1})`)}n.unshift(a),e=e.parentElement}return n.join(" > ")}},Xt=(e,t,n)=>{const a=ae(e);if(Wt(t,a)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(a)){const e=t.evaluate(a,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},_t=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return zt(e.body,t)},Lt=(e,t,n)=>_t(t,e)===n,It=e=>e.name?.toLowerCase().includes("cssselector")??!1,zt=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:a}=n[e];if(a){const e=zt(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},Mt=e=>e?.id||null,jt=e=>e.className||null,Yt=e=>e.textContent?.trim()||null,Vt=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},qt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Wt(e,t){const n=e.defaultView;if(!n)return null;return(new n.XPathEvaluator).evaluate(t,e,null,n.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}function Ut(e,t,n){if(e.includes(t)){const a=e.split(t)[0].trim(),r=n.defaultView;if(!r)return null;if(!e.includes("dynamic")){const t=new r.XPathEvaluator;if(t.evaluate(a,n,null,r.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let a;return t.evaluate(e,n,null,r.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(a=e,a):(console.error("Complete Locator is Invalid:",e),a=e,a)}console.error("Source Locator Not Found:",a)}}return null}const Ft=(e,t)=>{const n=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");n&&n.forEach(e=>{e.remove()});const a=new Set;let r=[];function o(e,t={}){const n=e?.value,o=t.value??e?.value,l={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;l.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(l.name,n,o),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),r.push(e))}(l)}function l(e,t,n){if(It(t))return _t(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+le(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=le(n);return e.querySelector(`[name="${t}"]`)}if("tagName"===t.name)return e.querySelector(n);if("linkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null;if("partialLinkText"===t.name)return Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null;if(!t.name.includes("xpath")&&!n.startsWith("//")||t.type.match("dynamic"))return e.querySelector(n);{const a=Wt(e,ae(n));return a&&o(t,{value:n,isRecorded:String(t.isRecorded).includes("N")?"N":"Y"}),a}}function s(e,t,n){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const r=l(a,t,n);if(r)return r}catch{continue}return null}const i=(e,t,n)=>{if(!e)return null;let a=e.trim();return a&&"null"!==a.toLowerCase()?(a=a.replace(/\\"/g,'"').replace(/\\'/g,"'"),a=a.replace(/^['"](.+?)['"]$/,"$1"),a=a.replace(/''/g,"'"),a=a.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(a=a.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!a||/^['"]{2}$/.test(a)?null:a:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const c=e.locators.filter(e=>"N"===e.isRecorded);if(c.length>0)for(const e of c)o(e);const u=String(n.value||n.type||"");if(u.includes("dynamic")||u.match("dynamic")||u.includes("{")||u.includes("}")){o(n);continue}if(e.isShared.includes("Y"))break e;try{let c=null;const u=n.value.split(">>>");for(const e of u){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(c=l(t,n,a),c||(c=s(t,n,a)),c||(c=zt(t.body,a)),!c){console.error("Element not found at:",a);break}}const f=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(c){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),a=e.locators.filter(e=>It(e)&&e.value);for(const e of n)Xt(e.value,t,c)&&o(e,{isSelfHealed:null});for(const e of a)Lt(e.value,t,c)&&o(e,{isSelfHealed:null});const l=r.filter(e=>"xpath"===e.name&&e.value),s=new Set(l.map(e=>oe(e.value))),u=[],m=Mt(c);if(m&&!f("id",m)&&!g(m)){const n=e.locators.find(e=>"id"===e.name);se(t,"id",m,c)&&(u.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:m}))}const d=c.tagName;if(d&&!f("tagName",d)){const n=e.locators.find(e=>"tagName"===e.name);se(t,"tagName",d,c)&&(u.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:d}))}const h=Yt(c);if(h&&!g(h)){const n=e.locators.find(e=>"linkText"===e.name);se(t,"linkText",h,c)&&(u.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:h}))}const p=Vt(c);if(p&&!f("name",p)&&!g(p)){const n=e.locators.find(e=>"name"===e.name);se(t,"name",p,c)&&(u.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=jt(c);if($&&""!==$.trim()&&!$.includes(" ")&&!f("className",$)&&!g($)){const n=e.locators.find(e=>"className"===e.name);se(t,"className",$,c)&&(u.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}At(c,"single").forEach(e=>{e.value&&!f("cssSelector",e.value)&&o(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const y=Array.from(c.attributes).filter(e=>!u.includes(e.name));let v=[];try{v=Ue(c,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==v?.length){const e=n.filter(e=>!Xt(e.value,t,c));let a=0;for(const t of e){if(a>=e.length)break;const n=oe(t.value);if(s.has(n))continue;const r=v.find(e=>e.value&&oe(e.value)===n);r?.value&&(o(t,{name:"xpath",value:r.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}if(a<e.length)for(const t of v){if(a>=e.length)break;if(!t.value)continue;const n=oe(t.value);s.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),s.add(n),a++)}}for(const n of e.locators)try{for(const a of e.locators)if(a.value)for(const e of qt)if(a.value.includes(e)){const r=Ut(a.value,e,t);if(r){o(a,{name:"xpath",value:r,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(r.length<5){const e=[{name:"id",value:Mt(c)},{name:"name",value:Vt(c)},{name:"className",value:jt(c)},{name:"tagName",value:c.tagName},{name:"linkText",value:Yt(c)}];for(const n of e){if(r.length>4)break;const{name:e,value:a}=n;a&&(g(a)||f(e,a)||"className"===e&&a.includes(" ")||se(t,e,a,c)&&o(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}r.length<5&&At(c,"multiple").forEach(e=>{r.length>4||e.value&&(f("cssSelector",e.value)||se(t,"cssSelector",e.value,c)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const N=r.map(e=>({...e,value:i(e.value,e.name,e.isRecorded)})),b=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:N.filter(e=>null!=e?.value&&""!==e.value),isShared:`${e.isShared}`,projectId:`${e.projectId}`,projectType:`${e.projectType}`,isRecorded:`${e.isRecorded}`,folder:`${e.folder}`,parentId:`${e.parentId}`,parentName:`${e.parentName}`,platform:`${e.platform}`,licenseId:`${e.licenseId}`,licenseType:`${e.licenseType}`,userId:`${e.userId}`}];return b}}catch(e){console.error("Error processing locator:",n,e);continue}}catch(e){console.error("Error processing locator:",n,e);continue}return null};const Ht={getOptimalClassChain:function e(t,n,a){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const r=n.tagName,o=["name","label","value"];for(const e of o){const o=a.find(t=>t.name===e);if(!o)continue;let l=o.value;if(!l)continue;if(l=l.trim().replace(/\s+/g," "),g(l))continue;const s=`//${r}[@${e}="${l}"]`;let i=0;try{i=y(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(l);if(1===i)return c?`/${r}[\`${e} CONTAINS "${l}"\`]`:`/${r}[\`${e} == "${l}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===r).indexOf(n)+1;return c?`/${r}[\`${e} CONTAINS "${l}"\`][${t}]`:`/${r}[\`${e} == "${l}"\`][${t}]`}}let l=`/${r}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===r);if(e.length>1){l+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,a)+l}catch(e){return console.log(`Unable to generate optimal -ios class chain : ${JSON.stringify(e)}`),null}},getOptimalPredicateString:function(e,t,n){try{if(!t?.tagName||1!==t?.nodeType||"XCUIElementTypeApplication"===t?.tagName)return"";let a=[],r=[];for(let o of n){const n=o.value,l=o.name;if(0!==n.length&&(n&&!g(n))){a.push(`@${l}="${n}"`);const o=`//*[${a.join(" and ")}]`;let s;r.push(`${l} == "${n}"`);try{s=y(o,t,e)}catch(e){console.log(e);continue}if(1===s)return r.join(" AND ")}}}catch(e){console.log(`The most optimal '-ios predicate string' could not be determined because an error was thrown: '${JSON.stringify(e,null,2)}'`)}return null}},Gt=()=>({xpath:Fe,referenceXpaths:wt,xpathUtils:ie,getElementsFromHTML:Ft,cssSelectors:Pt,iosSelectors:Ht});exports.createXPathAPI=Gt,exports.default=Gt;
2
2
  //# sourceMappingURL=index.browser.cjs.map