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