ff-dom 3.0.3 → 3.0.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/xpath.mjs CHANGED
@@ -1 +1 @@
1
- import{JSDOM as e,VirtualConsole as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i;let r=new WeakMap;const a=new Set,o=e=>{if(!e)return r=new WeakMap,s=new WeakMap,void a.forEach(e=>e(null));(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const r=e.getRootNode?.();return 9!==r?.nodeType&&11!==r?.nodeType||n(r),n(9===e.nodeType?e:e.ownerDocument),t})(e).forEach(e=>{r.delete(e)}),s=new WeakMap,a.forEach(t=>t(e))},l=(e,t)=>{const{owner:n,contextNode:a}=(e=>{const t=9===e.nodeType?e:e.ownerDocument||document;return{owner:t,contextNode:1===e.nodeType||9===e.nodeType||11===e.nodeType?e:t}})(t);let o=r.get(a);o||(o=new Map,r.set(a,o));const l=o.get(e);if(l)return l;const s=n.evaluate(e,a,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let s=new WeakMap,i=[];const c=new WeakMap,u=new Set(["flntooltip","flntooltip-bottom","fln-shield"]),f=new Set(["marked-element-temp","marked-element","mark-successfully","removePointers","element-style-reset",...u]),m=/^(?:(?:ng|ion)-(?:pristine|dirty|valid|invalid|touched|untouched|pending|submitted|focused)|oj-(?:focus(?:-highlight)?|hover|active|selected|enabled|disabled)|(?:item-)?has-(?:focus|value)|ng-star-inserted|hydrated|md|ios)$/,d=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!f.has(e)).sort(),h=e=>/\d/.test(e||""),g=e=>m.test(e),p=(e,t,n,r=!1)=>{const a=d(t),o=$(e,t,r);return o.length?1===a.length&&1===o.length?[`@class=${S(o[0])}`]:o.map(t=>{const r=b(`contains(@class,${S(t)})`,I(e),e.tagName.toLowerCase());return{token:t,count:V(r,e,n)}}).sort((e,t)=>e.token.length!==t.token.length?e.token.length-t.token.length:e.count-t.count).map(({token:e})=>`contains(@class,${S(e)})`):[]},$=(e,t,n=!1)=>{const r=c.get(e);return d(t).filter(e=>!(r?.has(e)||g(e)||!n&&h(e)))},y=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),v=(e,t)=>t?"class"===e||"className"===e?d(t).join(" "):t.replace("removePointers","").trim():"",x=e=>/\d/.test(e),b=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,N=e=>{const t=e?.textContent;return t},w=e=>e?.childNodes[0]?.nodeValue||"",E=(e,t,n,r=!1)=>{try{if(L(n)){const{owner:a,contextNode:o,cloneElement:l,cloneElements:s}=O(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:a,second:o}=l(e,n);if(!a)return 0;if(!o)return a===t?1:0;if(r&&Array.isArray(t)){let r=0;if(t.includes(a)&&r++,t.includes(o)&&r++,2===r)return 2;const l=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=l.iterateNext();)if(t.includes(s)&&(r++,2===r))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}'`},k=(e,t,n,r)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let o=0;if(r){if(1===E(`${e}[${r}]`,t,n))return`${e}[${r}]`;if(1===E(`(${e})[${r}]`,t,n))return`(${e})[${r}]`}const l=a.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=l.iterateNext();)if(o++,s.isSameNode(t))return 1===E(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===E(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},C=e=>e?e.replace(/\s\s+/g," ").trim():e,A=(e,t)=>{const n=C((t||"").trim());if(!e.children.length||n.length<=50)return"";const r=n.split(/\s+/).slice(0,3).join(" ");return r.length>2?`contains(normalize-space(.),${S(r)})`:""},R=e=>{const t=C((e||"").trim());if(!t||!h(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),r=n.split(/[^a-zA-Z]+/).map(e=>C(e).trim()).filter(e=>e.length>2&&/[a-zA-Z]/.test(e)).join(" ").trim();return{prefix:n.length>2&&/[a-zA-Z]/.test(n)?n:"",fragment:r.length>2?r:""}},T=e=>R(e).fragment,L=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,O=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),r=n.createElement("div");r.innerHTML=e.innerHTML,n.body.appendChild(r);const a=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let r=t;for(;r&&r.parentElement;){const e=r.parentElement;n.unshift(Array.from(e.children).indexOf(r)),r=e}return r&&r.parentNode===e?(n.unshift(Array.from(e.children).indexOf(r)),n):null})(e,t);return n?((e,t)=>{let n=e;for(const e of t){const t=n.children.item(e);if(!t)return null;n=t}return n})(r,n):null},o=Array.isArray(t)?t.map(e=>a(e)).filter(Boolean):[],l=Array.isArray(t)?null:a(t??null);return{owner:n,contextNode:r,cloneElement:l,cloneElements:o}},D=(e,t,n)=>{if("class"===e.name&&e.value.split(/\s+/).some(e=>f.has(e))){i.some(e=>e.doc===t.ownerDocument&&e.element===t&&"class"===e.attributeName)||i.push({url:t.baseURI,attributeName:"class",element:t,doc:t.ownerDocument})}const r=v(e.name,e.value);if(!r||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay","element-style-reset"].some(e=>e===r))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;if("class"===e.name||"className"===e.name){const n=c.get(t);return d(e.value).filter(e=>!n?.has(e)&&!g(e)&&!h(e)).length>0}const a=i?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!a&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(o=e.name,l=r,(!y.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(l))&&("class"===e.name||!h(r)))));var o,l},P=(e,t,n)=>{const r=((e,t)=>[t?"target":"reference",e.name,String(e.value)].join("::"))(e,n);let a=s.get(t);if(a){if(a.has(r))return a.get(r)}else a=new Map,s.set(t,a);const o=D(e,t);return a.set(r,o),o},I=e=>e instanceof SVGElement,z=(e,t,r,a,o,l)=>{if(a){const{tagName:s}=e;let i,c="";const u=[];let f;const m=r.startsWith("@"),d="."===r||"text()"===r,g=d?".":r,$=d&&/\s/.test(a.trim()),y=d?T(a):a,v=d&&h(a)?y:a,N=d?A(e,v):"";if("@class"===r){for(const n of p(e,a,t)){if(f=b(n,I(e),e.tagName.toLowerCase()),i=E(f,e,t),1===i&&!o)return f;{const n=k(f,e,t,i);if(n)return n}}return}if(d&&h(a)&&!y)return;if(a&&(!m||!x(a))){if(f=N?b(N,I(e),e.tagName.toLowerCase()):$?b(`normalize-space(${g})=${S(C(v)).trim()}`,I(e),e.tagName.toLowerCase()):n.test(a)?`//${s}[${r}=${S(v)}]`:b(`normalize-space(${r})=${S(C(v)).trim()}`,I(e),e.tagName.toLowerCase()),i=E(f,e,t),1===i&&!o)return f;{const n=k(f,e,t,i);if(n)return n}}if(m&&h(a))return;if(a&&l){const l=a.split(" ");if(l?.length)if(1===l.length){const u=[...new Set(l[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&C(u[0].trim())?.length>1&&a.startsWith(u[0])&&(c=n.test(u[0])?`starts-with(${r},${S(u[0]).trim()})`:`starts-with(${r},${S(C(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&C(u[u.length-1].trim())?.length>1&&a.endsWith(u[u.length-1])&&(c=n.test(u[u.length-1])?`ends-with(${r},${S(u[u.length-1]).trim()})`:`ends-with(${r},${S(C(u[u.length-1])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),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]&&C(d[0].trim())?.length&&a.startsWith(d[0])&&(c=n.test(d[0])?`starts-with(${r},${S(d[0]).trim()})`:`starts-with(${r},${S(C(d[0])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),1===i&&!o))return f;const h=l.slice(u,l.length-1).join(" ");if(d=[...new Set(h.match(/([^0-9]+)/g))],d?.length&&d[0]&&C(d[0].trim())?.length>3&&a.endsWith(d[0])&&(c=n.test(d[0])?`ends-with(${r},${S(d[0]).trim()})`:`ends-with(${r},${S(C(d[0])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),1===i&&!o))return f}}if(a&&l&&x(a)){const l=[...new Set(a.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&C(l[e].trim())?.length>1&&(n.test(l[e])?u.push(`contains(${r},${S(l[e].trim()).trim()})`):u.push(`contains(${r},${S(C(l[e])).trim()})`));if(u?.length&&(f=I(e)?`//*[local-name()='${s}' and ${u.join(" and ")}]`:`//${s}[${u.join(" and ")}]`,i=E(f,e,t),1===i&&!o))return f}if(f=I(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=E(f,e,t),1===i&&!o)return f}},_=(e,t,r,a)=>{try{const o=r.filter(t=>P(t,e,a)),l=r=>{const a=v(r.name,r.nodeValue);return a?"class"===r.name?p(e,a,t):h(a)?[]:n.test(a)?[`@${r.name}="${a}"`]:[`normalize-space(@${r.name})="${a}"`]:[]},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 t=C(N(e)?.trim()||""),r=T(t);if(h(t))return r?[`contains(normalize-space(.),${S(r)})`]:[];if(!t||t.length>80||/^\d+$/.test(t)){const n=A(e,t);return n?[n]:[]}const a=new Set,o=A(e,t);return o?(a.add(o),Array.from(a)):(n.test(t)&&t.length<=40&&!t.includes(" ")&&a.add(`text()=${S(t)}`),t.includes(" ")&&a.add(`normalize-space(.)=${S(C(t))}`),a.add(`contains(text(),${S(t)})`),Array.from(a))},u=(e,t)=>{const n=[],r=(a,o)=>{if(o.length!==t)for(let t=a;t<e.length;t++)o.push(e[t]),r(t+1,o),o.pop();else n.push([...o])};return r(0,[]),n},f=t=>I(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,m=(()=>{if(!(o.length<2))for(let n=2;n<=o.length;n++){const r=u(o,n);for(const n of r){const r=i(n);for(const n of r){if(n.length<2)continue;const r=f(n);let a;try{a=E(r,e,t)}catch{continue}if(1===a)return r}}}})();if(m)return m;const d=c();if(!d.length||!o.length)return;for(let n=1;n<=o.length;n++){const r=u(o,n);for(const n of r){const r=i(n);for(const n of r)if(n.length)for(const r of d){const a=[...n,r],o=f(a);try{if(1===E(o,e,t))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},W=(e,t,n)=>M(e,t,n)[0]||"",M=(e,t,r)=>{let a=I(e),o="";if(P(t,e,r)){let r=v(t.name,t.value);const l=t.name;if("class"===l){const t=e.getRootNode?.()??e.ownerDocument;return p(e,r,t).map(t=>a?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName||"*"}[${t}]`)}if(h(r))return[];o=n.test(r)?a?`*[local-name()='${e.tagName}' and @${l}=${S(r)}]`:`${e.tagName||"*"}[@${l}=${S(r)}]`:a?`*[local-name()='${e.tagName}' and normalize-space(@${l})=${S(r)}]`:`${e.tagName||"*"}[normalize-space(@${l})=${S(r)}]`}return o?[o]:[]},X=(e,t)=>{if(!e.textContent)return"";const r=w(e),a=T(r);if(h(r)&&!a)return"";const o=h(r)?a:r,l=A(e,o);let s;return s=l?b(l,I(e),e.tagName||"*"):h(r)?b(`contains(normalize-space(.),${S(o)})`,I(e),e.tagName||"*"):!n.test(r)||/\s/.test(r.trim())?b(`normalize-space(.)=${S(o)}`,I(e),e.tagName||"*"):I(e)?`//*[local-name()='${e.tagName}' and .=${S(o)}]`:`//${e.tagName||"*"}[.=${S(o)}]`,s},Y=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===d(n).length&&1===t.length?b(`normalize-space(@class)=${S(t[0])}`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{fragment:t}=R(n);return t?b(`contains(normalize-space(.),${S(t)})`,I(e),e.tagName.toLowerCase()):""}return b(`normalize-space(${t})=${S(C(n)).trim()}`,I(e),e.tagName.toLowerCase())},j=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===t.length?b(`starts-with(normalize-space(@class),${S(t[0])})`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{prefix:t,fragment:r}=R(n),a=t||r;return a?b(`starts-with(normalize-space(.),${S(a)})`,I(e),e.tagName.toLowerCase()):""}return b(`starts-with(${t},${S(C(n)).trim()})`,I(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===t.length?b(`contains(@class,${S(t[0])})`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{fragment:t}=R(n);return t?b(`contains(normalize-space(.),${S(t)})`,I(e),e.tagName.toLowerCase()):""}return b(`contains(${t},${S(C(n)).trim()})`,I(e),e.tagName.toLowerCase())},H=(e,t)=>{const r=t.flatMap(t=>(t=>{const r=v(t.name,t.value);if(!r)return[];if("class"===t.name){const t=e.getRootNode?.()??e.ownerDocument;return p(e,r,t)}return h(r)?[]:n.test(r)?[`@${t.name}=${S(r)}`]:[`normalize-space(@${t.name})=${S(r)}`]})(t)).filter(Boolean);if(r.length>=2)return b(`${r[0]} or ${r[1]}`,I(e),e.tagName.toLowerCase());const a=(()=>{const t=C(N(e)?.trim()||""),r=T(t);if(h(t))return r?`contains(normalize-space(.),${S(r)})`:null;const a=A(e,t);return a||(!t||t.length>80||/^\d+$/.test(t)?null:n.test(t)&&t.length<=40&&!t.includes(" ")?`text()=${S(t)}`:t.includes(" ")?`normalize-space(.)=${S(t)}`:`contains(text(),${S(t)})`)})();return 1===r.length&&a?b(`${r[0]} or ${a}`,I(e),e.tagName.toLowerCase()):""},V=(e,t,n)=>{try{return E(e,t,n)}catch(e){return 0}},F=(e,t)=>{const n=[],r=new Set,a=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"],l=[...o.map(e=>a.find(t=>t.name===e)).filter(Boolean),...a.filter(e=>!o.includes(e.name))],s=a=>{a&&!r.has(a)&&Z(a,e,t)&&(r.add(a),n.push(a))};l.forEach(t=>{if(P(t,e,!1))for(const n of ee(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=X(e);t&&s(t)}if(a.length>1){const n=_(e,t,a,!1);n&&s(n)}return n},B=(e,t)=>{const n=[];let r=t;for(;r&&r!==e;)n.unshift(J(r)),r=r.parentElement;return r===e?n.join("/"):""},G=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),r=J(e),a=I(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const a=F(t,n);for(const o of a){const a=`${o}/descendant::${r}`;if(1===V(a,e,n)&&U(a,n)===e)return a;const l=B(t,e);if(l){const t=`${o}/${l}`;if(1===V(t,e,n)&&U(t,n)===e)return t}}}return 1===V(a,e,n)&&U(a,n)===e?a:""},U=(e,t)=>{try{if(L(t)){const{owner:n,contextNode:r,cloneElement:a}=O(t);return n.evaluate(e,r,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||a}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},Z=(e,t,n)=>{try{const{first:r,second:a}=l(e,n);return!!r&&!a&&r===t}catch{return!1}},J=e=>I(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),K=(e,t,n)=>{if(!(e instanceof Element))return[];const r=new Set,a=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(r=t.value,!/\d/.test(r))&&P(t,e,n);var r}),l=(e,t)=>{t&&!r.has(t)&&(r.add(t),a.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"];s.forEach(n=>{const r=o.find(e=>e.name===n);if(r)for(const n of ee(e,r.name,r.value))n&&Z(n,e,t)&&l(`anchor by ${r.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const r of ee(e,n.name,n.value))r&&Z(r,e,t)&&l(`anchor by ${n.name}`,r)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=X(e);n&&Z(n,e,t)&&l("anchor by text",n)}if(o.length>1){const r=_(e,t,o,n);r&&Z(r,e,t)&&l("anchor by combination",r)}return a},Q=e=>{const t=N(e)?.trim(),n=T(t);if(t&&h(t))return n?`contains(normalize-space(.),${S(n)})`:void 0;const r=A(e,t);if(r)return r;const a=t?S((e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(t).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim().split("/")[0].trim()):t;return a?a!==`'${t}'`?`contains(.,${a})`:/\s/.test(t)?`normalize-space(.)='${C(t)}'`:`normalize-space(.)='${t}'`:void 0},ee=(e,t,n)=>{const r=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";if(n=v(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return p(e,n,t).map(t=>I(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(h(n))return[];a=r.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 a?[a]:[]},te=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function ne(e,t){const n=function(e,t){const n=function(e){return"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.value?e.value:""}(e);return"android"===String(t).toLowerCase()?n.toLowerCase().replace(/@text="[^"]*"/g,'@text="?"').replace(/@text='[^']*'/g,"@text='?'").replace(/"[^"]*"/g,"?").replace(/'[^']*'/g,"?").replace(/\/\/android\.[a-z0-9._-]+/g,"//android_tag").replace(/\/\/\*/g,"//*"):n.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e,t);if(t?.toLowerCase().includes("android"))return`XPATH|shape:${n}`;const r=function(e){const t="string"==typeof e?e:e?.value||"";if(!t)return{axis:"none",attribute:"none",usesNormalize:!1};const n=t.toLowerCase(),r=n.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=r?.[1]??"none",o=n.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:o?.[1]??"none",usesNormalize:n.includes("normalize-space")}}(e);return["XPATH",`axis:${r.axis}`,`attr:${r.attribute}`,`normalize:${r.usesNormalize}`,`shape:${n}`].join("|")}function re(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function ae(e,t,n,r,a){const o=r?.getRootNode?.()??e,l=String(a).toLowerCase().includes("android"),s=String(a).toLowerCase().includes("ios"),i=l||s,c=e=>{try{return Array.from(o.querySelectorAll(e))}catch{return[]}},u=(e,t)=>{try{return Array.from(o.querySelectorAll("*")).filter(n=>n.getAttribute(e)===t)}catch{return[]}},f=(e,t)=>{try{return Array.from(o.querySelectorAll("*")).filter(n=>n.getAttribute(e)?.includes(t)??!1)}catch{return[]}};try{switch(t){case"id":return l?1===u("resource-id",n).length:s?1===u("name",n).length:1===c(`#${re(n)}`).length;case"accessibilityId":return l?1===u("content-desc",n).length:s?1===u("name",n).length:1===u("aria-label",n).length;case"className":return l?1===u("class",n).length:s?1===u("type",n).length:1===c(`.${n}`).length;case"tagName":return l?1===u("class",n).length:s?1===c("*").filter(e=>(e.getAttribute("type")||e.tagName)===n).length:1===c(n).length;case"name":return l?1===u("text",n).length||1===u("content-desc",n).length:s?1===u("name",n).length:1===c(`[name="${re(n)}"]`).length;case"linkText":return l?1===u("text",n).length:s?1===u("label",n).length:1===c("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return l?1===f("text",n).length:s?1===f("label",n).length:1===c("a").filter(e=>e.textContent?.includes(n)).length;case"cssSelector":return!i&&1===c(n).length;default:return!1}}catch{return!1}}const oe={getOptimalClassChain:function e(t,n,r){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const a=n.tagName,o=["name","label","value"];for(const e of o){const o=r.find(t=>t.name===e);if(!o)continue;let l=o.value;if(!l)continue;if(l=l.trim().replace(/\s+/g," "),x(l))continue;const s=`//${a}[@${e}="${l}"]`;let i=0;try{i=E(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(l);if(1===i)return c?`**/${a}[\`${e} CONTAINS "${l}"\`]`:`**/${a}[\`${e} == "${l}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===a).indexOf(n)+1;return c?`**/${a}[\`${e} CONTAINS "${l}"\`][${t}]`:`**/${a}[\`${e} == "${l}"\`][${t}]`}}let l=`/${a}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===a);if(e.length>1){l+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,r)+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 r=[],a=[];const o=["name","label","value","type"].map(e=>n.find(t=>t.name===e)).filter(e=>Boolean(e));for(let n of o){const o=n.value,l=n.name;if(0!==o.length&&(o&&!x(o))){r.push(`@${l}="${o}"`);const n=`//*[${r.join(" and ")}]`;let s;a.push(`${l} == "${o}"`);try{s=E(n,t,e)}catch(e){console.log(e);continue}if(1===s){if("type"===l&&1===a.length)continue;return a.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}};let le=[],se=[],ie=[],ce=new WeakMap,ue=new WeakMap;const fe=e=>e?[e.tagName,Array.from(e.attributes||[]).map(e=>`${e.name}=${e.value}`).join("|"),e.textContent||""].join("::"):"";var me;me=()=>{ce=new WeakMap,ue=new WeakMap,se=[]},a.add(me);const de={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},he=e=>de[e]||e,ge=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),pe=e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value))&&(t.add(e.value),!0))},$e=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const r=e[n];if(t){r===t&&(t=null);continue}if("'"===r||'"'===r){t=r;continue}if("["!==r)continue;const a=e.indexOf("]",n+1);if(-1===a)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,a)))return!0}return!1})(e.value)),ye=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ve=e=>{if(!(e&&e instanceof Element))return[];const t=[],n=Array.from(e.children||[]);for(;n.length;){const e=n.shift();e.classList?.contains("flntooltip")||(t.push(e),n.push(...Array.from(e.children||[])))}return t},xe=(e,t)=>{const n=[];let r="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;r;)r.classList?.contains("flntooltip")||n.push(r),r="previous"===t?r.previousElementSibling:r.nextElementSibling;return n},be=(e,t)=>{const n=[];for(let r=e;r?.parentElement;r=r.parentElement){let e="previous"===t?r.previousElementSibling:r.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>ve(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},Ne=e=>{if(!(e instanceof Element))return!0;const t=e.textContent?.trim();return!e.id&&!e.className&&0===e.attributes.length&&(!t||t.length>60)&&e.children.length>2},we=e=>{let t=0;e.id&&(t+=100),e.getAttribute("data-testid")&&(t+=90),e.className&&(t+=50),0===e.children.length&&(t+=30);const n=e.textContent?.trim();return n&&n.length<40&&(t+=40),t},Ee=(e,t,n,r,a,o,l)=>{const s=Q(n),i=s?`${J(n)}[${s}]`:J(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(Ne(e))continue;const m=[()=>K(e,r,a),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,a));for(const r of n){const n=r.value;if(!n)continue;const a=q(e,`@${r.name}`,n);a&&t.push({key:"contains",value:a});const o=j(e,`@${r.name}`,n);o&&t.push({key:"starts-with",value:o})}return t}];for(let a=0;a<m.length;a++){let s=m[a]();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 a=`${e.value}/${t}::${i}`;if(Z(a,n,r)){if(c.push({key:o,value:a}),c.length>=2)return c;if(c.length>=5)return c}}if(l&&a===m.length-1)for(const a of s){const l=E(a.value,e,r);for(let e=1;e<=Math.min(l,3);e++){const l=`(${a.value})[${e}]/${t}::${i}`;if(Z(l,n,r)){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(Ne(s))continue;const e=K(s,r,a);for(const a of e.slice(0,5)){const e=`${a.value}/${t}::${i}`;if(Z(e,n,r)){if(c.push({key:o,value:e}),c.length>=2)return c;if(c.length>=5)return c}}}}}return c},Se=(e,t)=>{const n=[];let r=e;for(;r&&n.length<t;)n.push(r),r=r.parentElement;return n},ke=(e,t)=>{for(let n=e.nextElementSibling;n;n=n.nextElementSibling)if(n===t)return"following-sibling";for(let n=e.previousElementSibling;n;n=n.previousElementSibling)if(n===t)return"preceding-sibling";return""},Ce=(e,t)=>{const n=[];for(let r=e;r&&r!==t;r=r.parentElement){const e=r.parentElement;if(!e)return"";n.push(`/parent::${J(e)}`)}return n.join("")},Ae=(e,t)=>{const n=J(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Re=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))};for(let n=e.parentElement,a=0;n&&a<4&&t.length<20;n=n.parentElement,a++){const e=[xe(n,"previous").slice(0,4),xe(n,"next").slice(0,4)];for(const t of e)for(const e of t){r(e);let t=0;for(const n of ve(e).sort((e,t)=>we(t)-we(e))){if(t++>=8)break;r(n)}}}return t.sort((e,t)=>we(t)-we(e)).slice(0,20)})(e),l=Se(e.parentElement,3);for(const s of o){const o=K(s,t,n).slice(0,2);if(!o.length)continue;const i=Se(s,3);for(const n of o)for(const o of i){const i=Ce(s,o);if(o===s||i)for(const s of l){if(!s||!s.contains(e))continue;const l=ke(o,s);if(!l)continue;const c=`/${l}::${J(s)}`;for(const o of Ae(s,e)){const l=`${n.value}${i}${c}${o}`;if(!a.has(l)&&(a.add(l),Z(l,e,t)&&(r.push({key:"chained axes fallback",value:l}),r.length>=2)))return r}}}}return r},Te=e=>{const t=J(e),n=e.textContent?.trim(),r=(e=>{const t=T(e);return t||(e||"").split(/[^a-zA-Z]+/).map(e=>e.trim()).filter(e=>e.length>2).pop()})(n),a=Q(e),o=[];return r&&r!==n&&o.push(`${t}[contains(text(),${S(r)})]`),a&&o.push(`${t}[${a}]`),o.push(t),Array.from(new Set(o))},Le=(e,t,n)=>{const r=N(e)?.trim(),a=[];if(r&&r.length>2&&r.length<40&&!h(r)){const t=`//${e.tagName}[.=${S(r)}]`;a.push({key:"anchor by text",value:t})}return[...a,...K(e,t,n)]},Oe=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))},a=e=>{for(const t of[e,...ve(e)]){const e=N(t)?.trim();e&&e.length<40&&!h(e)&&0===t.children.length&&r(t)}};for(let n=e.parentElement,o=0;n&&o<4&&t.length<30;n=n.parentElement,o++){const e=xe(n,"previous").reverse(),t=xe(n,"next");for(const n of[...e,...t])a(n),r(n)}return t.slice(0,30)})(e),l=Te(e);for(const s of o){const o=Le(s,t,n).slice(0,2);if(o.length)for(const n of o)for(const o of Se(s.parentElement,5)){if(!o.contains(e))continue;const s=`/ancestor::${J(o)}`;for(const o of l){const l=`${n.value}${s}/descendant::${o}`;if(!a.has(l)&&(a.add(l),Z(l,e,t)&&(r.push({key:"ancestor descendant bridge",value:l}),r.length>=1)))return r}}}return r},De=(e,t)=>{const n=[];for(let r=t;r&&r!==e;r=r.parentElement)n.unshift(J(r));if(!n.length)return"";const r=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${r}`},Pe=(e,t,n,r)=>{const a=new Set,o=[],l=(e,t)=>{t&&!a.has(t)&&(!r&&/\[\d+\]/.test(t)||(a.add(t),o.push({key:e,value:t})))};return K(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)||!h(t.value)||"class"===t.name)return;const n=(e=>{const t=(e.split(/\d/)[0]||"").replace(/[-_:\s.]+$/g,"").trim();return t.length>2&&/[a-zA-Z]/.test(t)?t:""})(t.value);if(!n)return;const r=q(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,r)}),o},Ie=(e,t,n,r)=>{const a=[];for(let t=e.parentElement;t;t=t.parentElement)a.push(t);const o=ve(e),l=xe(e,"previous"),s=xe(e,"next"),i=be(e,"previous"),c=be(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(s),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(l),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(a),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(a),axis:"descendant",key:"descendant"},{nodes:u(a),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(o,10),axis:"ancestor",key:"ancestor"},{nodes:u(o,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]],m=((e,t,n,r)=>{const a=[],o=new Set;for(let l=e.parentElement,s=0;l&&s<8;l=l.parentElement,s++){const s=De(l,e);if(!s)continue;const i=Pe(l,t,n,r);for(const n of i.slice(0,3)){const r=`${n.value}${s}`;if(!o.has(r)&&(o.add(r),Z(r,e,t)&&(a.push({key:"child chain",value:r}),a.length>=2)))return a}}return a})(e,t,n,r);if(m.length)return m;for(const a of f)for(const o of a){const a=Ee(o.nodes,o.axis,e,t,n,o.key,r);if(a.length>0)return a}const d=Oe(e,t,n);return d.length?d:Re(e,t,n)||[]},ze=(e,t,n,r,a)=>{const o=he(r);return"text"===o?ge(r,((e,t,n)=>{if(!ye(e))return[];if("text"===n){const n=X(e)||He(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?ge(r,((e,t,n,r)=>{const a=[],o=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,n)),l=ye(e),s="contains"===r?q:"startsWith"===r?j:"normalizeSpace"===r?Y:null;if(!s)return a;if("contains"===r&&l)for(const n of["text()","."]){const a=s(e,n,l);if(a&&1===E(a,e,t))return[{key:`xpath by ${r} text`,value:a}]}if(o.forEach(n=>{if("class"===n.name)return void p(e,n.value,t).forEach(t=>{const n=b(t,I(e),e.tagName.toLowerCase());n&&a.push({key:`xpath by ${r} class`,value:n})});const o=s(e,`@${n.name}`,n.value);o&&a.push({key:`xpath by ${r} ${n.name}`,value:o})}),"contains"===r&&a.length){const n=a.find(n=>1===E(n.value,e,t));return n?[n]:[]}if(l){const t=s(e,".",l);t&&a.push({key:`xpath by ${r} text`,value:t})}return a})(e,t,n,o)):["and","or"].includes(o)?ge(r,((e,t,n,r)=>{const a=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,n));if("and"===r){const r=_(e,t,a,n);return r?[{key:"xpath by combination",value:r}]:[]}if("or"===r&&a.length>=1){const t=H(e,a);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,n,o)):"axes"===o?ge(r,Ie(e,t,n,!1)):"index"===o?ge(r,((e,t)=>{const n=[],r=e.tagName.toLowerCase(),a=Array.from(t.querySelectorAll(r)).indexOf(e)+1;if(a<=0)return[];n.push({key:"xpath by index",value:`(//${r})[${a}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?ee(o,"id",o.id):ee(o,"class",o.className.toString());for(const a of t){const t=Array.from(o.querySelectorAll(r)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${a}//${r})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?ge(r,[{key:"xpath till tag",value:G(e,t)}]):[]},_e=(e,t,n,r,a,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=E(e,n,r);if(1===t)return e;if(t>1&&(se.length?t<se[0].count&&(se.pop(),se.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):se.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!le.length){const o=k(e,n,r,t);o&&1===E(o,n,r)&&le.push({key:"relative xpath by unique parent "+(a?"index":""),value:o})}}}return null},We=(e,t,r,a,o,l)=>{try{const s=[a?"target":"reference",l?"index":"no-index",o,fe(r)].join("::");let i=ce.get(e);if(i){if(i.has(s))return i.get(s)}else i=new Map,ce.set(e,i);const c=[];let u=e;for(;u&&1===u.nodeType;){const e=!1;for(const e of Array.from(u.attributes))if(P(e,u,a)){const n=v(e.name,e.nodeValue),a=e.name;for(const e of ee(u,a,n)){let n;try{n=_e(e,o,r,t,l,"parent")}catch(e){continue}if(n)return n}}if(u.textContent&&!u.textContent)if(!a||a&&!x(u.textContent)){let e;e=n.test(u.textContent)?I(u)?`//*[local-name()='${u.tagName}' and .=${S(w(u))}]`:`//${u.tagName||"*"}[.=${S(w(u))}]`:I(u)?`//*[local-name()='${u.tagName}' and normalize-space(.)=${S(w(u))}]`:`//${u.tagName||"*"}[normalize-space(.)=${S(w(u))}]`;const a=_e(e,o,r,t,l,"parent");if(a)return a}else{const e=[],n=[...new Set(w(u).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(n?.length)for(let t=0;t<n?.length;t++)n[t]&&C(n[t].trim())&&(a.test(n[t])?e.push(`contains(.,${S(n[t].trim()).trim()})`):e.push(`contains(.,${S(C(n[t])).trim()})`));if(e?.length){const n=I(u)?`//*[local-name()='${u.tagName}' and ${e.join(" and ")}]`:`//${u.tagName||"*"}[${e.join(" and ")}]`,a=_e(n,o,r,t,l,"parent");if(a)return a}}if(!e){const e=I(u)?`/*[local-name()='${u.tagName}']`:`/${u.tagName}`;c.unshift(e)}u=u.parentElement}const f=c.join("")+o;if(1===E(f,e,t))return i.set(s,f),f;i.set(s,null)}catch(e){return console.error(e),null}},Me=(e,t,n,r)=>{const a=[];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(P(n,o,r)){const r=v(n.name,n.nodeValue),l=n.name;for(const n of ee(o,l,r)){let r;try{r=E(n,o,t)}catch(e){continue}if(1===r){a.unshift(n),e=!0;break}}}if(e)break}if(!e&&o.textContent&&!n.textContent){const n=X(o);if(n){if(1===E(n,o,t)){e=!0,a.unshift(n);break}}}if(e)break;{const e=I(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;a.unshift(e)}o=o.parentElement}return a.join("")}catch(e){return console.log(e),null}},Xe=(e,t,n)=>{const r=fe(n);let a=ue.get(e);if(a){if(a.has(r))return a.get(r)}else a=new Map,ue.set(e,a);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(P(n,l,!0)){const r=v(n.name,n.nodeValue),a=n.name;for(const n of ee(l,a,r)){let r;try{r=E(n,l,t)}catch(e){continue}if(1===r){e=!0,o.push(n);break}}}if(e)break}if(!e&&l.textContent&&!n.textContent){const n=X(l);if(n){if(1===E(n,l,t)){e=!0,o.push(n);break}}}if(e)break;{const e=I(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 a.set(r,e),e}catch(e){return console.log(e),a.set(r,null),null}},Ye=(e,t,n,r)=>{try{const a=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==a;o=o.nextElementSibling)je(o,e,t,r,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==a;o=o.previousElementSibling)je(o,e,t,r,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},je=(e,t,n,r,a,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){const l=M(e,{name:t.name,value:t.value},o);for(let t of l){t+=`/${a}::${r}`;const o=E(t,e,n);if(1===o)return void le.push({key:`xpath by ${a}`,value:t});o>1&&(se.length?o<se[0].count&&(se.pop(),se.push({key:`relative xpath by ${a}`,value:t,count:o})):se.push({key:`relative xpath by ${a}`,value:t,count:o}))}}if(!o){let t;if(t=W(e,{name:"text",value:e.textContent},o),t){const r=E(t,e,n);if(1===r)return void le.push({key:`xpath by ${a}`,value:t});r>1&&(se.length?r<se[0].count&&(se.pop(),se.push({key:`relative xpath by ${a}`,value:t,count:r})):se.push({key:`relative xpath by ${a}`,value:t,count:r}))}}}catch(e){console.log(`${a} xpath-error`,e)}};const qe=(e,t,n,r,a)=>{try{o(t);let l,s,i=[];if(le=[],a)for(const t of a){const n=M(e,{name:t.name,value:t.value},r);for(const e of n)e&&i.push(e)}if(e.textContent){let t=W(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(!le.length){if(Ye(e,t,r,i[a]),!le.length&&(l||(l=Me(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=E(r,e,t);if(1===o)le.push({key:"relative xpath by relative parent",value:r});else if(o>1&&n){const a=k(r,e,t,o);a&&1===E(a,e,t)&&le.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!le.length&&(s||(s=Xe(e,t,e)),s&&(s.includes("@")||s.includes("text()")||s.includes(".=")))){const r=s.replace(/^\/+/,""),o=`/${i[a]}/${r}`,l=E(o,e,t);if(1===l)le.push({key:"relative xpath by relative child",value:o});else if(l>1&&n){const r=k(o,e,t,l);r&&1===E(r,e,t)&&le.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(1===le?.length&&le?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const r=He(e,t,n,!1);r&&le.unshift({key:"xpath by text"+(n?"index":""),value:r})}if(!le.length){let o=We(e.parentElement,t,e,r,i[a],n);o&&le.push({key:"xpath by unique parent",value:o})}}return le}catch(e){console.log(e)}},He=(e,t,n,r)=>{if(""!=(e.textContent??"").trim()){const a=N(e);if(a)return z(e,t,"text()",a,n,r)||z(e,t,".",a,n,r)}},Ve=(e,t,n,r,a)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&P(e,t,a)){const o=((e,t,n,r,a)=>{let o;if(o=e.name,P(e,t,a))return z(t,n,`@${o}`,e.value,r,a)})(e,t,n,r,a);o&&le.push({key:`xpath by ${e.name}${r?" index":""}`,value:o})}});const l=He(t,n,r,a);if(l&&le.push({key:"xpath by text"+(r?" index":""),value:l}),o.find(e=>["className","class"].includes(e.name))&&P(o?.find(e=>["className","class"].includes(e.name)),t,a)){let e=((e,t,n,r)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=v("class",a),a=a?.trim(),a&&P({name:"class",value:a},e,r))return z(e,t,"@class",a,n,r)})(t,n,r,a);e&&le.push({key:"xpath by class",value:e})}if(o.length>1){const e=_(t,n,o,a);e&&le.push({key:"xpath by combination",value:e})}if(!le.length){const r=function(e,t,n,r){const{tagName:a}=t,o=t.textContent.trim();if(!o)return;const l=C(o),s=T(l);if(h(l)&&!s)return;const i=h(l)?s:l,c=A(t,i);for(const s of e)if(P(s,t,r)){let e=v(s.name,s.nodeValue);const r=`//${a}[@${s.name}='${e}' and ${c||(h(l)?`contains(normalize-space(.),${S(i)})`:/\s/.test(o)?`normalize-space(.)=${S(i)}`:`text()=${S(i)}`)}]`;if(r&&1==E(r,t,n))return r}}(e,t,n,a);r&&le.push({key:"xpath by textAttribute",value:r})}}catch(e){console.log(e)}},Fe=(e,t,n,r,a=[],l=[],s)=>{if("Android"===s)return((e,t,n,r,a=[])=>{le=[],ie=[];const o={},l={},s=e,i=s?.ownerDocument||t,c=s?.tagName,{attributes:u}=s;if([...u].forEach(e=>{"resource-id"===e.name?o.id=e.value:"content-desc"===e.name?o.content=e.value:o[e.name]=e.value}),o?.id&&!x(o.id)){const e=`//*[@resource-id=${S(o.id)}]`;1===E(e,s,i)&&(ie.push({key:"id",value:[{key:"resource-id",value:o.id}],viewkey:"Id"}),l["resource-id"]=1)}if(o?.content&&!x(o.content)){const e=`//*[@content-desc=${S(o.content)}]`;1===E(e,s,i)&&(ie.push({key:"accessibilityId",value:[{key:"accessibilityID",value:o.content}],viewkey:"accessibilityId"}),l["content-desc"]=1)}if(o?.class&&!x(o.class)){const e=`//*[@class=${S(o.class)}]`;1===E(e,s,i)&&(ie.push({key:"className",viewkey:"className",value:[{key:"class",value:o.class}]}),l.class=1)}const f=(a.length>0?a:Array.from(u)).filter(e=>!l[e.name]);if(Ve(f,s,i,n,r),le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+c.length),1===E(t,e,i)&&le.push({key:`${le[n].key} regex`,value:t})}}le.length||qe(s,i,n,r,f);for(const e of le)ie.push({key:"xpath",viewkey:"xpath",value:[e]});return ie})(e,t,n,r,a);if("iOS"===s)return((e,t,n,r,a=[])=>{le=[],ie=[];const o={},l=e,s=l?.ownerDocument||t,i=l?.tagName,{attributes:c}=l,u=(e,t,n)=>{const r=l.getAttribute(n);if(!r||x(r))return;const a=`//*[@${n}=${S(r)}]`;1===E(a,l,s)&&(ie.push({key:e,viewkey:t,value:[{key:n,value:r}]}),o[n]=1)};u("accessibilityId","accessibilityId","name"),u("className","className","type");const f=a.length>0?a:Array.from(c),m=f.filter(e=>["label","name","value","type"].includes(e.name)),d=oe.getOptimalClassChain(s,l,m);d&&ie.push({viewkey:"Class Chain",key:"iOSClassChain",value:[{key:"classChain",value:d}]});const h=oe.getOptimalPredicateString(s,l,m);h&&ie.push({viewkey:"Predicate String",key:"iOSNsPredicateString",value:[{key:"predicateString",value:h}]});const g=f.filter(e=>("name"===e.name||!o[e.name])&&["name","label","value"].includes(e.name));if(Ve(g,l,s,n,r),le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+i.length),1===E(t,e,s)&&le.push({key:`${le[n].key} regex`,value:t})}}le.length||qe(l,s,n,r,g);for(const e of le)ie.push({key:"xpath",viewkey:"xpath",value:[e]});return ie})(e,t,n,r,a);le=[],console.log(e);const i=e,c=i?.getRootNode?.(),u=c?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,f=u?c:i?.ownerDocument||t;o(f);const m=i.tagName,{attributes:d}=i,h=a.length>0?a:Array.from(d);if(Ve(h,i,f,n,r),l.length){const e=n||((e=[])=>e.some(e=>"index"===he(e)))(l),t=l.flatMap(e=>ze(i,f,r,e));return le=pe(t.filter(e=>1===E(e.value,i,f))),$e(le,e)}if(le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+m.length);1===E(t,e,f)&&le.push({key:`${le[n].key} regex`,value:t})}}return le.length||u||(le=Ie(i,f,r,n)),$e(pe(le),n)},Be=["data-testid","data-test-id","data-test","data-cy","data-qa","name","aria-label","aria-labelledby","placeholder","title","alt","role"],Ge=new Set(["id","class","style"]),Ue=(e,t)=>{const n=t?.ownerDocument?.defaultView?.CSS??globalThis.CSS;return n?.escape?n.escape(e):String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")},Ze=e=>{if(!e)return!1;const t=e.ownerDocument?.defaultView;return Boolean(t&&e instanceof t.Element)},Je=e=>{const t=e.tagName.toLowerCase();return"style"===t||"script"===t},Ke=e=>{const t=e.trim();return Boolean(t)&&t.length<=120&&!/^\d+$/.test(t)},Qe=(e,t,n)=>{try{const r=n.querySelectorAll(e);return 1===r.length&&r[0]===t}catch{return!1}},et=(e,t,n)=>{n&&!e.some(e=>e.value===n)&&e.push({key:t,value:n})},tt=(e,t="single")=>{const n=[],r=e.getRootNode();try{const a=nt(e);if(a&&Qe(a,e,r)&&(et(n,"cssSelector by id",a),"single"===t))return n;const o=at(e);if(o&&(et(n,"cssSelector by attribute",o),"single"===t))return n;const l=ot(e);if(l&&Qe(l,e,r)&&(et(n,"cssSelector by class",l),"single"===t))return n;const s=it(e);if(s&&Qe(s,e,r)&&(et(n,"cssSelector by stable parent",s),"single"===t))return n}catch(e){console.error(e)}return n},nt=e=>{if(!Ze(e)||Je(e))return;const t=e.getAttributeNode("id");return t&&(P(t,e,!0)||((e,t)=>{const n=t.value.trim();return!!Ke(n)&&(!i.some(t=>t.doc===e.ownerDocument&&t.element===e&&"id"===t.attributeName)&&!/\d{4,}/.test(n))})(e,t))?`#${Ue(e.id,e)}`:void 0};function rt(e,t=!1){const n=Array.from(e.attributes).filter(n=>{const r=n.name.toLowerCase();return!Ge.has(r)&&(!(t&&!Be.includes(r))&&(Ke(n.value)&&P(n,e,!0)))});return n.sort((e,t)=>{const n=Be.indexOf(e.name.toLowerCase()),r=Be.indexOf(t.name.toLowerCase());return(-1===n?999:n)-(-1===r?999:r)}),n.map(e=>{return`[${e.name}="${t=e.value.trim(),String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const at=e=>{if(!Ze(e)||Je(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase(),r=rt(e);for(const a of r){if(Qe(a,e,t))return a;const r=`${n}${a}`;if(Qe(r,e,t))return r}},ot=e=>{if(!Ze(e)||Je(e))return;const t=lt(e);if(!t)return;const n=e.getRootNode(),r=`${e.tagName.toLowerCase()}${t}`;return Qe(t,e,n)?t:Qe(r,e,n)?r:void 0},lt=e=>{if("string"!=typeof e.className||!e.className||i?.find(t=>t.element===e&&"class"===t.attributeName))return;const t=$(e,e.className).filter(Ke);return t.length?t.slice(0,3).map(t=>`.${Ue(t,e)}`).join(""):void 0},st=(e,t={})=>{if(!Ze(e)||Je(e))return[];const n=[],r=e.tagName.toLowerCase(),a=nt(e);a&&n.push(a);for(const a of rt(e,t.preferredAttributesOnly))n.push(a),t.includeTag&&n.push(`${r}${a}`);const o=lt(e);return o&&(n.push(o),t.includeTag&&n.push(`${r}${o}`)),Array.from(new Set(n))},it=e=>{if(!Ze(e)||Je(e))return;const t=e.getRootNode(),n=st(e,{includeTag:!0,preferredAttributesOnly:!1});let r=e.parentElement;for(;r&&Ze(r)&&!Je(r);){const a=st(r,{includeTag:!0,preferredAttributesOnly:!0});for(const o of a)if(Qe(o,r,t))for(const r of n){const n=`${o} ${r}`;if(Qe(n,e,t))return n;const a=`${o} > ${r}`;if(Qe(a,e,t))return a}r=r.parentElement}},ct=(e,t,n)=>{const r=te(e);if(vt(t,r)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(r)){const e=t.evaluate(r,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},ut=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return dt(e.body,t)},ft=(e,t,n)=>ut(t,e)===n,mt=e=>e.name?.toLowerCase().includes("cssselector")??!1,dt=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:r}=n[e];if(r){const e=dt(r,t);if(e)return e;if(r&&!t.includes("dynamic"))return r.querySelector(t)}}}catch(e){console.log(e)}return null},ht=(e,t)=>{if(!e)return null;const n=String(t).toLowerCase();return n.includes("android")?e.getAttribute("resource-id")||e.getAttribute("resourceId")||null:n.includes("ios")?e.getAttribute("name")||null:e.id||null},gt=(e,t)=>{const n=String(t).toLowerCase();return n.includes("android")?e.getAttribute("class")||e.getAttribute("className")||null:n.includes("ios")?e.getAttribute("type")||null:e.className||null},pt=e=>e.textContent?.trim()||null,$t=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},yt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function vt(e,t){try{const n=e.defaultView?.XPathResult?.FIRST_ORDERED_NODE_TYPE??("undefined"!=typeof XPathResult?XPathResult.FIRST_ORDERED_NODE_TYPE:9),r=e.defaultView?.XPathEvaluator?new e.defaultView.XPathEvaluator:"undefined"!=typeof XPathEvaluator?new XPathEvaluator:null;return(r?r.evaluate(t,e,null,n,null):e.evaluate(t,e,null,n,null)).singleNodeValue}catch(e){return console.error("Invalid XPath:",t,e),null}}function xt(e,t,n){if(e.includes(t)){const r=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(r,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let r;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(r=e,r):(console.error("Complete Locator is Invalid:",e),r=e,r)}console.error("Source Locator Not Found:",r)}}return null}const bt=(e,t,n)=>{o(t);const r=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");r&&r.forEach(e=>{e.remove()});const a=new Set;let l=[];function s(e,t={}){const n=e?.value,r=t.value??e?.value,o={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;o.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(o.name,n,r),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(o)}const i=(e,t,n)=>{for(const r of Array.from(e.querySelectorAll("*")))if(r.getAttribute(t)===n)return r;return null},c=e=>String(e).toLowerCase().includes("android"),u=e=>c(e)||String(e).toLowerCase().includes("ios"),f=e=>String(e).toLowerCase().includes("ios"),m=e=>{switch(String(e||"").trim().toLowerCase().replace(/^-/,"").replace(/[\s_-]+/g,"")){case"id":return"id";case"name":return"name";case"xpath":return"xpath";case"classname":return"className";case"accessibilityid":return"accessibilityId";case"iospredicatestring":case"iosnspredicatestring":return"iosPredicateString";case"iosclasschain":return"iosClassChain";default:return String(e||"")}},d=t=>e.locators.find(e=>m(e.name)===t),h=(e,t)=>"type"===t.toLowerCase()?e.getAttribute("type")||e.tagName||"":e.getAttribute(t)||"",g=(e,t)=>{const n=t.trim().replace(/^\((.*)\)$/s,"$1");if(/^(TRUEPREDICATE|1\s*==\s*1)$/i.test(n))return!0;const{clauses:r,operators:a}=(e=>{const t=[],n=[];let r="",a=0;for(let o=0;o<e.length;o++){const l=e[o];if(('"'===l||"'"===l)&&"\\"!==e[o-1]){r=r===l?"":r||l;continue}if(r)continue;const s=e.slice(o).match(/^\s+(AND|OR)\s+/i);s&&(t.push(e.slice(a,o).trim()),n.push(s[1].toUpperCase()),o+=s[0].length-1,a=o+1)}return t.push(e.slice(a).trim()),{clauses:t,operators:n}})(n),o=r.map(t=>{const n=t.match(/^([\w-]+)\s*(==|=|!=|CONTAINS|BEGINSWITH|ENDSWITH|MATCHES)(\[[cd]+\])?\s*(?:"((?:\\.|[^"])*)"|'((?:\\.|[^'])*)'|([^\s]+))$/i);if(!n)return!1;const[,r,a,o,l,s,i]=n,c=(l??s??i??"").replace(/\\([\\"'])/g,"$1");let u=h(e,r),f=c;switch("1"===f&&"true"===u.toLowerCase()?u="1":"0"===f&&"false"===u.toLowerCase()&&(u="0"),o?.toLowerCase().includes("c")&&(u=u.toLocaleLowerCase(),f=f.toLocaleLowerCase()),a.toUpperCase()){case"=":case"==":return u===f;case"!=":return u!==f;case"CONTAINS":return u.includes(f);case"BEGINSWITH":return u.startsWith(f);case"ENDSWITH":return u.endsWith(f);case"MATCHES":try{return new RegExp(f).test(u)}catch{return!1}default:return!1}});let l=o[0]??!1;return a.forEach((e,t)=>{l="AND"===e?l&&o[t+1]:l||o[t+1]}),l},p=(e,t)=>{const n=(e=>{const t=[];let n="",r="",a="",o=0;for(let l=0;l<e.length;l++){const s=e[l];'"'!==s&&"'"!==s||"\\"===e[l-1]?r||"`"!==s&&"$"!==s?r||a||"["!==s?r||a||"]"!==s||o--:o++:a=a===s?"":a||s:r=r===s?"":r||s,"/"!==s||r||a||0!==o?n+=s:(n&&t.push(n),n="")}return n&&t.push(n),t.filter(Boolean)})(t.trim());let r=[e],a=!1;for(const e of n){if("**"===e){a=!0;continue}const t=e.match(/^([^[]+)/)?.[1]?.trim()||"*",n=Array.from(e.matchAll(/\[(?:`([^`]*)`|\$([^$]*)\$)\]/g)).map(e=>e[1]??e[2]),o=e.match(/\[(-?\d+)\]\s*$/),l=[];for(const e of r){const r=a?Array.from(e.querySelectorAll("*")):9===e.nodeType?[e.documentElement]:Array.from(e.children);l.push(...r.filter(e=>{const r=h(e,"type");return("*"===t||r===t)&&n.every(t=>g(e,t))}))}if(o){const e=Number(o[1]),t=e<0?l.length+e:e-1;r=l[t]?[l[t]]:[]}else r=l;if(a=!1,!r.length)return null}return r[0]||null},$=(e,t)=>("xpath"===m(e.name)||e.name?.toLowerCase().includes("xpath")||t.startsWith("//"))&&!String(e.type||"").includes("dynamic"),y=e=>e.flatMap(e=>e?Array.isArray(e.value)?"xpath"!==e.key&&"xpath"!==e.viewkey?[]:e.value:[e]:[]).filter(e=>"string"==typeof e?.value&&e.value.trim().startsWith("//")),v=(e,t,n)=>{const r=m(t.name);if($(t,n))return vt(e,te(n));if("id"===r||"accessibilityId"!==r&&t.name.includes("id")||n.startsWith("#")){const t=n.startsWith("#")?n.slice(1):n;return i(e,"resource-id",t)||i(e,"content-desc",t)}return"accessibilityId"===r?i(e,"content-desc",n):"className"===r||t.name.includes("className")||n.startsWith(".")?e.querySelector(`[class="${n}"]`)||null:"name"===r?i(e,"text",n)||i(e,"content-desc",n):"tagName"===r?e.querySelector(`[class="${n}"]`)||null:"linkText"===r?i(e,"text",n):"partialLinkText"===r&&Array.from(e.querySelectorAll("*")).find(e=>e.getAttribute("text")?.includes(n))||null},b=(e,t,n)=>{const r=m(t.name);return $(t,n)?vt(e,te(n)):"id"===r||"accessibilityId"===r||"name"===r?i(e,"name",n):"className"===r?i(e,"type",n):"iosPredicateString"===r?((e,t)=>Array.from(e.querySelectorAll("*")).find(e=>g(e,t))||null)(e,n):"iosClassChain"===r?p(e,n):null},N=(e,t,n)=>{const r=m(t.name);if($(t,n))return vt(e,te(n));if(mt(t))return ut(e,n);if("id"===r||t.name.includes("id")||n.startsWith("#")){const t=n.startsWith("#")?n.slice(1):n;return e.querySelector("#"+re(t))}return"className"===r||t.name.includes("className")||n.startsWith(".")?e.querySelector(n):"name"===r?e.querySelector(`[name="${re(n)}"]`):"tagName"===r?e.querySelector(n):"linkText"===r?Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null:"partialLinkText"===r&&Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null};function w(e,t,r){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const o=c(n)?v(a,t,r):f(n)?b(a,t,r):N(a,t,r);if(o)return o}catch{continue}return null}const E=(e,t,n,r)=>{if(null==e)return null;"string"!=typeof e&&(e=String(e));let a=e.trim();if(!a||"null"===a.toLowerCase())return null;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());const o=String(r).toLowerCase().includes("android"),l=/^[a-zA-Z0-9._]+:id\/[a-zA-Z0-9_]+$/.test(a);return"xpath"!==t||"Y"!==n||a.startsWith("//")||o&&l?!a||/^['"]{2}$/.test(a)?null:a:null};e:for(const r of e.locators)try{String(r.isRecorded||"");const o=e.locators.filter(e=>"N"===e.isRecorded);if(o.length>0)for(const e of o)s(e);const i=String(r.value||r.type||"");if(i.includes("dynamic")||i.match("dynamic")||i.includes("{")||i.includes("}")){s(r);continue}if(e.isShared.includes("Y"))break e;try{let o=null;const i=r.value.split(">>>");for(const e of i){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(o=c(n)?v(t,r,a):f(n)?b(t,r,a):N(t,r,a),o||(o=w(t,r,a)),o||u(n)||!t.body||(o=dt(t.body,a)),!o){console.error("Element not found at:",a);break}}const h=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(o){const r=e.locators.filter(e=>"xpath"===m(e.name)&&e.value),a=e.locators.filter(e=>mt(e)&&e.value);for(const e of r)ct(e.value,t,o)&&s(e,{isSelfHealed:null});for(const e of a)ft(e.value,t,o)&&s(e,{isSelfHealed:null});const i=l.filter(e=>"xpath"===m(e.name)&&e.value),g=new Set(i.map(e=>ne(e.value,n))),p=[],$=ht(o,n);if(!f(n)&&$&&!h("id",$)&&!x($)){const e=d("id");ae(t,"id",$,o,n)&&(p.push(c(n)?"resource-id":"id"),s(e,{name:"id",type:"static",isRecorded:"Y",value:$}))}const v=c(n)?o.getAttribute("content-desc"):f(n)?o.getAttribute("name"):o.getAttribute("aria-label"),b=d("accessibilityId");if(!v||f(n)&&!b||h("accessibilityId",v)||x(v)||ae(t,"accessibilityId",v,o,n)&&(p.push(c(n)?"content-desc":f(n)?"name":"aria-label"),s(b,{name:b?.name||"accessibilityId",type:"static",isRecorded:"Y",value:v})),!u(n)){const e=o.tagName;if(e&&!h("tagName",e)){const r=d("tagName");ae(t,"tagName",e,o,n)&&(p.push("tagName"),s(r,{name:"tagName",type:"static",isRecorded:"Y",value:e}))}}const N=pt(o);if(N&&!x(N)){const e=d("linkText");ae(t,"linkText",N,o,n)&&(p.push(c(n)?"text":"linkText"),s(e,{name:c(n)?"name":"linkText",type:"static",isRecorded:"Y",value:N}))}const w=$t(o);if(!f(n)&&w&&!h("name",w)&&!x(w)){const e=d("name");ae(t,"name",w,o,n)&&(p.push("name"),s(e,{name:"name",type:"static",isRecorded:"Y",value:w}))}const S=gt(o,n),k=d("className");if(!S||f(n)&&!k||""===S.trim()||S.includes(" ")||h("className",S)||x(S)||ae(t,"className",S,o,n)&&(p.push(f(n)?"type":"className"),s(k,{name:k?.name||(f(n)?"class name":"className"),type:"static",isRecorded:"Y",value:S})),f(n)){const e=Array.from(o.attributes),n=oe.getOptimalPredicateString(t,o,e),r=d("iosPredicateString");r&&n&&!h(r.name,n)&&s(r,{name:r.name,type:"static",isRecorded:"Y",value:n});const a=oe.getOptimalClassChain(t,o,e),l=d("iosClassChain");l&&a&&!h(l.name,a)&&s(l,{name:l.name,type:"static",isRecorded:"Y",value:a})}u(n)||tt(o,"single").forEach(e=>{e.value&&!h("cssSelector",e.value)&&s(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const C=Array.from(o.attributes).filter(e=>!p.includes(e.name)||f(n)&&"name"===e.name);let A=[];try{A=Fe(o,t,!1,!0,C,[],n)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==A?.length){const e=r.filter(e=>!ct(e.value,t,o));let a=0;for(const t of e){if(a>=e.length)break;const r=ne(t.value,n);if(g.has(r))continue;const o=y(A).find(e=>"string"==typeof e.value&&ne(e.value,n)===r);o?.value&&(s(t,{name:"xpath",value:o.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),g.add(r),a++)}if(a<e.length){console.log("xpathResults =",JSON.stringify(A,null,2));for(const t of A){const o=y([t]);for(const t of o){if(a>=e.length)break;const o="string"==typeof t.value?t.value:"";if(!o)continue;const l=ne(o,n);if(g.has(l))continue;const i=e[a]??r[a];i&&(s(i,{name:"xpath",value:o,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),g.add(l),a++)}}}}for(const n of e.locators)try{for(const r of e.locators)if(r.value)for(const e of yt)if(r.value.includes(e)){const a=xt(r.value,e,t);if(a){s(r,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(!f(n)&&l.length<5){const e=[{name:"id",value:ht(o,n)},{name:"name",value:$t(o)},{name:"className",value:gt(o,n)},...u(n)?[]:[{name:"tagName",value:o.tagName}],{name:c(n)?"name":"linkText",value:pt(o)}];for(const r of e){if(l.length>4)break;const{name:e,value:a}=r;a&&(x(a)||h(e,a)||"className"===e&&a.includes(" ")||ae(t,e,a,o,n)&&s(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&!u(n)&&tt(o,"multiple").forEach(e=>{l.length>4||e.value&&(h("cssSelector",e.value)||ae(t,"cssSelector",e.value,o,n)&&s(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const R=l.map(e=>({...e,value:E(e.value,e.name,e.isRecorded,n)})),T=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:R.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 T}}catch(e){console.error("Error processing locator:",r,e);continue}}catch(e){console.error("Error processing locator:",r,e);continue}return null};async function Nt(){return{fromHTML:async(n,r)=>{let a;if(["android","ios"].some(e=>String(r).toLowerCase().includes(e))){const t=new e(""),o=((e,t,n)=>{if(!n)return null;const r=(new n).parseFromString(e,t);if(r.querySelector("parsererror"))throw new Error("Invalid XML");return r})(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),"text/xml",t.window.DOMParser);if(!o)throw new Error(`Failed to parse ${r} XML`);a=o,global.document=o,global.Node=t.window.Node,global.Element=t.window.Element,global.HTMLElement=t.window.HTMLElement,global.XPathResult=t.window.XPathResult,global.SVGElement=t.window.SVGElement,global.XPathEvaluator=t.window.XPathEvaluator}else{const r=new t,o=new e(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"dangerously",resources:"usable",virtualConsole:r}),{window:l}=o;a=l.document,global.document=l.document,global.Node=l.Node,global.Element=l.Element,global.HTMLElement=l.HTMLElement,global.SVGElement=l.SVGElement;const s=l.CSS??{};s.escape||(s.escape=e=>String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")),global.CSS=s,global.XPathResult=l.XPathResult,global.XPathEvaluator=l.XPathEvaluator}return{autoHeal:async e=>bt(e,a,r)}}}}export{Nt as default};
1
+ import{JSDOM as e,VirtualConsole as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i;let r=new WeakMap;const a=new Set,o=e=>{if(!e)return r=new WeakMap,s=new WeakMap,void a.forEach(e=>e(null));(e=>{const t=[],n=e=>{e&&!t.includes(e)&&t.push(e)};n(e);const r=e.getRootNode?.();return 9!==r?.nodeType&&11!==r?.nodeType||n(r),n(9===e.nodeType?e:e.ownerDocument),t})(e).forEach(e=>{r.delete(e)}),s=new WeakMap,a.forEach(t=>t(e))},l=(e,t)=>{const{owner:n,contextNode:a}=(e=>{const t=9===e.nodeType?e:e.ownerDocument||document;return{owner:t,contextNode:1===e.nodeType||9===e.nodeType||11===e.nodeType?e:t}})(t);let o=r.get(a);o||(o=new Map,r.set(a,o));const l=o.get(e);if(l)return l;const s=n.evaluate(e,a,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null),i={first:s.iterateNext(),second:s.iterateNext()};return o.set(e,i),i};let s=new WeakMap,i=[];const c=new WeakMap,u=new Set(["flntooltip","flntooltip-bottom","fln-shield"]),f=new Set(["marked-element-temp","marked-element","mark-successfully","removePointers","element-style-reset",...u]),m=/^(?:(?:ng|ion)-(?:pristine|dirty|valid|invalid|touched|untouched|pending|submitted|focused)|oj-(?:focus(?:-highlight)?|hover|active|selected|enabled|disabled)|(?:item-)?has-(?:focus|value)|ng-star-inserted|hydrated|md|ios)$/,d=e=>(e||"").split(/\s+/).map(e=>e.trim()).filter(e=>e&&!f.has(e)).sort(),h=e=>/\d/.test(e||""),g=e=>m.test(e),p=(e,t,n,r=!1)=>{const a=d(t),o=$(e,t,r);return o.length?1===a.length&&1===o.length?[`@class=${S(o[0])}`]:o.map(t=>{const r=b(`contains(@class,${S(t)})`,I(e),e.tagName.toLowerCase());return{token:t,count:V(r,e,n)}}).sort((e,t)=>e.token.length!==t.token.length?e.token.length-t.token.length:e.count-t.count).map(({token:e})=>`contains(@class,${S(e)})`):[]},$=(e,t,n=!1)=>{const r=c.get(e);return d(t).filter(e=>!(r?.has(e)||g(e)||!n&&h(e)))},y=new Set(["data-testid","data-test-id","data-test","data-cy","testid"]),v=(e,t)=>t?"class"===e||"className"===e?d(t).join(" "):t.replace("removePointers","").trim():"",x=e=>/\d/.test(e),b=(e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`,N=e=>{const t=e?.textContent;return t},w=e=>e?.childNodes[0]?.nodeValue||"",E=(e,t,n,r=!1)=>{try{if(L(n)){const{owner:a,contextNode:o,cloneElement:l,cloneElements:s}=O(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:a,second:o}=l(e,n);if(!a)return 0;if(!o)return a===t?1:0;if(r&&Array.isArray(t)){let r=0;if(t.includes(a)&&r++,t.includes(o)&&r++,2===r)return 2;const l=(9===n.nodeType?n:n.ownerDocument).evaluate(e,n,null,XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);let s;for(;s=l.iterateNext();)if(t.includes(s)&&(r++,2===r))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}'`},k=(e,t,n,r)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let o=0;if(r){if(1===E(`${e}[${r}]`,t,n))return`${e}[${r}]`;if(1===E(`(${e})[${r}]`,t,n))return`(${e})[${r}]`}const l=a.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let s=null;for(;s=l.iterateNext();)if(o++,s.isSameNode(t))return 1===E(`${e}[${o}]`,t,n)?`${e}[${o}]`:1===E(`(${e})[${o}]`,t,n)?`(${e})[${o}]`:void 0}catch(e){console.log(e)}},C=e=>e?e.replace(/\s\s+/g," ").trim():e,A=(e,t)=>{const n=C((t||"").trim());if(!e.children.length||n.length<=50)return"";const r=n.split(/\s+/).slice(0,3).join(" ");return r.length>2?`contains(normalize-space(.),${S(r)})`:""},R=e=>{const t=C((e||"").trim());if(!t||!h(t))return{prefix:t,fragment:t};const n=t.split(/[0-9]/)[0].replace(/[₹$€£¥₫₽₩₦₱₲₴₵₡₭₮₺฿៛]+/g,"").trim(),r=n.split(/[^a-zA-Z]+/).map(e=>C(e).trim()).filter(e=>e.length>2&&/[a-zA-Z]/.test(e)).join(" ").trim();return{prefix:n.length>2&&/[a-zA-Z]/.test(n)?n:"",fragment:r.length>2?r:""}},T=e=>R(e).fragment,L=e=>e?.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&"host"in e,O=(e,t)=>{const n=e.ownerDocument.implementation.createHTMLDocument("shadow-xpath"),r=n.createElement("div");r.innerHTML=e.innerHTML,n.body.appendChild(r);const a=t=>{if(!(t&&t instanceof e.ownerDocument.defaultView.Element))return null;const n=((e,t)=>{const n=[];let r=t;for(;r&&r.parentElement;){const e=r.parentElement;n.unshift(Array.from(e.children).indexOf(r)),r=e}return r&&r.parentNode===e?(n.unshift(Array.from(e.children).indexOf(r)),n):null})(e,t);return n?((e,t)=>{let n=e;for(const e of t){const t=n.children.item(e);if(!t)return null;n=t}return n})(r,n):null},o=Array.isArray(t)?t.map(e=>a(e)).filter(Boolean):[],l=Array.isArray(t)?null:a(t??null);return{owner:n,contextNode:r,cloneElement:l,cloneElements:o}},D=(e,t,n)=>{if("class"===e.name&&e.value.split(/\s+/).some(e=>f.has(e))){i.some(e=>e.doc===t.ownerDocument&&e.element===t&&"class"===e.attributeName)||i.push({url:t.baseURI,attributeName:"class",element:t,doc:t.ownerDocument})}const r=v(e.name,e.value);if(!r||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip","flutter-highlight-overlay","element-style-reset"].some(e=>e===r))return!1;if(["style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;if("class"===e.name||"className"===e.name){const n=c.get(t);return d(e.value).filter(e=>!n?.has(e)&&!g(e)&&!h(e)).length>0}const a=i?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!a&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(o=e.name,l=r,(!y.has(o.toLowerCase())||!(e=>/(?:^|[-_:])\d{4,}(?:$|[-_:])/.test(e))(l))&&("class"===e.name||!h(r)))));var o,l},P=(e,t,n)=>{const r=((e,t)=>[t?"target":"reference",e.name,String(e.value)].join("::"))(e,n);let a=s.get(t);if(a){if(a.has(r))return a.get(r)}else a=new Map,s.set(t,a);const o=D(e,t);return a.set(r,o),o},I=e=>e instanceof SVGElement,z=(e,t,r,a,o,l)=>{if(a){const{tagName:s}=e;let i,c="";const u=[];let f;const m=r.startsWith("@"),d="."===r||"text()"===r,g=d?".":r,$=d&&/\s/.test(a.trim()),y=d?T(a):a,v=d&&h(a)?y:a,N=d?A(e,v):"";if("@class"===r){for(const n of p(e,a,t)){if(f=b(n,I(e),e.tagName.toLowerCase()),i=E(f,e,t),1===i&&!o)return f;{const n=k(f,e,t,i);if(n)return n}}return}if(d&&h(a)&&!y)return;if(a&&(!m||!x(a))){if(f=N?b(N,I(e),e.tagName.toLowerCase()):$?b(`normalize-space(${g})=${S(C(v)).trim()}`,I(e),e.tagName.toLowerCase()):n.test(a)?`//${s}[${r}=${S(v)}]`:b(`normalize-space(${r})=${S(C(v)).trim()}`,I(e),e.tagName.toLowerCase()),i=E(f,e,t),1===i&&!o)return f;{const n=k(f,e,t,i);if(n)return n}}if(m&&h(a))return;if(a&&l){const l=a.split(" ");if(l?.length)if(1===l.length){const u=[...new Set(l[0].match(/([^0-9]+)/g))];if(u?.length>=1&&u[0]&&C(u[0].trim())?.length>1&&a.startsWith(u[0])&&(c=n.test(u[0])?`starts-with(${r},${S(u[0]).trim()})`:`starts-with(${r},${S(C(u[0])).trim()})`),u?.length>1&&u[u.length-1]&&C(u[u.length-1].trim())?.length>1&&a.endsWith(u[u.length-1])&&(c=n.test(u[u.length-1])?`ends-with(${r},${S(u[u.length-1]).trim()})`:`ends-with(${r},${S(C(u[u.length-1])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),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]&&C(d[0].trim())?.length&&a.startsWith(d[0])&&(c=n.test(d[0])?`starts-with(${r},${S(d[0]).trim()})`:`starts-with(${r},${S(C(d[0])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),1===i&&!o))return f;const h=l.slice(u,l.length-1).join(" ");if(d=[...new Set(h.match(/([^0-9]+)/g))],d?.length&&d[0]&&C(d[0].trim())?.length>3&&a.endsWith(d[0])&&(c=n.test(d[0])?`ends-with(${r},${S(d[0]).trim()})`:`ends-with(${r},${S(C(d[0])).trim()})`),c?.length&&(f=I(e)?`//*[local-name()='${s}' and ${c}]`:`//${s}[${c}]`,i=E(f,e,t),1===i&&!o))return f}}if(a&&l&&x(a)){const l=[...new Set(a.match(/([^0-9]+)/g))];if(l?.length)for(let e=0;e<l?.length;e++)l[e]&&C(l[e].trim())?.length>1&&(n.test(l[e])?u.push(`contains(${r},${S(l[e].trim()).trim()})`):u.push(`contains(${r},${S(C(l[e])).trim()})`));if(u?.length&&(f=I(e)?`//*[local-name()='${s}' and ${u.join(" and ")}]`:`//${s}[${u.join(" and ")}]`,i=E(f,e,t),1===i&&!o))return f}if(f=I(e)?`//*[local-name()='${s}' and text()]`:`//${s}[text()]`,i=E(f,e,t),1===i&&!o)return f}},_=(e,t,r,a)=>{try{const o=r.filter(t=>P(t,e,a)),l=r=>{const a=v(r.name,r.nodeValue);return a?"class"===r.name?p(e,a,t):h(a)?[]:n.test(a)?[`@${r.name}="${a}"`]:[`normalize-space(@${r.name})="${a}"`]:[]},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 t=C(N(e)?.trim()||""),r=T(t);if(h(t))return r?[`contains(normalize-space(.),${S(r)})`]:[];if(!t||t.length>80||/^\d+$/.test(t)){const n=A(e,t);return n?[n]:[]}const a=new Set,o=A(e,t);return o?(a.add(o),Array.from(a)):(n.test(t)&&t.length<=40&&!t.includes(" ")&&a.add(`text()=${S(t)}`),t.includes(" ")&&a.add(`normalize-space(.)=${S(C(t))}`),a.add(`contains(text(),${S(t)})`),Array.from(a))},u=(e,t)=>{const n=[],r=(a,o)=>{if(o.length!==t)for(let t=a;t<e.length;t++)o.push(e[t]),r(t+1,o),o.pop();else n.push([...o])};return r(0,[]),n},f=t=>I(e)?`//*[local-name()='${e.tagName}' and ${t.join(" and ")}]`:`//${e.tagName}[${t.join(" and ")}]`,m=(()=>{if(!(o.length<2))for(let n=2;n<=o.length;n++){const r=u(o,n);for(const n of r){const r=i(n);for(const n of r){if(n.length<2)continue;const r=f(n);let a;try{a=E(r,e,t)}catch{continue}if(1===a)return r}}}})();if(m)return m;const d=c();if(!d.length||!o.length)return;for(let n=1;n<=o.length;n++){const r=u(o,n);for(const n of r){const r=i(n);for(const n of r)if(n.length)for(const r of d){const a=[...n,r],o=f(a);try{if(1===E(o,e,t))return o}catch{continue}}}}}catch(e){console.log(`XPath generation error: ${JSON.stringify(e,null,2)}`)}},W=(e,t,n)=>M(e,t,n)[0]||"",M=(e,t,r)=>{let a=I(e),o="";if(P(t,e,r)){let r=v(t.name,t.value);const l=t.name;if("class"===l){const t=e.getRootNode?.()??e.ownerDocument;return p(e,r,t).map(t=>a?`*[local-name()='${e.tagName}' and ${t}]`:`${e.tagName||"*"}[${t}]`)}if(h(r))return[];o=n.test(r)?a?`*[local-name()='${e.tagName}' and @${l}=${S(r)}]`:`${e.tagName||"*"}[@${l}=${S(r)}]`:a?`*[local-name()='${e.tagName}' and normalize-space(@${l})=${S(r)}]`:`${e.tagName||"*"}[normalize-space(@${l})=${S(r)}]`}return o?[o]:[]},X=(e,t)=>{if(!e.textContent)return"";const r=w(e),a=T(r);if(h(r)&&!a)return"";const o=h(r)?a:r,l=A(e,o);let s;return s=l?b(l,I(e),e.tagName||"*"):h(r)?b(`contains(normalize-space(.),${S(o)})`,I(e),e.tagName||"*"):!n.test(r)||/\s/.test(r.trim())?b(`normalize-space(.)=${S(o)}`,I(e),e.tagName||"*"):I(e)?`//*[local-name()='${e.tagName}' and .=${S(o)}]`:`//${e.tagName||"*"}[.=${S(o)}]`,s},Y=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===d(n).length&&1===t.length?b(`normalize-space(@class)=${S(t[0])}`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{fragment:t}=R(n);return t?b(`contains(normalize-space(.),${S(t)})`,I(e),e.tagName.toLowerCase()):""}return b(`normalize-space(${t})=${S(C(n)).trim()}`,I(e),e.tagName.toLowerCase())},j=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===t.length?b(`starts-with(normalize-space(@class),${S(t[0])})`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{prefix:t,fragment:r}=R(n),a=t||r;return a?b(`starts-with(normalize-space(.),${S(a)})`,I(e),e.tagName.toLowerCase()):""}return b(`starts-with(${t},${S(C(n)).trim()})`,I(e),e.tagName.toLowerCase())},q=(e,t,n)=>{if("@class"===t){const t=$(e,n);return 1===t.length?b(`contains(@class,${S(t[0])})`,I(e),e.tagName.toLowerCase()):""}if(t.startsWith("@")&&h(n))return"";if(("."===t||"text()"===t)&&h(n)){const{fragment:t}=R(n);return t?b(`contains(normalize-space(.),${S(t)})`,I(e),e.tagName.toLowerCase()):""}return b(`contains(${t},${S(C(n)).trim()})`,I(e),e.tagName.toLowerCase())},H=(e,t)=>{const r=t.flatMap(t=>(t=>{const r=v(t.name,t.value);if(!r)return[];if("class"===t.name){const t=e.getRootNode?.()??e.ownerDocument;return p(e,r,t)}return h(r)?[]:n.test(r)?[`@${t.name}=${S(r)}`]:[`normalize-space(@${t.name})=${S(r)}`]})(t)).filter(Boolean);if(r.length>=2)return b(`${r[0]} or ${r[1]}`,I(e),e.tagName.toLowerCase());const a=(()=>{const t=C(N(e)?.trim()||""),r=T(t);if(h(t))return r?`contains(normalize-space(.),${S(r)})`:null;const a=A(e,t);return a||(!t||t.length>80||/^\d+$/.test(t)?null:n.test(t)&&t.length<=40&&!t.includes(" ")?`text()=${S(t)}`:t.includes(" ")?`normalize-space(.)=${S(t)}`:`contains(text(),${S(t)})`)})();return 1===r.length&&a?b(`${r[0]} or ${a}`,I(e),e.tagName.toLowerCase()):""},V=(e,t,n)=>{try{return E(e,t,n)}catch(e){return 0}},F=(e,t)=>{const n=[],r=new Set,a=Array.from(e.attributes||[]),o=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"],l=[...o.map(e=>a.find(t=>t.name===e)).filter(Boolean),...a.filter(e=>!o.includes(e.name))],s=a=>{a&&!r.has(a)&&Z(a,e,t)&&(r.add(a),n.push(a))};l.forEach(t=>{if(P(t,e,!1))for(const n of ee(e,t.name,t.value))s(n)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const t=X(e);t&&s(t)}if(a.length>1){const n=_(e,t,a,!1);n&&s(n)}return n},B=(e,t)=>{const n=[];let r=t;for(;r&&r!==e;)n.unshift(J(r)),r=r.parentElement;return r===e?n.join("/"):""},G=(e,t)=>{const n=t??(e.getRootNode?.()||e.ownerDocument),r=J(e),a=I(e)?`//*[local-name()='${e.tagName.toLowerCase()}']`:`//${e.tagName.toLowerCase()}`;for(let t=e.parentElement;t;t=t.parentElement){const a=F(t,n);for(const o of a){const a=`${o}/descendant::${r}`;if(1===V(a,e,n)&&U(a,n)===e)return a;const l=B(t,e);if(l){const t=`${o}/${l}`;if(1===V(t,e,n)&&U(t,n)===e)return t}}}return 1===V(a,e,n)&&U(a,n)===e?a:""},U=(e,t)=>{try{if(L(t)){const{owner:n,contextNode:r,cloneElement:a}=O(t);return n.evaluate(e,r,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue||a}return t.evaluate(e,t,null,t.defaultView.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}catch(e){return null}},Z=(e,t,n)=>{try{const{first:r,second:a}=l(e,n);return!!r&&!a&&r===t}catch{return!1}},J=e=>I(e)?`*[local-name()='${e.tagName.toLowerCase()}']`:e.tagName.toLowerCase(),K=(e,t,n)=>{if(!(e instanceof Element))return[];const r=new Set,a=[],o=Array.from(e.attributes||[]).filter(t=>{return t?.value&&(r=t.value,!/\d/.test(r))&&P(t,e,n);var r}),l=(e,t)=>{t&&!r.has(t)&&(r.add(t),a.push({key:e,value:t}))},s=["id","data-testid","data-test","data-qa","name","formcontrolname","aria-label","role"];s.forEach(n=>{const r=o.find(e=>e.name===n);if(r)for(const n of ee(e,r.name,r.value))n&&Z(n,e,t)&&l(`anchor by ${r.name}`,n)}),o.forEach(n=>{if(!s.includes(n.name))for(const r of ee(e,n.name,n.value))r&&Z(r,e,t)&&l(`anchor by ${n.name}`,r)});const i=e.textContent?.trim();if(i&&i.length<40&&0===e.children.length){const n=X(e);n&&Z(n,e,t)&&l("anchor by text",n)}if(o.length>1){const r=_(e,t,o,n);r&&Z(r,e,t)&&l("anchor by combination",r)}return a},Q=e=>{const t=N(e)?.trim(),n=T(t);if(t&&h(t))return n?`contains(normalize-space(.),${S(n)})`:void 0;const r=A(e,t);if(r)return r;const a=t?S((e=>(e&&=e.split("\n")[0].length>0?e.split("\n")[0]:e.split("\n")[1],e))(t).split(/[^\u0000-\u00ff]/).reduce((e,t)=>e.length>t.length?e:t,"").trim().split("/")[0].trim()):t;return a?a!==`'${t}'`?`contains(.,${a})`:/\s/.test(t)?`normalize-space(.)='${C(t)}'`:`normalize-space(.)='${t}'`:void 0},ee=(e,t,n)=>{const r=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";if(n=v(t,n)){if("class"===t){const t=e.getRootNode?.()??e.ownerDocument;return p(e,n,t).map(t=>I(e)?`//*[local-name()='${e.tagName}' and ${t}]`:`//${e.tagName||"*"}[${t}]`)}if(h(n))return[];a=r.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 a?[a]:[]},te=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function ne(e,t){const n=function(e,t){const n=function(e){return"string"==typeof e?e:e&&"object"==typeof e&&"string"==typeof e.value?e.value:""}(e);return"android"===String(t).toLowerCase()?n.toLowerCase().replace(/@text="[^"]*"/g,'@text="?"').replace(/@text='[^']*'/g,"@text='?'").replace(/"[^"]*"/g,"?").replace(/'[^']*'/g,"?").replace(/\/\/android\.[a-z0-9._-]+/g,"//android_tag").replace(/\/\/\*/g,"//*"):n.toLowerCase().replace(/'[^']*'/g,"?").replace(/"[^"]*"/g,"?").replace(/\[\d+\]/g,"[?]").replace(/\/\/[a-z0-9_-]+/g,"//node").replace(/\/[a-z0-9_-]+/g,"/node")}(e,t);if(t?.toLowerCase().includes("android"))return`XPATH|shape:${n}`;const r=function(e){const t="string"==typeof e?e:e?.value||"";if(!t)return{axis:"none",attribute:"none",usesNormalize:!1};const n=t.toLowerCase(),r=n.match(/(ancestor-or-self|ancestor|descendant-or-self|descendant|following-sibling|preceding-sibling|following|preceding|parent|child|self)::/),a=r?.[1]??"none",o=n.match(/@([a-z0-9:-]+)/);return{axis:a,attribute:o?.[1]??"none",usesNormalize:n.includes("normalize-space")}}(e);return["XPATH",`axis:${r.axis}`,`attr:${r.attribute}`,`normalize:${r.usesNormalize}`,`shape:${n}`].join("|")}function re(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function ae(e,t,n,r,a){const o=r?.getRootNode?.()??e,l=String(a).toLowerCase().includes("android"),s=String(a).toLowerCase().includes("ios"),i=l||s,c=e=>{try{return Array.from(o.querySelectorAll(e))}catch{return[]}},u=(e,t)=>{try{return Array.from(o.querySelectorAll("*")).filter(n=>n.getAttribute(e)===t)}catch{return[]}},f=(e,t)=>{try{return Array.from(o.querySelectorAll("*")).filter(n=>n.getAttribute(e)?.includes(t)??!1)}catch{return[]}};try{switch(t){case"id":return l?1===u("resource-id",n).length:s?1===u("name",n).length:1===c(`#${re(n)}`).length;case"accessibilityId":return l?1===u("content-desc",n).length:s?1===u("name",n).length:1===u("aria-label",n).length;case"className":return l?1===u("class",n).length:s?1===u("type",n).length:1===c(`.${n}`).length;case"tagName":return l?1===u("class",n).length:s?1===c("*").filter(e=>(e.getAttribute("type")||e.tagName)===n).length:1===c(n).length;case"name":return l?1===u("text",n).length||1===u("content-desc",n).length:s?1===u("name",n).length:1===c(`[name="${re(n)}"]`).length;case"linkText":return l?1===u("text",n).length:s?1===u("label",n).length:1===c("a").filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return l?1===f("text",n).length:s?1===f("label",n).length:1===c("a").filter(e=>e.textContent?.includes(n)).length;case"cssSelector":return!i&&1===c(n).length;default:return!1}}catch{return!1}}const oe={getOptimalClassChain:function e(t,n,r){try{if(!n||1!==n.nodeType||!n.tagName||"XCUIElementTypeApplication"===n.tagName)return"";const a=n.tagName,o=["name","label","value"];for(const e of o){const o=r.find(t=>t.name===e);if(!o)continue;let l=o.value;if(!l)continue;if(l=l.trim().replace(/\s+/g," "),x(l))continue;const s=`//${a}[@${e}="${l}"]`;let i=0;try{i=E(s,n,t)}catch(e){console.log(e);continue}const c=/\s/.test(l);if(1===i)return c?`**/${a}[\`${e} CONTAINS "${l}"\`]`:`**/${a}[\`${e} == "${l}"\`]`;if(i>1&&n.parentElement){const t=Array.from(n.parentElement.children).filter(e=>e.tagName===a).indexOf(n)+1;return c?`**/${a}[\`${e} CONTAINS "${l}"\`][${t}]`:`**/${a}[\`${e} == "${l}"\`][${t}]`}}let l=`/${a}`;if(n.parentElement){const e=Array.from(n.parentElement.children).filter(e=>e.tagName===a);if(e.length>1){l+=`[${e.indexOf(n)+1}]`}}return e(t,n.parentElement,r)+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 r=[],a=[];const o=["name","label","value","type"].map(e=>n.find(t=>t.name===e)).filter(e=>Boolean(e));for(let n of o){const o=n.value,l=n.name;if(0!==o.length&&(o&&!x(o))){r.push(`@${l}="${o}"`);const n=`//*[${r.join(" and ")}]`;let s;a.push(`${l} == "${o}"`);try{s=E(n,t,e)}catch(e){console.log(e);continue}if(1===s){if("type"===l&&1===a.length)continue;return a.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}};let le=[],se=[],ie=[],ce=new WeakMap,ue=new WeakMap;const fe=e=>e?[e.tagName,Array.from(e.attributes||[]).map(e=>`${e.name}=${e.value}`).join("|"),e.textContent||""].join("::"):"";var me;me=()=>{ce=new WeakMap,ue=new WeakMap,se=[]},a.add(me);const de={andConditions:"and",orConditions:"or",contains:"contains",startsWith:"startsWith",normalizeSpace:"normalizeSpace",axes:"axes",index:"index",hardCodedText:"text",tillTag:"tag"},he=e=>de[e]||e,ge=(e,t)=>t.map(t=>({...t,key:t?.key?.includes(e)?t.key:`${e} ${t.key}`.trim()})),pe=e=>{const t=new Set;return e.filter(e=>!(!e?.value||t.has(e.value))&&(t.add(e.value),!0))},$e=(e,t)=>t?e:e.filter(e=>!(e=>{let t=null;for(let n=0;n<e.length;n++){const r=e[n];if(t){r===t&&(t=null);continue}if("'"===r||'"'===r){t=r;continue}if("["!==r)continue;const a=e.indexOf("]",n+1);if(-1===a)return!1;if(/^\s*\d+\s*$/.test(e.slice(n+1,a)))return!0}return!1})(e.value)),ye=e=>e?.textContent?.replace(/\s+/g," ")?.trim()||"",ve=e=>{if(!(e&&e instanceof Element))return[];const t=[],n=Array.from(e.children||[]);for(;n.length;){const e=n.shift();e.classList?.contains("flntooltip")||(t.push(e),n.push(...Array.from(e.children||[])))}return t},xe=(e,t)=>{const n=[];let r="previous"===t?e.previousElementSibling:e.nextElementSibling;for(;r;)r.classList?.contains("flntooltip")||n.push(r),r="previous"===t?r.previousElementSibling:r.nextElementSibling;return n},be=(e,t)=>{const n=[];for(let r=e;r?.parentElement;r=r.parentElement){let e="previous"===t?r.previousElementSibling:r.nextElementSibling;for(;e;)e.classList?.contains("flntooltip")||(n.push(e),n.push({node:e,expand:()=>ve(e)})),e="previous"===t?e.previousElementSibling:e.nextElementSibling}return n},Ne=e=>{if(!(e instanceof Element))return!0;const t=e.textContent?.trim();return!e.id&&!e.className&&0===e.attributes.length&&(!t||t.length>60)&&e.children.length>2},we=e=>{let t=0;e.id&&(t+=100),e.getAttribute("data-testid")&&(t+=90),e.className&&(t+=50),0===e.children.length&&(t+=30);const n=e.textContent?.trim();return n&&n.length<40&&(t+=40),t},Ee=(e,t,n,r,a,o,l)=>{const s=Q(n),i=s?`${J(n)}[${s}]`:J(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(Ne(e))continue;const m=[()=>K(e,r,a),()=>{const t=[],n=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,a));for(const r of n){const n=r.value;if(!n)continue;const a=q(e,`@${r.name}`,n);a&&t.push({key:"contains",value:a});const o=j(e,`@${r.name}`,n);o&&t.push({key:"starts-with",value:o})}return t}];for(let a=0;a<m.length;a++){let s=m[a]();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 a=`${e.value}/${t}::${i}`;if(Z(a,n,r)){if(c.push({key:o,value:a}),c.length>=2)return c;if(c.length>=5)return c}}if(l&&a===m.length-1)for(const a of s){const l=E(a.value,e,r);for(let e=1;e<=Math.min(l,3);e++){const l=`(${a.value})[${e}]/${t}::${i}`;if(Z(l,n,r)){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(Ne(s))continue;const e=K(s,r,a);for(const a of e.slice(0,5)){const e=`${a.value}/${t}::${i}`;if(Z(e,n,r)){if(c.push({key:o,value:e}),c.length>=2)return c;if(c.length>=5)return c}}}}}return c},Se=(e,t)=>{const n=[];let r=e;for(;r&&n.length<t;)n.push(r),r=r.parentElement;return n},ke=(e,t)=>{for(let n=e.nextElementSibling;n;n=n.nextElementSibling)if(n===t)return"following-sibling";for(let n=e.previousElementSibling;n;n=n.previousElementSibling)if(n===t)return"preceding-sibling";return""},Ce=(e,t)=>{const n=[];for(let r=e;r&&r!==t;r=r.parentElement){const e=r.parentElement;if(!e)return"";n.push(`/parent::${J(e)}`)}return n.join("")},Ae=(e,t)=>{const n=J(t);return t.parentElement===e?[`/${n}`,`/descendant::${n}`]:[`/descendant::${n}`]},Re=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))};for(let n=e.parentElement,a=0;n&&a<4&&t.length<20;n=n.parentElement,a++){const e=[xe(n,"previous").slice(0,4),xe(n,"next").slice(0,4)];for(const t of e)for(const e of t){r(e);let t=0;for(const n of ve(e).sort((e,t)=>we(t)-we(e))){if(t++>=8)break;r(n)}}}return t.sort((e,t)=>we(t)-we(e)).slice(0,20)})(e),l=Se(e.parentElement,3);for(const s of o){const o=K(s,t,n).slice(0,2);if(!o.length)continue;const i=Se(s,3);for(const n of o)for(const o of i){const i=Ce(s,o);if(o===s||i)for(const s of l){if(!s||!s.contains(e))continue;const l=ke(o,s);if(!l)continue;const c=`/${l}::${J(s)}`;for(const o of Ae(s,e)){const l=`${n.value}${i}${c}${o}`;if(!a.has(l)&&(a.add(l),Z(l,e,t)&&(r.push({key:"chained axes fallback",value:l}),r.length>=2)))return r}}}}return r},Te=e=>{const t=J(e),n=e.textContent?.trim(),r=(e=>{const t=T(e);return t||(e||"").split(/[^a-zA-Z]+/).map(e=>e.trim()).filter(e=>e.length>2).pop()})(n),a=Q(e),o=[];return r&&r!==n&&o.push(`${t}[contains(text(),${S(r)})]`),a&&o.push(`${t}[${a}]`),o.push(t),Array.from(new Set(o))},Le=(e,t,n)=>{const r=N(e)?.trim(),a=[];if(r&&r.length>2&&r.length<40&&!h(r)){const t=`//${e.tagName}[.=${S(r)}]`;a.push({key:"anchor by text",value:t})}return[...a,...K(e,t,n)]},Oe=(e,t,n)=>{const r=[],a=new Set,o=(e=>{const t=[],n=new Set,r=r=>{r&&r!==e&&!n.has(r)&&(r.contains(e)||e.contains(r)||(n.add(r),t.push(r)))},a=e=>{for(const t of[e,...ve(e)]){const e=N(t)?.trim();e&&e.length<40&&!h(e)&&0===t.children.length&&r(t)}};for(let n=e.parentElement,o=0;n&&o<4&&t.length<30;n=n.parentElement,o++){const e=xe(n,"previous").reverse(),t=xe(n,"next");for(const n of[...e,...t])a(n),r(n)}return t.slice(0,30)})(e),l=Te(e);for(const s of o){const o=Le(s,t,n).slice(0,2);if(o.length)for(const n of o)for(const o of Se(s.parentElement,5)){if(!o.contains(e))continue;const s=`/ancestor::${J(o)}`;for(const o of l){const l=`${n.value}${s}/descendant::${o}`;if(!a.has(l)&&(a.add(l),Z(l,e,t)&&(r.push({key:"ancestor descendant bridge",value:l}),r.length>=1)))return r}}}return r},De=(e,t)=>{const n=[];for(let r=t;r&&r!==e;r=r.parentElement)n.unshift(J(r));if(!n.length)return"";const r=n.pop();return`${n.length?`/${n.join("/")}`:""}/child::${r}`},Pe=(e,t,n,r)=>{const a=new Set,o=[],l=(e,t)=>{t&&!a.has(t)&&(!r&&/\[\d+\]/.test(t)||(a.add(t),o.push({key:e,value:t})))};return K(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)||!h(t.value)||"class"===t.name)return;const n=(e=>{const t=(e.split(/\d/)[0]||"").replace(/[-_:\s.]+$/g,"").trim();return t.length>2&&/[a-zA-Z]/.test(t)?t:""})(t.value);if(!n)return;const r=q(e,`@${t.name}`,n);l(`anchor by stable ${t.name}`,r)}),o},Ie=(e,t,n,r)=>{const a=[];for(let t=e.parentElement;t;t=t.parentElement)a.push(t);const o=ve(e),l=xe(e,"previous"),s=xe(e,"next"),i=be(e,"previous"),c=be(e,"next"),u=(e,t=20)=>e.length>t?e.slice(0,t):e,f=[[{nodes:u(s),axis:"preceding-sibling",key:"preceding-sibling"},{nodes:u(l),axis:"following-sibling",key:"following-sibling"}],[{nodes:u(a),axis:"child",key:"child"},{nodes:u(o,15),axis:"parent",key:"parent"}],[{nodes:u(a),axis:"descendant",key:"descendant"},{nodes:u(a),axis:"descendant-or-self",key:"descendant-or-self"},{nodes:u(o,10),axis:"ancestor",key:"ancestor"},{nodes:u(o,10),axis:"ancestor-or-self",key:"ancestor-or-self"}],[{nodes:u(i),axis:"following",key:"following"},{nodes:u(c),axis:"preceding",key:"preceding"}]],m=((e,t,n,r)=>{const a=[],o=new Set;for(let l=e.parentElement,s=0;l&&s<8;l=l.parentElement,s++){const s=De(l,e);if(!s)continue;const i=Pe(l,t,n,r);for(const n of i.slice(0,3)){const r=`${n.value}${s}`;if(!o.has(r)&&(o.add(r),Z(r,e,t)&&(a.push({key:"child chain",value:r}),a.length>=2)))return a}}return a})(e,t,n,r);if(m.length)return m;for(const a of f)for(const o of a){const a=Ee(o.nodes,o.axis,e,t,n,o.key,r);if(a.length>0)return a}const d=Oe(e,t,n);return d.length?d:Re(e,t,n)||[]},ze=(e,t,n,r,a)=>{const o=he(r);return"text"===o?ge(r,((e,t,n)=>{if(!ye(e))return[];if("text"===n){const n=X(e)||He(e,t,!1,!1);return n?[{key:"xpath by text",value:n}]:[]}return[]})(e,t,o)):["contains","startsWith","normalizeSpace"].includes(o)?ge(r,((e,t,n,r)=>{const a=[],o=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,n)),l=ye(e),s="contains"===r?q:"startsWith"===r?j:"normalizeSpace"===r?Y:null;if(!s)return a;if("contains"===r&&l)for(const n of["text()","."]){const a=s(e,n,l);if(a&&1===E(a,e,t))return[{key:`xpath by ${r} text`,value:a}]}if(o.forEach(n=>{if("class"===n.name)return void p(e,n.value,t).forEach(t=>{const n=b(t,I(e),e.tagName.toLowerCase());n&&a.push({key:`xpath by ${r} class`,value:n})});const o=s(e,`@${n.name}`,n.value);o&&a.push({key:`xpath by ${r} ${n.name}`,value:o})}),"contains"===r&&a.length){const n=a.find(n=>1===E(n.value,e,t));return n?[n]:[]}if(l){const t=s(e,".",l);t&&a.push({key:`xpath by ${r} text`,value:t})}return a})(e,t,n,o)):["and","or"].includes(o)?ge(r,((e,t,n,r)=>{const a=Array.from(e.attributes||[]).filter(t=>t?.value&&P(t,e,n));if("and"===r){const r=_(e,t,a,n);return r?[{key:"xpath by combination",value:r}]:[]}if("or"===r&&a.length>=1){const t=H(e,a);return t?[{key:"xpath by or",value:t}]:[]}return[]})(e,t,n,o)):"axes"===o?ge(r,Ie(e,t,n,!1)):"index"===o?ge(r,((e,t)=>{const n=[],r=e.tagName.toLowerCase(),a=Array.from(t.querySelectorAll(r)).indexOf(e)+1;if(a<=0)return[];n.push({key:"xpath by index",value:`(//${r})[${a}]`});let o=e.parentElement;for(;o&&o!==t.body;){if(o.id||o.className){const t=o.id?ee(o,"id",o.id):ee(o,"class",o.className.toString());for(const a of t){const t=Array.from(o.querySelectorAll(r)).indexOf(e)+1;if(t>0){n.push({key:"xpath by index",value:`(${a}//${r})[${t}]`});break}}if(n.length>1)break}o=o.parentElement}return n})(e,t)):"tag"===o?ge(r,[{key:"xpath till tag",value:G(e,t)}]):[]},_e=(e,t,n,r,a,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=E(e,n,r);if(1===t)return e;if(t>1&&(se.length?t<se[0].count&&(se.pop(),se.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):se.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!le.length){const o=k(e,n,r,t);o&&1===E(o,n,r)&&le.push({key:"relative xpath by unique parent "+(a?"index":""),value:o})}}}return null},We=(e,t,r,a,o,l)=>{try{const s=[a?"target":"reference",l?"index":"no-index",o,fe(r)].join("::");let i=ce.get(e);if(i){if(i.has(s))return i.get(s)}else i=new Map,ce.set(e,i);const c=[];let u=e;for(;u&&1===u.nodeType;){const e=!1;for(const e of Array.from(u.attributes))if(P(e,u,a)){const n=v(e.name,e.nodeValue),a=e.name;for(const e of ee(u,a,n)){let n;try{n=_e(e,o,r,t,l,"parent")}catch(e){continue}if(n)return n}}if(u.textContent&&!u.textContent)if(!a||a&&!x(u.textContent)){let e;e=n.test(u.textContent)?I(u)?`//*[local-name()='${u.tagName}' and .=${S(w(u))}]`:`//${u.tagName||"*"}[.=${S(w(u))}]`:I(u)?`//*[local-name()='${u.tagName}' and normalize-space(.)=${S(w(u))}]`:`//${u.tagName||"*"}[normalize-space(.)=${S(w(u))}]`;const a=_e(e,o,r,t,l,"parent");if(a)return a}else{const e=[],n=[...new Set(w(u).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(n?.length)for(let t=0;t<n?.length;t++)n[t]&&C(n[t].trim())&&(a.test(n[t])?e.push(`contains(.,${S(n[t].trim()).trim()})`):e.push(`contains(.,${S(C(n[t])).trim()})`));if(e?.length){const n=I(u)?`//*[local-name()='${u.tagName}' and ${e.join(" and ")}]`:`//${u.tagName||"*"}[${e.join(" and ")}]`,a=_e(n,o,r,t,l,"parent");if(a)return a}}if(!e){const e=I(u)?`/*[local-name()='${u.tagName}']`:`/${u.tagName}`;c.unshift(e)}u=u.parentElement}const f=c.join("")+o;if(1===E(f,e,t))return i.set(s,f),f;i.set(s,null)}catch(e){return console.error(e),null}},Me=(e,t,n,r)=>{const a=[];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(P(n,o,r)){const r=v(n.name,n.nodeValue),l=n.name;for(const n of ee(o,l,r)){let r;try{r=E(n,o,t)}catch(e){continue}if(1===r){a.unshift(n),e=!0;break}}}if(e)break}if(!e&&o.textContent&&!n.textContent){const n=X(o);if(n){if(1===E(n,o,t)){e=!0,a.unshift(n);break}}}if(e)break;{const e=I(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;a.unshift(e)}o=o.parentElement}return a.join("")}catch(e){return console.log(e),null}},Xe=(e,t,n)=>{const r=fe(n);let a=ue.get(e);if(a){if(a.has(r))return a.get(r)}else a=new Map,ue.set(e,a);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(P(n,l,!0)){const r=v(n.name,n.nodeValue),a=n.name;for(const n of ee(l,a,r)){let r;try{r=E(n,l,t)}catch(e){continue}if(1===r){e=!0,o.push(n);break}}}if(e)break}if(!e&&l.textContent&&!n.textContent){const n=X(l);if(n){if(1===E(n,l,t)){e=!0,o.push(n);break}}}if(e)break;{const e=I(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 a.set(r,e),e}catch(e){return console.log(e),a.set(r,null),null}},Ye=(e,t,n,r)=>{try{const a=document.querySelector(".flntooltip");for(let o=e.nextElementSibling;null!==o&&o!==a;o=o.nextElementSibling)je(o,e,t,r,"preceding-sibling",n);for(let o=e.previousElementSibling;null!==o&&o!==a;o=o.previousElementSibling)je(o,e,t,r,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},je=(e,t,n,r,a,o)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){const l=M(e,{name:t.name,value:t.value},o);for(let t of l){t+=`/${a}::${r}`;const o=E(t,e,n);if(1===o)return void le.push({key:`xpath by ${a}`,value:t});o>1&&(se.length?o<se[0].count&&(se.pop(),se.push({key:`relative xpath by ${a}`,value:t,count:o})):se.push({key:`relative xpath by ${a}`,value:t,count:o}))}}if(!o){let t;if(t=W(e,{name:"text",value:e.textContent},o),t){const r=E(t,e,n);if(1===r)return void le.push({key:`xpath by ${a}`,value:t});r>1&&(se.length?r<se[0].count&&(se.pop(),se.push({key:`relative xpath by ${a}`,value:t,count:r})):se.push({key:`relative xpath by ${a}`,value:t,count:r}))}}}catch(e){console.log(`${a} xpath-error`,e)}};const qe=(e,t,n,r,a)=>{try{o(t);let l,s,i=[];if(le=[],a)for(const t of a){const n=M(e,{name:t.name,value:t.value},r);for(const e of n)e&&i.push(e)}if(e.textContent){let t=W(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(!le.length){if(Ye(e,t,r,i[a]),!le.length&&(l||(l=Me(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=E(r,e,t);if(1===o)le.push({key:"relative xpath by relative parent",value:r});else if(o>1&&n){const a=k(r,e,t,o);a&&1===E(a,e,t)&&le.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!le.length&&(s||(s=Xe(e,t,e)),s&&(s.includes("@")||s.includes("text()")||s.includes(".=")))){const r=s.replace(/^\/+/,""),o=`/${i[a]}/${r}`,l=E(o,e,t);if(1===l)le.push({key:"relative xpath by relative child",value:o});else if(l>1&&n){const r=k(o,e,t,l);r&&1===E(r,e,t)&&le.push({key:"relative xpath by relative parent "+(n?"index":""),value:r})}}if(1===le?.length&&le?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const r=He(e,t,n,!1);r&&le.unshift({key:"xpath by text"+(n?"index":""),value:r})}if(!le.length){let o=We(e.parentElement,t,e,r,i[a],n);o&&le.push({key:"xpath by unique parent",value:o})}}return le}catch(e){console.log(e)}},He=(e,t,n,r)=>{if(""!=(e.textContent??"").trim()){const a=N(e);if(a)return z(e,t,"text()",a,n,r)||z(e,t,".",a,n,r)}},Ve=(e,t,n,r,a)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&P(e,t,a)){const o=((e,t,n,r,a)=>{let o;if(o=e.name,P(e,t,a))return z(t,n,`@${o}`,e.value,r,a)})(e,t,n,r,a);o&&le.push({key:`xpath by ${e.name}${r?" index":""}`,value:o})}});const l=He(t,n,r,a);if(l&&le.push({key:"xpath by text"+(r?" index":""),value:l}),o.find(e=>["className","class"].includes(e.name))&&P(o?.find(e=>["className","class"].includes(e.name)),t,a)){let e=((e,t,n,r)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=v("class",a),a=a?.trim(),a&&P({name:"class",value:a},e,r))return z(e,t,"@class",a,n,r)})(t,n,r,a);e&&le.push({key:"xpath by class",value:e})}if(o.length>1){const e=_(t,n,o,a);e&&le.push({key:"xpath by combination",value:e})}if(!le.length){const r=function(e,t,n,r){const{tagName:a}=t,o=t.textContent.trim();if(!o)return;const l=C(o),s=T(l);if(h(l)&&!s)return;const i=h(l)?s:l,c=A(t,i);for(const s of e)if(P(s,t,r)){let e=v(s.name,s.nodeValue);const r=`//${a}[@${s.name}='${e}' and ${c||(h(l)?`contains(normalize-space(.),${S(i)})`:/\s/.test(o)?`normalize-space(.)=${S(i)}`:`text()=${S(i)}`)}]`;if(r&&1==E(r,t,n))return r}}(e,t,n,a);r&&le.push({key:"xpath by textAttribute",value:r})}}catch(e){console.log(e)}},Fe=(e,t,n,r,a=[],l=[],s)=>{if("Android"===s)return((e,t,n,r,a=[])=>{le=[],ie=[];const o={},l={},s=e,i=s?.ownerDocument||t,c=s?.tagName,{attributes:u}=s;if([...u].forEach(e=>{"resource-id"===e.name?o.id=e.value:"content-desc"===e.name?o.content=e.value:o[e.name]=e.value}),o?.id&&!x(o.id)){const e=`//*[@resource-id=${S(o.id)}]`;1===E(e,s,i)&&(ie.push({key:"id",value:[{key:"resource-id",value:o.id}],viewkey:"Id"}),l["resource-id"]=1)}if(o?.content&&!x(o.content)){const e=`//*[@content-desc=${S(o.content)}]`;1===E(e,s,i)&&(ie.push({key:"accessibilityId",value:[{key:"accessibilityID",value:o.content}],viewkey:"accessibilityId"}),l["content-desc"]=1)}if(o?.class&&!x(o.class)){const e=`//*[@class=${S(o.class)}]`;1===E(e,s,i)&&(ie.push({key:"className",viewkey:"className",value:[{key:"class",value:o.class}]}),l.class=1)}const f=(a.length>0?a:Array.from(u)).filter(e=>!l[e.name]);if(Ve(f,s,i,n,r),le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+c.length),1===E(t,e,i)&&le.push({key:`${le[n].key} regex`,value:t})}}le.length||qe(s,i,n,r,f);for(const e of le)ie.push({key:"xpath",viewkey:"xpath",value:[e]});return ie})(e,t,n,r,a);if("iOS"===s)return((e,t,n,r,a=[])=>{le=[],ie=[];const o={},l=e,s=l?.ownerDocument||t,i=l?.tagName,{attributes:c}=l,u=(e,t,n)=>{const r=l.getAttribute(n);if(!r||x(r))return;const a=`//*[@${n}=${S(r)}]`;1===E(a,l,s)&&(ie.push({key:e,viewkey:t,value:[{key:n,value:r}]}),o[n]=1)};u("accessibilityId","accessibilityId","name"),u("className","className","type");const f=a.length>0?a:Array.from(c),m=f.filter(e=>["label","name","value","type"].includes(e.name)),d=oe.getOptimalClassChain(s,l,m);d&&ie.push({viewkey:"Class Chain",key:"iOSClassChain",value:[{key:"classChain",value:d}]});const h=oe.getOptimalPredicateString(s,l,m);h&&ie.push({viewkey:"Predicate String",key:"iOSNsPredicateString",value:[{key:"predicateString",value:h}]});const g=f.filter(e=>("name"===e.name||!o[e.name])&&["name","label","value"].includes(e.name));if(Ve(g,l,s,n,r),le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+i.length),1===E(t,e,s)&&le.push({key:`${le[n].key} regex`,value:t})}}le.length||qe(l,s,n,r,g);for(const e of le)ie.push({key:"xpath",viewkey:"xpath",value:[e]});return ie})(e,t,n,r,a);le=[];const i=e,c=i?.getRootNode?.(),u=c?.nodeType===Node.DOCUMENT_FRAGMENT_NODE,f=u?c:i?.ownerDocument||t;o(f);const m=i.tagName,{attributes:d}=i,h=a.length>0?a:Array.from(d);if(Ve(h,i,f,n,r),l.length){const e=n||((e=[])=>e.some(e=>"index"===he(e)))(l),t=l.flatMap(e=>ze(i,f,r,e));return le=pe(t.filter(e=>1===E(e.value,i,f))),$e(le,e)}if(le.length){const t=le.length;for(let n=0;n<t;n++){let t=le[n].value;t="//*"+t.substring(t.indexOf("//")+2+m.length);1===E(t,e,f)&&le.push({key:`${le[n].key} regex`,value:t})}}return le.length||u||(le=Ie(i,f,r,n)),$e(pe(le),n)},Be=["data-testid","data-test-id","data-test","data-cy","data-qa","name","aria-label","aria-labelledby","placeholder","title","alt","role"],Ge=new Set(["id","class","style"]),Ue=(e,t)=>{const n=t?.ownerDocument?.defaultView?.CSS??globalThis.CSS;return n?.escape?n.escape(e):String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")},Ze=e=>{if(!e)return!1;const t=e.ownerDocument?.defaultView;return Boolean(t&&e instanceof t.Element)},Je=e=>{const t=e.tagName.toLowerCase();return"style"===t||"script"===t},Ke=e=>{const t=e.trim();return Boolean(t)&&t.length<=120&&!/^\d+$/.test(t)},Qe=(e,t,n)=>{try{const r=n.querySelectorAll(e);return 1===r.length&&r[0]===t}catch{return!1}},et=(e,t,n)=>{n&&!e.some(e=>e.value===n)&&e.push({key:t,value:n})},tt=(e,t="single")=>{const n=[],r=e.getRootNode();try{const a=nt(e);if(a&&Qe(a,e,r)&&(et(n,"cssSelector by id",a),"single"===t))return n;const o=at(e);if(o&&(et(n,"cssSelector by attribute",o),"single"===t))return n;const l=ot(e);if(l&&Qe(l,e,r)&&(et(n,"cssSelector by class",l),"single"===t))return n;const s=it(e);if(s&&Qe(s,e,r)&&(et(n,"cssSelector by stable parent",s),"single"===t))return n}catch(e){console.error(e)}return n},nt=e=>{if(!Ze(e)||Je(e))return;const t=e.getAttributeNode("id");return t&&(P(t,e,!0)||((e,t)=>{const n=t.value.trim();return!!Ke(n)&&(!i.some(t=>t.doc===e.ownerDocument&&t.element===e&&"id"===t.attributeName)&&!/\d{4,}/.test(n))})(e,t))?`#${Ue(e.id,e)}`:void 0};function rt(e,t=!1){const n=Array.from(e.attributes).filter(n=>{const r=n.name.toLowerCase();return!Ge.has(r)&&(!(t&&!Be.includes(r))&&(Ke(n.value)&&P(n,e,!0)))});return n.sort((e,t)=>{const n=Be.indexOf(e.name.toLowerCase()),r=Be.indexOf(t.name.toLowerCase());return(-1===n?999:n)-(-1===r?999:r)}),n.map(e=>{return`[${e.name}="${t=e.value.trim(),String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const at=e=>{if(!Ze(e)||Je(e))return;const t=e.getRootNode(),n=e.tagName.toLowerCase(),r=rt(e);for(const a of r){if(Qe(a,e,t))return a;const r=`${n}${a}`;if(Qe(r,e,t))return r}},ot=e=>{if(!Ze(e)||Je(e))return;const t=lt(e);if(!t)return;const n=e.getRootNode(),r=`${e.tagName.toLowerCase()}${t}`;return Qe(t,e,n)?t:Qe(r,e,n)?r:void 0},lt=e=>{if("string"!=typeof e.className||!e.className||i?.find(t=>t.element===e&&"class"===t.attributeName))return;const t=$(e,e.className).filter(Ke);return t.length?t.slice(0,3).map(t=>`.${Ue(t,e)}`).join(""):void 0},st=(e,t={})=>{if(!Ze(e)||Je(e))return[];const n=[],r=e.tagName.toLowerCase(),a=nt(e);a&&n.push(a);for(const a of rt(e,t.preferredAttributesOnly))n.push(a),t.includeTag&&n.push(`${r}${a}`);const o=lt(e);return o&&(n.push(o),t.includeTag&&n.push(`${r}${o}`)),Array.from(new Set(n))},it=e=>{if(!Ze(e)||Je(e))return;const t=e.getRootNode(),n=st(e,{includeTag:!0,preferredAttributesOnly:!1});let r=e.parentElement;for(;r&&Ze(r)&&!Je(r);){const a=st(r,{includeTag:!0,preferredAttributesOnly:!0});for(const o of a)if(Qe(o,r,t))for(const r of n){const n=`${o} ${r}`;if(Qe(n,e,t))return n;const a=`${o} > ${r}`;if(Qe(a,e,t))return a}r=r.parentElement}},ct=(e,t,n)=>{const r=te(e);if(vt(t,r)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(r)){const e=t.evaluate(r,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(let t=0;t<e.snapshotLength;t++)if(e.snapshotItem(t)===n)return!0}return!1},ut=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return dt(e.body,t)},ft=(e,t,n)=>ut(t,e)===n,mt=e=>e.name?.toLowerCase().includes("cssselector")??!1,dt=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:r}=n[e];if(r){const e=dt(r,t);if(e)return e;if(r&&!t.includes("dynamic"))return r.querySelector(t)}}}catch(e){console.log(e)}return null},ht=(e,t)=>{if(!e)return null;const n=String(t).toLowerCase();return n.includes("android")?e.getAttribute("resource-id")||e.getAttribute("resourceId")||null:n.includes("ios")?e.getAttribute("name")||null:e.id||null},gt=(e,t)=>{const n=String(t).toLowerCase();return n.includes("android")?e.getAttribute("class")||e.getAttribute("className")||null:n.includes("ios")?e.getAttribute("type")||null:e.className||null},pt=e=>e.textContent?.trim()||null,$t=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},yt=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function vt(e,t){try{const n=e.defaultView?.XPathResult?.FIRST_ORDERED_NODE_TYPE??("undefined"!=typeof XPathResult?XPathResult.FIRST_ORDERED_NODE_TYPE:9),r=e.defaultView?.XPathEvaluator?new e.defaultView.XPathEvaluator:"undefined"!=typeof XPathEvaluator?new XPathEvaluator:null;return(r?r.evaluate(t,e,null,n,null):e.evaluate(t,e,null,n,null)).singleNodeValue}catch(e){return console.error("Invalid XPath:",t,e),null}}function xt(e,t,n){if(e.includes(t)){const r=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(r,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let r;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(r=e,r):(console.error("Complete Locator is Invalid:",e),r=e,r)}console.error("Source Locator Not Found:",r)}}return null}const bt=(e,t,n)=>{o(t);const r=t.querySelectorAll("script, style, link[rel='stylesheet'], meta, noscript, embed, object, param, source, svg");r&&r.forEach(e=>{e.remove()});const a=new Set;let l=[];function s(e,t={}){const n=e?.value,r=t.value??e?.value,o={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;o.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(o.name,n,r),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(o)}const i=(e,t,n)=>{for(const r of Array.from(e.querySelectorAll("*")))if(r.getAttribute(t)===n)return r;return null},c=e=>String(e).toLowerCase().includes("android"),u=e=>c(e)||String(e).toLowerCase().includes("ios"),f=e=>String(e).toLowerCase().includes("ios"),m=e=>{switch(String(e||"").trim().toLowerCase().replace(/^-/,"").replace(/[\s_-]+/g,"")){case"id":return"id";case"name":return"name";case"xpath":return"xpath";case"classname":return"className";case"accessibilityid":return"accessibilityId";case"iospredicatestring":case"iosnspredicatestring":return"iosPredicateString";case"iosclasschain":return"iosClassChain";default:return String(e||"")}},d=t=>e.locators.find(e=>m(e.name)===t),h=(e,t)=>"type"===t.toLowerCase()?e.getAttribute("type")||e.tagName||"":e.getAttribute(t)||"",g=(e,t)=>{const n=t.trim().replace(/^\((.*)\)$/s,"$1");if(/^(TRUEPREDICATE|1\s*==\s*1)$/i.test(n))return!0;const{clauses:r,operators:a}=(e=>{const t=[],n=[];let r="",a=0;for(let o=0;o<e.length;o++){const l=e[o];if(('"'===l||"'"===l)&&"\\"!==e[o-1]){r=r===l?"":r||l;continue}if(r)continue;const s=e.slice(o).match(/^\s+(AND|OR)\s+/i);s&&(t.push(e.slice(a,o).trim()),n.push(s[1].toUpperCase()),o+=s[0].length-1,a=o+1)}return t.push(e.slice(a).trim()),{clauses:t,operators:n}})(n),o=r.map(t=>{const n=t.match(/^([\w-]+)\s*(==|=|!=|CONTAINS|BEGINSWITH|ENDSWITH|MATCHES)(\[[cd]+\])?\s*(?:"((?:\\.|[^"])*)"|'((?:\\.|[^'])*)'|([^\s]+))$/i);if(!n)return!1;const[,r,a,o,l,s,i]=n,c=(l??s??i??"").replace(/\\([\\"'])/g,"$1");let u=h(e,r),f=c;switch("1"===f&&"true"===u.toLowerCase()?u="1":"0"===f&&"false"===u.toLowerCase()&&(u="0"),o?.toLowerCase().includes("c")&&(u=u.toLocaleLowerCase(),f=f.toLocaleLowerCase()),a.toUpperCase()){case"=":case"==":return u===f;case"!=":return u!==f;case"CONTAINS":return u.includes(f);case"BEGINSWITH":return u.startsWith(f);case"ENDSWITH":return u.endsWith(f);case"MATCHES":try{return new RegExp(f).test(u)}catch{return!1}default:return!1}});let l=o[0]??!1;return a.forEach((e,t)=>{l="AND"===e?l&&o[t+1]:l||o[t+1]}),l},p=(e,t)=>{const n=(e=>{const t=[];let n="",r="",a="",o=0;for(let l=0;l<e.length;l++){const s=e[l];'"'!==s&&"'"!==s||"\\"===e[l-1]?r||"`"!==s&&"$"!==s?r||a||"["!==s?r||a||"]"!==s||o--:o++:a=a===s?"":a||s:r=r===s?"":r||s,"/"!==s||r||a||0!==o?n+=s:(n&&t.push(n),n="")}return n&&t.push(n),t.filter(Boolean)})(t.trim());let r=[e],a=!1;for(const e of n){if("**"===e){a=!0;continue}const t=e.match(/^([^[]+)/)?.[1]?.trim()||"*",n=Array.from(e.matchAll(/\[(?:`([^`]*)`|\$([^$]*)\$)\]/g)).map(e=>e[1]??e[2]),o=e.match(/\[(-?\d+)\]\s*$/),l=[];for(const e of r){const r=a?Array.from(e.querySelectorAll("*")):9===e.nodeType?[e.documentElement]:Array.from(e.children);l.push(...r.filter(e=>{const r=h(e,"type");return("*"===t||r===t)&&n.every(t=>g(e,t))}))}if(o){const e=Number(o[1]),t=e<0?l.length+e:e-1;r=l[t]?[l[t]]:[]}else r=l;if(a=!1,!r.length)return null}return r[0]||null},$=(e,t)=>("xpath"===m(e.name)||e.name?.toLowerCase().includes("xpath")||t.startsWith("//"))&&!String(e.type||"").includes("dynamic"),y=e=>e.flatMap(e=>e?Array.isArray(e.value)?"xpath"!==e.key&&"xpath"!==e.viewkey?[]:e.value:[e]:[]).filter(e=>"string"==typeof e?.value&&e.value.trim().startsWith("//")),v=(e,t,n)=>{const r=m(t.name);if($(t,n))return vt(e,te(n));if("id"===r||"accessibilityId"!==r&&t.name.includes("id")||n.startsWith("#")){const t=n.startsWith("#")?n.slice(1):n;return i(e,"resource-id",t)||i(e,"content-desc",t)}return"accessibilityId"===r?i(e,"content-desc",n):"className"===r||t.name.includes("className")||n.startsWith(".")?e.querySelector(`[class="${n}"]`)||null:"name"===r?i(e,"text",n)||i(e,"content-desc",n):"tagName"===r?e.querySelector(`[class="${n}"]`)||null:"linkText"===r?i(e,"text",n):"partialLinkText"===r&&Array.from(e.querySelectorAll("*")).find(e=>e.getAttribute("text")?.includes(n))||null},b=(e,t,n)=>{const r=m(t.name);return $(t,n)?vt(e,te(n)):"id"===r||"accessibilityId"===r||"name"===r?i(e,"name",n):"className"===r?i(e,"type",n):"iosPredicateString"===r?((e,t)=>Array.from(e.querySelectorAll("*")).find(e=>g(e,t))||null)(e,n):"iosClassChain"===r?p(e,n):null},N=(e,t,n)=>{const r=m(t.name);if($(t,n))return vt(e,te(n));if(mt(t))return ut(e,n);if("id"===r||t.name.includes("id")||n.startsWith("#")){const t=n.startsWith("#")?n.slice(1):n;return e.querySelector("#"+re(t))}return"className"===r||t.name.includes("className")||n.startsWith(".")?e.querySelector(n):"name"===r?e.querySelector(`[name="${re(n)}"]`):"tagName"===r?e.querySelector(n):"linkText"===r?Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.trim()===n)||null:"partialLinkText"===r&&Array.from(e.querySelectorAll("a")).find(e=>e.textContent?.includes(n))||null};function w(e,t,r){const a=e.querySelectorAll("iframe");for(const e of a)try{const a=e.contentDocument||e.contentWindow?.document;if(!a)continue;const o=c(n)?v(a,t,r):f(n)?b(a,t,r):N(a,t,r);if(o)return o}catch{continue}return null}const E=(e,t,n,r)=>{if(null==e)return null;"string"!=typeof e&&(e=String(e));let a=e.trim();if(!a||"null"===a.toLowerCase())return null;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());const o=String(r).toLowerCase().includes("android"),l=/^[a-zA-Z0-9._]+:id\/[a-zA-Z0-9_]+$/.test(a);return"xpath"!==t||"Y"!==n||a.startsWith("//")||o&&l?!a||/^['"]{2}$/.test(a)?null:a:null};e:for(const r of e.locators)try{String(r.isRecorded||"");const o=e.locators.filter(e=>"N"===e.isRecorded);if(o.length>0)for(const e of o)s(e);const i=String(r.value||r.type||"");if(i.includes("dynamic")||i.match("dynamic")||i.includes("{")||i.includes("}")){s(r);continue}if(e.isShared.includes("Y"))break e;try{let o=null;const i=r.value.split(">>>");for(const e of i){if(!t){console.error("Element not found at:",e);break}const a=e.trim();if(o=c(n)?v(t,r,a):f(n)?b(t,r,a):N(t,r,a),o||(o=w(t,r,a)),o||u(n)||!t.body||(o=dt(t.body,a)),!o){console.error("Element not found at:",a);break}}const h=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(o){const r=e.locators.filter(e=>"xpath"===m(e.name)&&e.value),a=e.locators.filter(e=>mt(e)&&e.value);for(const e of r)ct(e.value,t,o)&&s(e,{isSelfHealed:null});for(const e of a)ft(e.value,t,o)&&s(e,{isSelfHealed:null});const i=l.filter(e=>"xpath"===m(e.name)&&e.value),g=new Set(i.map(e=>ne(e.value,n))),p=[],$=ht(o,n);if(!f(n)&&$&&!h("id",$)&&!x($)){const e=d("id");ae(t,"id",$,o,n)&&(p.push(c(n)?"resource-id":"id"),s(e,{name:"id",type:"static",isRecorded:"Y",value:$}))}const v=c(n)?o.getAttribute("content-desc"):f(n)?o.getAttribute("name"):o.getAttribute("aria-label"),b=d("accessibilityId");if(!v||f(n)&&!b||h("accessibilityId",v)||x(v)||ae(t,"accessibilityId",v,o,n)&&(p.push(c(n)?"content-desc":f(n)?"name":"aria-label"),s(b,{name:b?.name||"accessibilityId",type:"static",isRecorded:"Y",value:v})),!u(n)){const e=o.tagName;if(e&&!h("tagName",e)){const r=d("tagName");ae(t,"tagName",e,o,n)&&(p.push("tagName"),s(r,{name:"tagName",type:"static",isRecorded:"Y",value:e}))}}const N=pt(o);if(N&&!x(N)){const e=d("linkText");ae(t,"linkText",N,o,n)&&(p.push(c(n)?"text":"linkText"),s(e,{name:c(n)?"name":"linkText",type:"static",isRecorded:"Y",value:N}))}const w=$t(o);if(!f(n)&&w&&!h("name",w)&&!x(w)){const e=d("name");ae(t,"name",w,o,n)&&(p.push("name"),s(e,{name:"name",type:"static",isRecorded:"Y",value:w}))}const S=gt(o,n),k=d("className");if(!S||f(n)&&!k||""===S.trim()||S.includes(" ")||h("className",S)||x(S)||ae(t,"className",S,o,n)&&(p.push(f(n)?"type":"className"),s(k,{name:k?.name||(f(n)?"class name":"className"),type:"static",isRecorded:"Y",value:S})),f(n)){const e=Array.from(o.attributes),n=oe.getOptimalPredicateString(t,o,e),r=d("iosPredicateString");r&&n&&!h(r.name,n)&&s(r,{name:r.name,type:"static",isRecorded:"Y",value:n});const a=oe.getOptimalClassChain(t,o,e),l=d("iosClassChain");l&&a&&!h(l.name,a)&&s(l,{name:l.name,type:"static",isRecorded:"Y",value:a})}u(n)||tt(o,"single").forEach(e=>{e.value&&!h("cssSelector",e.value)&&s(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const C=Array.from(o.attributes).filter(e=>!p.includes(e.name)||f(n)&&"name"===e.name);let A=[];try{A=Fe(o,t,!1,!0,C,[],n)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==A?.length){const e=r.filter(e=>!ct(e.value,t,o));let a=0;for(const t of e){if(a>=e.length)break;const r=ne(t.value,n);if(g.has(r))continue;const o=y(A).find(e=>"string"==typeof e.value&&ne(e.value,n)===r);o?.value&&(s(t,{name:"xpath",value:o.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),g.add(r),a++)}if(a<e.length){console.log("xpathResults =",JSON.stringify(A,null,2));for(const t of A){const o=y([t]);for(const t of o){if(a>=e.length)break;const o="string"==typeof t.value?t.value:"";if(!o)continue;const l=ne(o,n);if(g.has(l))continue;const i=e[a]??r[a];i&&(s(i,{name:"xpath",value:o,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),g.add(l),a++)}}}}for(const n of e.locators)try{for(const r of e.locators)if(r.value)for(const e of yt)if(r.value.includes(e)){const a=xt(r.value,e,t);if(a){s(r,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(!f(n)&&l.length<5){const e=[{name:"id",value:ht(o,n)},{name:"name",value:$t(o)},{name:"className",value:gt(o,n)},...u(n)?[]:[{name:"tagName",value:o.tagName}],{name:c(n)?"name":"linkText",value:pt(o)}];for(const r of e){if(l.length>4)break;const{name:e,value:a}=r;a&&(x(a)||h(e,a)||"className"===e&&a.includes(" ")||ae(t,e,a,o,n)&&s(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&!u(n)&&tt(o,"multiple").forEach(e=>{l.length>4||e.value&&(h("cssSelector",e.value)||ae(t,"cssSelector",e.value,o,n)&&s(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const R=l.map(e=>({...e,value:E(e.value,e.name,e.isRecorded,n)})),T=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:R.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 T}}catch(e){console.error("Error processing locator:",r,e);continue}}catch(e){console.error("Error processing locator:",r,e);continue}return null};async function Nt(){return{fromHTML:async(n,r)=>{let a;if(["android","ios"].some(e=>String(r).toLowerCase().includes(e))){const t=new e(""),o=((e,t,n)=>{if(!n)return null;const r=(new n).parseFromString(e,t);if(r.querySelector("parsererror"))throw new Error("Invalid XML");return r})(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),"text/xml",t.window.DOMParser);if(!o)throw new Error(`Failed to parse ${r} XML`);a=o,global.document=o,global.Node=t.window.Node,global.Element=t.window.Element,global.HTMLElement=t.window.HTMLElement,global.XPathResult=t.window.XPathResult,global.SVGElement=t.window.SVGElement,global.XPathEvaluator=t.window.XPathEvaluator}else{const r=new t,o=new e(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"dangerously",resources:"usable",virtualConsole:r}),{window:l}=o;a=l.document,global.document=l.document,global.Node=l.Node,global.Element=l.Element,global.HTMLElement=l.HTMLElement,global.SVGElement=l.SVGElement;const s=l.CSS??{};s.escape||(s.escape=e=>String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")),global.CSS=s,global.XPathResult=l.XPathResult,global.XPathEvaluator=l.XPathEvaluator}return{autoHeal:async e=>bt(e,a,r)}}}}export{Nt as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ff-dom",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-beta.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "files": [