ff-dom 2.0.9 → 3.0.0-beta.2

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