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