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