ff-dom 2.0.7 → 2.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +1 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cdn.js +1 -1
- package/dist/types/browser/browser/xpath.d.ts +1 -1
- package/dist/types/browser/types/locator.d.ts +1 -0
- package/dist/types/browser/utils/cssSelector.d.ts +3 -2
- package/dist/types/browser/utils/xpathHelpers.d.ts +1 -1
- package/dist/types/node/types/locator.d.ts +1 -0
- package/dist/types/node/utils/cssSelector.d.ts +3 -2
- package/dist/types/node/utils/xpathHelpers.d.ts +1 -1
- package/dist/xpath.mjs +1 -1
- package/dist/xpath.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.cdn.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){"use strict";const t=/^[\S]+( [\S]+)*$/i;const n={};let a,l=new Map,r=[];const o=e=>/\d/.test(e),s=e=>{const t=e?.textContent;return t},i=e=>e?.childNodes[0]?.nodeValue||"",c=(e,t,a,l=!1)=>{try{let r;if(void 0!==n[e])r=n[e];else{r=(9===a.nodeType?a:a.ownerDocument).evaluate(`count(${e})`,a,null,XPathResult.NUMBER_TYPE,null).numberValue,n[e]=r}if(l&&Array.isArray(t)){if(r>1){const n=y(e,a,!0);let l,r=0;if(n instanceof XPathResult)for(;(l=n?.iterateNext())&&(!t.includes(l)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return y(e,a)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},u=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},f=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},m=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===c(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===c(`(${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===c(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===c(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},h=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(),g=e=>e?e.replace(/\s\s+/g," ").trim():e,d=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},p=(e,t,n)=>{if(!e?.value||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip"].some(t=>t===e.value))return!1;if(["type","style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const a=r?.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||!o(e.value))))},$=e=>e instanceof SVGElement,v=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,y=(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},N=(e,n,a,l,r,s)=>{if(l){const{tagName:i}=e;let f,m="";const h=[];let d;if(l&&(!s||!o(l))&&(d=t.test(l)?`//${i}[${a}=${u(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${u(g(l)).trim()}`,$(e),e.tagName.toLowerCase()),f=c(d,e,n),1===f&&!r))return d;if(l&&s){const o=l.split(" ");if(o?.length)if(1===o.length){const s=[...new Set(o[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&g(s[0].trim())?.length>1&&l.startsWith(s[0])&&(m=t.test(s[0])?`starts-with(${a},${u(s[0]).trim()})`:`starts-with(${a},${u(g(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&g(s[s.length-1].trim())?.length>1&&l.endsWith(s[s.length-1])&&(m=t.test(s[s.length-1])?`ends-with(${a},${u(s[s.length-1]).trim()})`:`ends-with(${a},${u(g(s[s.length-1])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d}else{const s=o.length%2==0?o.length/2:o.length%2,h=o.slice(0,s).join(" ");let p=[...new Set(h.match(/([^0-9]+)/g))];if(p?.length&&p[0]&&g(p[0].trim())?.length&&l.startsWith(p[0])&&(m=t.test(p[0])?`starts-with(${a},${u(p[0]).trim()})`:`starts-with(${a},${u(g(p[0])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d;const v=o.slice(s,o.length-1).join(" ");if(p=[...new Set(v.match(/([^0-9]+)/g))],p?.length&&p[0]&&g(p[0].trim())?.length>3&&l.endsWith(p[0])&&(m=t.test(p[0])?`ends-with(${a},${u(p[0]).trim()})`:`ends-with(${a},${u(g(p[0])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d}}if(l&&s&&o(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let e=0;e<o?.length;e++)o[e]&&g(o[e].trim())?.length>1&&(t.test(o[e])?h.push(`contains(${a},${u(o[e].trim()).trim()})`):h.push(`contains(${a},${u(g(o[e])).trim()})`));if(h?.length&&(d=$(e)?`//*[local-name()='${i}' and ${h.join(" and ")}]`:`//${i}[${h.join(" and ")}]`,f=c(d,e,n),1===f&&!r))return d}if(d=$(e)?`//*[local-name()='${i}' and text()]`:`//${i}[text()]`,f=c(d,e,n),1===f&&!r)return d}},b=(e,t)=>{try{if(!e)return"";let n=$(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 b(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},x=(e,t,n,a=!1,r)=>{try{if(l.has(e))return l.get(e);const s=[];let f=e;for(;f;){let l="",h=!1,d=e===f?r??f.attributes:f.attributes;for(const e of Array.from(d))if(p(e,f,a)){let a=e.nodeValue;a=a?.replace("removePointers","")??"";const r=e.name;l=C(f,r,a);let o=0;if(l&&(o=c(l,f,t),1===o)){s.unshift(v(l)),h=!0;break}if(o>1&&n&&(l=m(l,f,t,o),l)){s.unshift(v(l)),h=!0;break}}if(f.textContent)if(!a||a&&!o(f.textContent)){l=new RegExp(/^[\S]+( [\S]+)*$/gi).test(f.textContent)?$(f)?`//*[local-name()='${f.tagName}' and .=${u(i(f))}]`:`//${f.tagName||"*"}[.=${u(i(f))}]`:$(f)?`//*[local-name()='${f.tagName}' and normalize-space(.)=${u(i(f))}]`:`//${f.tagName||"*"}[normalize-space(.)=${u(i(f))}]`;let e=c(l,f,t);if(1===e)return l;if(e>1&&n)return l=m(l,f,t,e),l}else{let e=[];const a=[...new Set(i(f).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&g(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${u(a[t].trim()).trim()})`):e.push(`contains(.,${u(g(a[t])).trim()})`));if(e?.length){l=$(f)?`//*[local-name()='${f.tagName}' and ${e.join(" and ")}]`:`//${f.tagName||"*"}[${e.join(" and ")}]`;let a=c(l,f,t);if(1===a)return l;if(a>1&&n)return l=m(l,f,t,a),l}}if(h)break;{let e=$(f)?`/*[local-name()='${f.tagName}']`:`/${f.tagName}`;if(f.parentElement){const t=Array.from(f.parentElement.children).filter(e=>e.tagName===f.tagName);if(t.length>1){e+=`[${t.indexOf(f)+1}]`}}s.unshift(e)}f=f.parentElement}const h=`${s.join("")}`;return l.set(e,h),h}catch(e){return console.log(e),null}},E=(e,n)=>{const a=[];let l="";if(e&&!o(e.value)&&"function"!=typeof e.nodeValue){const r=[...new Set(e.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&g(r[n].trim())?.length>2&&(t.test(r[n])?a.push(`contains(@${e.name},${u(r[n].trim())})`):a.push(`contains(@${e.name},${u(g(r[n])).trim()})`));if(a?.length)return l=$(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},S=(e,n,a,l)=>{try{const r=[];if(a.length>1)for(const o of a)if(p(o,e,l)){const a=o.nodeValue;t.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=$(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let s;try{s=c(l,e,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)}'`)}},w=(e,n,a)=>{let l=$(e),r="";if(p(n,e,a)){let a=n.value;a=a.replace("removePointers","");const o=n.name;r=t.test(a)?l?`*[local-name()='${e.tagName}' and @${o}=${u(a)}]`:`${e.tagName||"*"}[@${o}=${u(a)}]`:l?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${u(a)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${u(a)}]`}return r},k=(e,n)=>{if(!e.textContent)return"";const a=i(e);let l;return l=t.test(a)?$(e)?`//*[local-name()='${e.tagName}' and .=${u(a)}]`:`//${e.tagName||"*"}[.=${u(a)}]`:$(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${u(a)}]`:`//${e.tagName||"*"}[normalize-space(.)=${u(a)}]`,l},R=e=>{const t=s(e)?.trim(),n=t?u(h(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},C=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.test(n)?"class"===t?$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`:$(e)?`//*[local-name()='${e.tagName}' and @${t}=${u(n)}]`:`//${e.tagName||"*"}[@${t}=${u(n)}]`:$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`),l},A=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,P=(e,n,a)=>{let l;const r=[];if(e.textContent&&(!a||a&&!o(e.textContent))&&(t.test(e.textContent)?(l=$(e)?`*[local-name()='${e.tagName}' and .=${u(s(e))}]`:`${e.tagName}[.=${u(s(e))}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})):(l=$(e)?`*[local-name()='${e.tagName}' and ${R(e)})]`:`${e.tagName}[${R(e)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))),e.attributes)for(const t of Array.from(e.attributes))if(p(t,e,a)){let n=t.nodeValue;if(n){n=n.replace("removePointers","");const a=t.name;l="class"===a?$(e)?`*[local-name()='${e.tagName}' and contains(@${a},${u(n)})]`:`${e.tagName}[contains(@${a},${u(n)})]`:$(e)?`*[local-name()='${e.tagName}' and @${a}=${u(n)}]`:`${e.tagName}[@${a}=${u(n)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})}}if(!r?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=S(e,n,Array.prototype.slice.call(e.attributes),a);t&&r.push({key:"getReferenceElementsXpath",value:t})}}if(!r?.length){const n=[];let l;const s=$(e);if(e.textContent&&a&&o(e.textContent)){const a=[...new Set(e.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let e=0;e<a?.length;e++)a[e]&&g(a[e].trim())?.length>1&&(t.test(a[e])?n.push(`contains(.,${u(a[e]).trim()})`):n.push(`contains(.,${u(g(a[e])).trim()})`));n?.length&&(l=s?`//*[local-name()='${s}' and ${n.join(" and ")}]`:`//${s}[${n.join(" and ")}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))}}if(!r?.length){const t=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(p(e,t,a)){const n=E(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(e.attributes,e,0,a);t?.length&&r.concat(t)}return r},D=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"),O=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function T(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 X(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function j(e,t,n){try{switch(t){case"id":return null!==e.getElementById(n)&&1===e.querySelectorAll(`#${X(n)}`).length;case"name":return 1===e.querySelectorAll(`[name="${X(n)}"]`).length;case"className":return 1===e.getElementsByClassName(n).length;case"tagName":return 1===e.getElementsByTagName(n).length;case"linkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.includes(n)).length;case"cssSelector":return 1===e.querySelectorAll(n).length;default:return!1}}catch{return!1}}const L={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:P,getAbsoluteXPath:b,getRelativeXPath:x,getCombinationXpath:E,getAttributeCombinationXpath:S,getElementFromXpath:y,isSvg:$,findXpathWithIndex:m,isNumberExist:o,getTextContent:s,getCountOfXPath:c,normalizeXPath:D,getShadowRoot:d,escapeCharacters:u,removeParenthesis:f,checkBlockedAttributes:p,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:O,deleteGarbageFromInnerText:h,replaceTempAttributes:v,createObserver:e=>{a=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&($(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)||r.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{a?.observe(e,t)},stopObserver:()=>{a?.disconnect()},modifiedElementAttributes:r,cspEnabled:!1,getXPathPattern:T,escapeAttrValue:X,isUniqueInDOM:j};let Y=[],_=[],q=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){q?.get(e)||q.set(e,c(e,n,a));const t=q?.get(e);if(1===t)return e;if(t>1&&(_.length?t<_[0].count&&(_.pop(),_.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):_.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!Y.length){const r=m(e,n,a,t);r&&1===c(r,n,a)&&Y.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},M=(e,n,a,l,r,s)=>{try{if(I.has(e))return I.get(e);const f=[];let m=e;for(;m&&1===m.nodeType;){const e=!1;for(const e of Array.from(m.attributes))if(p(e,m,l)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const l=e.name,o=C(m,l,t);let i;try{i=z(o,r,a,n,s,"parent")}catch(e){continue}if(i)return i}if(m.textContent&&!m.textContent)if(!l||l&&!o(m.textContent)){let e;e=t.test(m.textContent)?$(m)?`//*[local-name()='${m.tagName}' and .=${u(i(m))}]`:`//${m.tagName||"*"}[.=${u(i(m))}]`:$(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${u(i(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${u(i(m))}]`;const l=z(e,r,a,n,s,"parent");if(l)return l}else{const e=[],t=[...new Set(i(m).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&g(t[n].trim())&&(l.test(t[n])?e.push(`contains(.,${u(t[n].trim()).trim()})`):e.push(`contains(.,${u(g(t[n])).trim()})`));if(e?.length){const t=$(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`,l=z(t,r,a,n,s,"parent");if(l)return l}}if(!e){const e=$(m)?`/*[local-name()='${m.tagName}']`:`/${m.tagName}`;f.unshift(e)}m=m.parentElement}const h=f.join("")+r;if(1===c(h,e,n))return I.set(e,h),h}catch(e){return console.error(e),null}},W=(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(p(n,o,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,s=C(o,l,a);let i;try{i=c(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=k(o);if(n){if(1===c(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=$(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}},H=(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(p(n,l,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=C(l,o,r);let i;try{i=c(s,l,t)}catch(e){continue}if(1===i){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=k(l);if(n){if(1===c(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=$(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}},F=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)U(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)U(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},U=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=w(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=c(o,e,n);if(1===t)return void Y.push({key:`xpath by ${l}`,value:o});t>1&&(_.length?t<_[0].count&&(_.pop(),_.push({key:`relative xpath by ${l}`,value:o,count:t})):_.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=w(e,{name:"text",value:e.textContent},r),t){const a=c(t,e,n);if(1===a)return void Y.push({key:`xpath by ${l}`,value:t});a>1&&(_.length?a<_[0].count&&(_.pop(),_.push({key:`relative xpath by ${l}`,value:t,count:a})):_.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};function B(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();for(const o of e)if(p(o,t,a)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==c(a,t,n))return a}}}const G=(e,t,n,a,l)=>{try{let r,o,s=[];if(Y=[],console.log(l),l)for(const t of l){let n=w(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=w(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(!Y.length){if(F(e,t,a,s[l]),!Y.length&&(r||(r=W(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=c(a,e,t);if(1===o)Y.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=m(a,e,t,o);l&&1===c(l,e,t)&&Y.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!Y.length&&(o||(o=H(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=c(a,e,t);if(1===r)Y.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=m(a,e,t,r);l&&1===c(l,e,t)&&Y.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===Y?.length&&Y?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=K(e,t,n,!1);a&&Y.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!Y.length){let r=M(e.parentElement,t,e,a,s[l],n);r&&Y.push({key:"xpath by unique parent",value:r})}}return Y}catch(e){console.log(e)}},J=(e,t,n,a,l)=>{let r;return r=e.name,N(t,n,`@${r}`,e.value,a,l)},Z=(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 N(e,t,"@class",l,n,a)},K=(e,t,n,a)=>{if(""!=e.textContent){const l=s(e);if(l)return N(e,t,".",l,n,a)}},Q=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&p(e,t,l)){const r=J(e,t,n,a,l);r&&Y.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=K(t,n,a,l);if(o&&Y.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&p(r?.find(e=>"className"===e.name),t,l)){let e=Z(t,n,a,l);e&&Y.push({key:"xpath by class",value:e})}if(!Y.length){const a=B(e,t,n,l);a&&Y.push({key:"xpath by textAttribute",value:a})}if(!Y.length&&r.length>1){const e=S(t,n,r,l);e&&Y.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},ee=(e,t,n,a,l=[])=>{Y=[],console.log(e);const r=e,o=r?.ownerDocument||t,s=r.tagName,{attributes:i}=r,u=l.length>0?l:Array.from(i);if(Q(u,r,o,n,a),Y.length){const t=Y.length;for(let n=0;n<t;n++){let t=Y[n].value;t="//*"+t.substring(t.indexOf("//")+2+s.length);1===c(t,e,o)&&Y.push({key:`${Y[n].key} regex`,value:t})}}return Y.length||G(r,o,n,a,Array.from(r.attributes)),Y},te={parseDOM:ee,getTextXPath:K,getUniqueClassName:Z,attributesBasedXPath:J,addAllXPathAttributes:Q,addRelativeXpaths:G,getXPathUsingAttributeAndText:B,getSiblingRelativeXPath:F,getChildRelativeXpath:H,getParentRelativeXpath:W,getUniqueParentXpath:M,checkRelativeXpathRelation:z};let ne=[],ae=[];const le=/^[\S]+( [\S]+)*$/gi,re=(e,t,n,a,l,r,o,s=0,i=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)c.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const f=ie(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,l,i);if(f)return f}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${A(t,e[e.length-1])}`;let r=c(u,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:v(u)}];if(r>1&&l&&(u=m(u,e[e.length-1],a,r),u&&(r=c(u,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:v(u)}]}},oe=(e,t,n,a,l,r=!1,o=!1)=>{const i=e[e.length-2],c=e[e.length-1],f=d(c)??c.ownerDocument,m=n.find(e=>e?.key?.includes("absolute"))?.value||b(i,i.ownerDocument),h=[],g=[];m.split("/").map(e=>h.push(e)),h.map(e=>g.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=a.find(e=>e?.key?.includes("absolute"))?.value||b(c,c.ownerDocument),y=[],N=[];v.split("/").map(e=>y.push(e)),y.map(e=>N.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var x=0;x<h.length&&h[x]==y[x];x++);const S=[];for(let e=x-1;e<h.length;e++)h[e]&&S.push(g[e]);const w=[];for(let e="descendant"===l?x:x-1;e<y.length;e++)y[e]&&(w.length?w.push(N[e]):w.push(N[e].replace(/\[([0-9]+)\]/gm,"")));let k;if(ae=a,e[e.length-2].textContent){k=le.test(e[e.length-2].textContent)?$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${u(s(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${u(s(e[e.length-2]))}]`:$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${R(e[e.length-2])})]`:`${e[e.length-2].tagName}[${R(e[e.length-2])}]`,S[S.length-1]=k;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;if(s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,s)return re(e,s,l,f||t,r,w,i,a,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=n.name;k=$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${u(a)}]`:`${e[e.length-2].tagName}[@${s}=${u(a)}]`,S[S.length-1]=k;const i=S.join("["),c=S.length-1,m=i;for(let n=0;n<ae.length;n++){let a;return a=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,a,l,f||t,r,w,m,c,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=E(n,e[e.length-2]);if(s){k=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,S[S.length-1]=k;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;return s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,s,l,f||t,r,w,i,a,o)}}}}}const C=S.join("["),A=S.length-1,P=ie(`${C+(A?"]".repeat(A):"")}`,w,e[e.length-1],e,t,l,r,o);if(P)return P},se=(e,t,n,a,l,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const u=[];try{s=a.filter(e=>!e?.key?.includes("absolute")),i=l.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let a=0;a<i.length;a++){let l=`//${0!==s[e].value.indexOf("//")?A(s[e].value):A(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[a].value.indexOf("//")?A(i[a].value):A(i[a].value.substring(i[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=c(l,t,t.ownerDocument);if(o>1)if(r){if(l=m(l,t,t.ownerDocument,o),l)return u.push({key:`dynamic ${n}${r?" index":""}`,value:v(l)}),u}else o>1&&(ne.length?o<ne[0].count&&(ne.pop(),ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:v(l)}),u}if(!u.length)for(let a=0;a<s.length;a++)for(let l=0;l<i.length;l++){const c=`${0!==i[l].value.indexOf("//")?i[l].value:i[l].value.substring(i[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(c.length>1){const l=ie(`${0!==s[a].value.indexOf("//")?A(s[a].value):A(s[a].value.substring(s[a].value.indexOf("//")+2))}`,c,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},ie=(e,t,n,a,l,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${A(s)}`;const u=c(i,n,l);if(1===u)return[{key:`dynamic ${r}`,value:v(i)}];if(u>1&&o&&(i=m(i,a[a.length-1],l,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${A(u)}`;const f=c(i,n,l);if(1===f)return[{key:`dynamic ${r}`,value:v(i)}];if(f>1&&o&&(i=m(i,a[a.length-1],l,f),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}},ce={findRelativeXpath:(e,t,n,a,l,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],f=[];if(r&&ne.length){const e=m(ne[0].value,t,t.ownerDocument,ne[0].count);e&&(f=f.concat({key:`${ne[0]?.key?ne[0]?.key:"xpath with "} index`,value:e}),ne.pop())}if(!f.length){for(e.isSameNode(t)&&(u=se(e,t,"self",a,l,r,o),u&&(f=f.concat(u))),c=e.parentElement,c===t&&(u=se(e,t,"parent",a,l,r,o),u&&(f=f.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=se(e,t,"ancestor",a,l,r,o),u)){f=f.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=se(e,t,"ancestor-or-self",a,l,r,o),u)){f=f.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=se(e,t,"following-sibling",a,l,r,o),u)){f=f.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=se(e,t,"preceding-sibling",a,l,r,o),u)){f=f.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=se(e,t,"child",a,l,r,o),u)){f=f.concat(u);break}const m=e.compareDocumentPosition(t);2===m&&(u=se(e,t,"preceding",a,l,r,o)),4===m&&(u=se(e,t,"following",a,l,r,o)),u&&(f=f.concat(u));const h=oe([e,t],n,a,l,"descendant",r,o);h&&(f=f.concat(h));const g=oe([e,t],n,a,l,"descendant-or-self",r,o);g&&(f=f.concat(g))}if(f.length)return f.length>1&&f.sort(function(e,t){return e.value.length-t.value.length}),f.filter(e=>!e.key?.includes("index"))?.length?[f.filter(e=>!e.key?.includes("index"))[0]]:[f[0]]},getDescendantXpath:oe,getXpathRelationExpression:se,getTraverseXpathExpression:ie,getReferenceElementXpath:e=>{let t=[];if(t=ee(e,e.ownerDocument,!1,!1),t?.length){let n=ee(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=ee(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(e.value)}:{key:"",value:e.value});if(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)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(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=b(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}};let ue=[];const fe=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},me=e=>{const t=[],n=e.getRootNode();try{const a=he(e);if(a&&fe(a,e,n))return t.push({key:"cssSelector by id",value:a}),t;const l=pe(e);l&&fe(l,e,n)&&t.push({key:"cssSelector by class",value:l});const r=de(e);r&&t.push({key:"cssSelector by name",value:r});const o=$e(e);o&&fe(o,e,n)&&t.push({key:"Absolute cssSelector",value:o})}catch(e){console.error(e)}return t},he=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&&!o(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(" > ")},ge=new Set(["id","class","style"]);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=function(e){return Array.from(e.attributes).filter(e=>!ge.has(e?.name?.toLowerCase())&&e.value&&!o(e.value)).map(e=>`[${e.name}="${CSS.escape(e.value)}"]`)}(e);for(const t of l){const l=`${a}${t}`;if(fe(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||o(e.className)||ue?.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:me,getIdCssPath:he,getAttributeCssPath:de,getClassCssPath:pe,getAbsoluteCssPath:$e},ye=(e,t,n)=>{const a=D(e);if(Ae(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,we=e=>e.className||null,ke=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 Ae(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 Pe(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 r(e,t={}){const n=e?.value,r=t.value??e?.value,o={name:t.name??e?.name,type:t.type??e?.type,value:t.value??e?.value,reference:t.reference??e?.reference,status:t.status??e?.status,isRecorded:t.isRecorded??e?.isRecorded},s="Y"===e?.isSelfHealed;o.isSelfHealed=s?"Y":t.hasOwnProperty("isSelfHealed")?t.isSelfHealed:((e,t,n)=>t&&n&&t===n?null:"Y")(o.name,n,r),function(e){const t=`${e.name}:${e.value}`;a.has(t)||(a.add(t),l.push(e))}(o)}const s=(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 i=e.locators.filter(e=>"N"===e.isRecorded);if(i.length>0)for(const e of i)r(e);const c=String(n.value||n.type||"");if(c.includes("dynamic")||c.match("dynamic")||c.includes("{")||c.includes("}")){r(n);continue}if(e.isShared.includes("Y"))break e;try{let i=null;if(n.value.startsWith("iframe")){const e=t.querySelector(n.value);if(e){const t=e.contentDocument||e.contentWindow?.document;t&&(i=t.querySelector(n.value.slice(6)))}}else{const e=n.value.split(">>>");for(const a of e){if(!t){console.error("Element not found at:",a);break}{const e=a.trim();if(xe(n))i=Ne(t,e);else if(n.name.includes("id")||e.startsWith("#"))i=t.querySelector("#"+X(e));else if(n.name.includes("className")||e.startsWith("."))i=t.querySelector("."+e);else if("name"===n.name){const n=X(e);i=t.querySelector(`[name="${n}"]`)}else if("tagName"===n.name)i=t.querySelector(e);else if("linkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.trim()===e)||null;else if("partialLinkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.includes(e))||null;else if(!n.name.includes("xpath")&&!e.startsWith("//")||n.type.match("dynamic"))i=t.querySelector(e),i||(i=Ee(t.body,e));else{const a=D(e);i=Ae(t,a),i&&r(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const c=(e,t)=>{const n=`${e}:${t}`;return a.has(n)};if(i){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,i)&&r(e,{isSelfHealed:null});for(const e of a)be(e.value,t,i)&&r(e,{isSelfHealed:null});const u=l.filter(e=>"xpath"===e.name&&e.value),f=new Set(u.map(e=>T(e.value))),m=[],h=Se(i);if(h&&!c("id",h)&&!o(h)){const n=e.locators.find(e=>"id"===e.name);j(t,"id",h)&&(m.push("id"),r(n,{name:"id",type:"static",isRecorded:"Y",value:h}))}const g=i.tagName;if(g&&!c("tagName",g)){const n=e.locators.find(e=>"tagName"===e.name);j(t,"tagName",g)&&(m.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:g}))}const d=ke(i);if(d&&!o(d)){const n=e.locators.find(e=>"linkText"===e.name);j(t,"linkText",d)&&(m.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:d}))}const p=Re(i);if(p&&!c("name",p)&&!o(p)){const n=e.locators.find(e=>"name"===e.name);j(t,"name",p)&&(m.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=we(i);if($&&""!==$.trim()&&!$.includes(" ")&&!c("className",$)&&!o($)){const n=e.locators.find(e=>"className"===e.name);j(t,"className",$)&&(m.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}me(i).forEach(e=>{e.value&&!c("cssSelector",e.value)&&j(t,"cssSelector",e.value)&&r(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const v=Array.from(i.attributes).filter(e=>!m.includes(e.name));let y=[];try{y=ee(i,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,i));let a=0;for(const t of e){if(a>=e.length)break;const n=T(t.value);if(f.has(n))continue;const l=y.find(e=>e.value&&T(e.value)===n);l?.value&&(r(t,{name:"xpath",value:l.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),f.add(n),a++)}if(a<e.length)for(const t of y){if(a>=e.length)break;if(!t.value)continue;const n=T(t.value);f.has(n)||(r(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),f.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=Pe(a.value,e,t);if(l){r(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(i)},{name:"name",value:Re(i)},{name:"className",value:we(i)},{name:"tagName",value:i.tagName},{name:"linkText",value:ke(i)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(o(a)||c(e,a)||"className"===e&&a.includes(" ")||j(t,e,a)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}}const N=l.map(e=>({...e,value:s(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:te,referenceXpaths:ce,xpathUtils:L,getElementsFromHTML:De,cssSelectors:ve});e.createXPathAPI=Oe,e.default=Oe,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
|
|
1
|
+
!function(e){"use strict";const t=/^[\S]+( [\S]+)*$/i;const n={};let a,l=new Map,r=[];const o=e=>/\d/.test(e),s=e=>{const t=e?.textContent;return t},i=e=>e?.childNodes[0]?.nodeValue||"",c=(e,t,a,l=!1)=>{try{let r;if(void 0!==n[e])r=n[e];else{r=(9===a.nodeType?a:a.ownerDocument).evaluate(`count(${e})`,a,null,XPathResult.NUMBER_TYPE,null).numberValue,n[e]=r}if(l&&Array.isArray(t)){if(r>1){const n=y(e,a,!0);let l,r=0;if(n instanceof XPathResult)for(;(l=n?.iterateNext())&&(!t.includes(l)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return y(e,a)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},u=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},f=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},m=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===c(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===c(`(${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===c(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===c(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},h=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(),g=e=>e?e.replace(/\s\s+/g," ").trim():e,d=e=>{if(!e||!e?.getRootNode)return null;const t=e.getRootNode();return t&&t?.host?t:null},p=(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=r?.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||!o(e.value))))},$=e=>e instanceof SVGElement,v=e=>e?e.replace(/\b[a-zA-Z_]*disabled\b/gi,"disabled"):e,y=(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},N=(e,n,a,l,r,s)=>{if(l){const{tagName:i}=e;let f,m="";const h=[];let d;if(l&&(!s||!o(l))&&(d=t.test(l)?`//${i}[${a}=${u(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${u(g(l)).trim()}`,$(e),e.tagName.toLowerCase()),f=c(d,e,n),1===f&&!r))return d;if(l&&s){const o=l.split(" ");if(o?.length)if(1===o.length){const s=[...new Set(o[0].match(/([^0-9]+)/g))];if(s?.length>=1&&s[0]&&g(s[0].trim())?.length>1&&l.startsWith(s[0])&&(m=t.test(s[0])?`starts-with(${a},${u(s[0]).trim()})`:`starts-with(${a},${u(g(s[0])).trim()})`),s?.length>1&&s[s.length-1]&&g(s[s.length-1].trim())?.length>1&&l.endsWith(s[s.length-1])&&(m=t.test(s[s.length-1])?`ends-with(${a},${u(s[s.length-1]).trim()})`:`ends-with(${a},${u(g(s[s.length-1])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d}else{const s=o.length%2==0?o.length/2:o.length%2,h=o.slice(0,s).join(" ");let p=[...new Set(h.match(/([^0-9]+)/g))];if(p?.length&&p[0]&&g(p[0].trim())?.length&&l.startsWith(p[0])&&(m=t.test(p[0])?`starts-with(${a},${u(p[0]).trim()})`:`starts-with(${a},${u(g(p[0])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d;const v=o.slice(s,o.length-1).join(" ");if(p=[...new Set(v.match(/([^0-9]+)/g))],p?.length&&p[0]&&g(p[0].trim())?.length>3&&l.endsWith(p[0])&&(m=t.test(p[0])?`ends-with(${a},${u(p[0]).trim()})`:`ends-with(${a},${u(g(p[0])).trim()})`),m?.length&&(d=$(e)?`//*[local-name()='${i}' and ${m}]`:`//${i}[${m}]`,f=c(d,e,n),1===f&&!r))return d}}if(l&&s&&o(l)){const o=[...new Set(l.match(/([^0-9]+)/g))];if(o?.length)for(let e=0;e<o?.length;e++)o[e]&&g(o[e].trim())?.length>1&&(t.test(o[e])?h.push(`contains(${a},${u(o[e].trim()).trim()})`):h.push(`contains(${a},${u(g(o[e])).trim()})`));if(h?.length&&(d=$(e)?`//*[local-name()='${i}' and ${h.join(" and ")}]`:`//${i}[${h.join(" and ")}]`,f=c(d,e,n),1===f&&!r))return d}if(d=$(e)?`//*[local-name()='${i}' and text()]`:`//${i}[text()]`,f=c(d,e,n),1===f&&!r)return d}},b=(e,t)=>{try{if(!e)return"";let n=$(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 b(e?.parentElement,t)+n}catch(e){return console.log("xpath",e),""}},x=(e,t,n,a=!1,r)=>{try{if(l.has(e))return l.get(e);const s=[];let f=e;for(;f;){let l="",h=!1,d=e===f?r??f.attributes:f.attributes;for(const e of Array.from(d))if(p(e,f,a)){let a=e.nodeValue;a=a?.replace("removePointers","")??"";const r=e.name;l=C(f,r,a);let o=0;if(l&&(o=c(l,f,t),1===o)){s.unshift(v(l)),h=!0;break}if(o>1&&n&&(l=m(l,f,t,o),l)){s.unshift(v(l)),h=!0;break}}if(f.textContent)if(!a||a&&!o(f.textContent)){l=new RegExp(/^[\S]+( [\S]+)*$/gi).test(f.textContent)?$(f)?`//*[local-name()='${f.tagName}' and .=${u(i(f))}]`:`//${f.tagName||"*"}[.=${u(i(f))}]`:$(f)?`//*[local-name()='${f.tagName}' and normalize-space(.)=${u(i(f))}]`:`//${f.tagName||"*"}[normalize-space(.)=${u(i(f))}]`;let e=c(l,f,t);if(1===e)return l;if(e>1&&n)return l=m(l,f,t,e),l}else{let e=[];const a=[...new Set(i(f).match(/([^0-9]+)/g))];let r=new RegExp(/^[\S]+( [\S]+)*$/gi);if(a?.length)for(let t=0;t<a?.length;t++)a[t]&&g(a[t].trim())&&(r.test(a[t])?e.push(`contains(.,${u(a[t].trim()).trim()})`):e.push(`contains(.,${u(g(a[t])).trim()})`));if(e?.length){l=$(f)?`//*[local-name()='${f.tagName}' and ${e.join(" and ")}]`:`//${f.tagName||"*"}[${e.join(" and ")}]`;let a=c(l,f,t);if(1===a)return l;if(a>1&&n)return l=m(l,f,t,a),l}}if(h)break;{let e=$(f)?`/*[local-name()='${f.tagName}']`:`/${f.tagName}`;if(f.parentElement){const t=Array.from(f.parentElement.children).filter(e=>e.tagName===f.tagName);if(t.length>1){e+=`[${t.indexOf(f)+1}]`}}s.unshift(e)}f=f.parentElement}const h=`${s.join("")}`;return l.set(e,h),h}catch(e){return console.log(e),null}},E=(e,n)=>{const a=[];let l="";if(e&&!o(e.value)&&"function"!=typeof e.nodeValue){const r=[...new Set(e.value.match(/([^0-9]+)/g))];if(r?.length)for(let n=0;n<r?.length;n++)r[n]&&g(r[n].trim())?.length>2&&(t.test(r[n])?a.push(`contains(@${e.name},${u(r[n].trim())})`):a.push(`contains(@${e.name},${u(g(r[n])).trim()})`));if(a?.length)return l=$(n)?`//*[local-name()='${n.tagName}' and ${a.join(" and ")}]`:`//${n.tagName}[${a.join(" and ")}]`,l}},S=(e,n,a,l)=>{try{const r=[];if(a.length>1)for(const o of a)if(p(o,e,l)){const a=o.nodeValue;t.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=$(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let s;try{s=c(l,e,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)}'`)}},k=(e,n,a)=>{let l=$(e),r="";if(p(n,e,a)){let a=n.value;a=a.replace("removePointers","");const o=n.name;r=t.test(a)?l?`*[local-name()='${e.tagName}' and @${o}=${u(a)}]`:`${e.tagName||"*"}[@${o}=${u(a)}]`:l?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${u(a)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${u(a)}]`}return r},w=(e,n)=>{if(!e.textContent)return"";const a=i(e);let l;return l=t.test(a)?$(e)?`//*[local-name()='${e.tagName}' and .=${u(a)}]`:`//${e.tagName||"*"}[.=${u(a)}]`:$(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${u(a)}]`:`//${e.tagName||"*"}[normalize-space(.)=${u(a)}]`,l},R=e=>{const t=s(e)?.trim(),n=t?u(h(t)):t;if(n)return n!==`'${t}'`?`contains(.,${n})`:`normalize-space(.)='${t}'`},C=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.test(n)?"class"===t?$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`:$(e)?`//*[local-name()='${e.tagName}' and @${t}=${u(n)}]`:`//${e.tagName||"*"}[@${t}=${u(n)}]`:$(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${u(n)})]`:`//${e.tagName||"*"}[contains(@${t},${u(n)})]`),l},P=(e,t)=>e?e.replace(/\bdisabled\b/gi,"flndisabled"):e,A=(e,n,a)=>{let l;const r=[];if(e.textContent&&(!a||a&&!o(e.textContent))&&(t.test(e.textContent)?(l=$(e)?`*[local-name()='${e.tagName}' and .=${u(s(e))}]`:`${e.tagName}[.=${u(s(e))}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})):(l=$(e)?`*[local-name()='${e.tagName}' and ${R(e)})]`:`${e.tagName}[${R(e)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))),e.attributes)for(const t of Array.from(e.attributes))if(p(t,e,a)){let n=t.nodeValue;if(n){n=n.replace("removePointers","");const a=t.name;l="class"===a?$(e)?`*[local-name()='${e.tagName}' and contains(@${a},${u(n)})]`:`${e.tagName}[contains(@${a},${u(n)})]`:$(e)?`*[local-name()='${e.tagName}' and @${a}=${u(n)}]`:`${e.tagName}[@${a}=${u(n)}]`,l&&r.push({key:"getReferenceElementsXpath",value:l})}}if(!r?.length){const t=Array.prototype.slice.call(e.attributes);if(t?.length>1){const t=S(e,n,Array.prototype.slice.call(e.attributes),a);t&&r.push({key:"getReferenceElementsXpath",value:t})}}if(!r?.length){const n=[];let l;const s=$(e);if(e.textContent&&a&&o(e.textContent)){const a=[...new Set(e.textContent.match(/([^0-9]+)/g))];if(a?.length)for(let e=0;e<a?.length;e++)a[e]&&g(a[e].trim())?.length>1&&(t.test(a[e])?n.push(`contains(.,${u(a[e]).trim()})`):n.push(`contains(.,${u(g(a[e])).trim()})`));n?.length&&(l=s?`//*[local-name()='${s}' and ${n.join(" and ")}]`:`//${s}[${n.join(" and ")}]`,l&&r.push({key:"getReferenceElementsXpath",value:l}))}}if(!r?.length){const t=((e,t,n,a)=>{const l=Array.prototype.slice.call(e),r=[];try{l.map(e=>{if(p(e,t,a)){const n=E(e,t);n&&r.push({key:`split xpath by ${e.name}`,value:n})}})}catch(e){console.log(e)}return r})(e.attributes,e,0,a);t?.length&&r.concat(t)}return r},D=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"),O=(e,t)=>{let n=t,a=1;for(;a>0;){const t=e[++n];"("==t?a++:")"==t&&a--}return n};function X(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 j(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 L={parseXml:(e,t)=>window.DOMParser?(new window.DOMParser).parseFromString(e,t):null,getReferenceElementsXpath:A,getAbsoluteXPath:b,getRelativeXPath:x,getCombinationXpath:E,getAttributeCombinationXpath:S,getElementFromXpath:y,isSvg:$,findXpathWithIndex:m,isNumberExist:o,getTextContent:s,getCountOfXPath:c,normalizeXPath:D,getShadowRoot:d,escapeCharacters:u,removeParenthesis:f,checkBlockedAttributes:p,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:O,deleteGarbageFromInnerText:h,replaceTempAttributes:v,createObserver:e=>{a=new MutationObserver(t=>{t.forEach(t=>{t?.addedNodes?.length&&e(t?.addedNodes),t.target instanceof HTMLElement&&("attributes"===t?.type&&"class"===t.attributeName&&($(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)||r.push({url:t.target.baseURI,attributeName:t.attributeName,element:t.target,doc:t.target.ownerDocument}))})})},startObserver:(e,t)=>{a?.observe(e,t)},stopObserver:()=>{a?.disconnect()},modifiedElementAttributes:r,cspEnabled:!1,getXPathPattern:X,escapeAttrValue:T,isUniqueInDOM:j};let Y=[],_=[],V=new Map,I=new Map;const z=new Map,q=(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){V?.get(e)||V.set(e,c(e,n,a));const t=V?.get(e);if(1===t)return e;if(t>1&&(_.length?t<_[0].count&&(_.pop(),_.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):_.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!Y.length){const r=m(e,n,a,t);r&&1===c(r,n,a)&&Y.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},M=(e,n,a,l,r,s)=>{try{if(z.has(e))return z.get(e);const f=[];let m=e;for(;m&&1===m.nodeType;){const e=!1;for(const e of Array.from(m.attributes))if(p(e,m,l)){let t=e.nodeValue;t=t?.replace("removePointers","")??"";const l=e.name,o=C(m,l,t);let i;try{i=q(o,r,a,n,s,"parent")}catch(e){continue}if(i)return i}if(m.textContent&&!m.textContent)if(!l||l&&!o(m.textContent)){let e;e=t.test(m.textContent)?$(m)?`//*[local-name()='${m.tagName}' and .=${u(i(m))}]`:`//${m.tagName||"*"}[.=${u(i(m))}]`:$(m)?`//*[local-name()='${m.tagName}' and normalize-space(.)=${u(i(m))}]`:`//${m.tagName||"*"}[normalize-space(.)=${u(i(m))}]`;const l=q(e,r,a,n,s,"parent");if(l)return l}else{const e=[],t=[...new Set(i(m).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(t?.length)for(let n=0;n<t?.length;n++)t[n]&&g(t[n].trim())&&(l.test(t[n])?e.push(`contains(.,${u(t[n].trim()).trim()})`):e.push(`contains(.,${u(g(t[n])).trim()})`));if(e?.length){const t=$(m)?`//*[local-name()='${m.tagName}' and ${e.join(" and ")}]`:`//${m.tagName||"*"}[${e.join(" and ")}]`,l=q(t,r,a,n,s,"parent");if(l)return l}}if(!e){const e=$(m)?`/*[local-name()='${m.tagName}']`:`/${m.tagName}`;f.unshift(e)}m=m.parentElement}const h=f.join("")+r;if(1===c(h,e,n))return z.set(e,h),h}catch(e){return console.error(e),null}},W=(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(p(n,o,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,s=C(o,l,a);let i;try{i=c(s,o,t)}catch(e){continue}if(1===i){r.unshift(s),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=w(o);if(n){if(1===c(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=$(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}},H=(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(p(n,l,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,s=C(l,o,r);let i;try{i=c(s,l,t)}catch(e){continue}if(1===i){e=!0,a.push(s);break}}if(!e&&l.textContent&&!n.textContent){const n=w(l);if(n){if(1===c(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=$(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 I.set(e,o),o}catch(e){return console.log(e),null}},F=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)U(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)U(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},U=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=k(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=c(o,e,n);if(1===t)return void Y.push({key:`xpath by ${l}`,value:o});t>1&&(_.length?t<_[0].count&&(_.pop(),_.push({key:`relative xpath by ${l}`,value:o,count:t})):_.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=k(e,{name:"text",value:e.textContent},r),t){const a=c(t,e,n);if(1===a)return void Y.push({key:`xpath by ${l}`,value:t});a>1&&(_.length?a<_[0].count&&(_.pop(),_.push({key:`relative xpath by ${l}`,value:t,count:a})):_.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};function B(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();for(const o of e)if(p(o,t,a)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a){if(1==c(a,t,n))return a}}}const G=(e,t,n,a,l)=>{try{let r,o,s=[];if(Y=[],console.log(l),l)for(const t of l){let n=k(e,{name:t.name,value:t.value},a);console.log(n),n&&s.push(n)}if(e.textContent){let t=k(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(!Y.length){if(F(e,t,a,s[l]),!Y.length&&(r||(r=W(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=c(a,e,t);if(1===o)Y.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=m(a,e,t,o);l&&1===c(l,e,t)&&Y.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!Y.length&&(o||(o=H(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${s[l]+o.substring(1)}`,r=c(a,e,t);if(1===r)Y.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=m(a,e,t,r);l&&1===c(l,e,t)&&Y.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===Y?.length&&Y?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=K(e,t,n,!1);a&&Y.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!Y.length){let r=M(e.parentElement,t,e,a,s[l],n);r&&Y.push({key:"xpath by unique parent",value:r})}}return Y}catch(e){console.log(e)}},J=(e,t,n,a,l)=>{let r;return r=e.name,N(t,n,`@${r}`,e.value,a,l)},Z=(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 N(e,t,"@class",l,n,a)},K=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const l=s(e);if(l)return N(e,t,".",l,n,a)}},Q=(e,t,n,a,l)=>{const r=e;try{r.map(e=>{if("className"!==e.name&&"class"!==e.name&&p(e,t,l)){const r=J(e,t,n,a,l);r&&Y.push({key:`xpath by ${e.name}${a?" index":""}`,value:r})}});const o=K(t,n,a,l);if(o&&Y.push({key:"xpath by text"+(a?" index":""),value:o}),r.find(e=>"className"===e.name)&&p(r?.find(e=>"className"===e.name),t,l)){let e=Z(t,n,a,l);e&&Y.push({key:"xpath by class",value:e})}if(!Y.length){const a=B(e,t,n,l);a&&Y.push({key:"xpath by textAttribute",value:a})}if(!Y.length&&r.length>1){const e=S(t,n,r,l);e&&Y.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},ee=(e,t,n,a,l=[])=>{Y=[],console.log(e);const r=e,o=r?.ownerDocument||t,s=r.tagName,{attributes:i}=r,u=l.length>0?l:Array.from(i);if(Q(u,r,o,n,a),Y.length){const t=Y.length;for(let n=0;n<t;n++){let t=Y[n].value;t="//*"+t.substring(t.indexOf("//")+2+s.length);1===c(t,e,o)&&Y.push({key:`${Y[n].key} regex`,value:t})}}return Y.length||G(r,o,n,a,Array.from(r.attributes)),Y},te={parseDOM:ee,getTextXPath:K,getUniqueClassName:Z,attributesBasedXPath:J,addAllXPathAttributes:Q,addRelativeXpaths:G,getXPathUsingAttributeAndText:B,getSiblingRelativeXPath:F,getChildRelativeXpath:H,getParentRelativeXpath:W,getUniqueParentXpath:M,checkRelativeXpathRelation:q};let ne=[],ae=[];const le=/^[\S]+( [\S]+)*$/gi,re=(e,t,n,a,l,r,o,s=0,i=!1)=>{let u="";if(t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g)?.length>=r.length){const c=[],u=t.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);for(let e=1;e<=r.length;e++)c.unshift(e===r.length?r[r.length-e]:u[u.length-e]);const f=ie(`${o+(s?"]".repeat(s):"")}`,c,e[e.length-1],e,a,n,l,i);if(f)return f}else{u=`//${o+(s?"]".repeat(s):"")}/${n}::${P(t,e[e.length-1])}`;let r=c(u,e[e.length-1],a);if(1===r)return[{key:`dynamic ${n}`,value:v(u)}];if(r>1&&l&&(u=m(u,e[e.length-1],a,r),u&&(r=c(u,e[e.length-1],a),1===r)))return[{key:`dynamic ${n} ${l?" index":""}`,value:v(u)}]}},oe=(e,t,n,a,l,r=!1,o=!1)=>{const i=e[e.length-2],c=e[e.length-1],f=d(c)??c.ownerDocument,m=n.find(e=>e?.key?.includes("absolute"))?.value||b(i,i.ownerDocument),h=[],g=[];m.split("/").map(e=>h.push(e)),h.map(e=>g.push(e.replace(/\[([0-9]+)\]/gm,"")));const v=a.find(e=>e?.key?.includes("absolute"))?.value||b(c,c.ownerDocument),y=[],N=[];v.split("/").map(e=>y.push(e)),y.map(e=>N.push(e.replace(/\[([0-9]+)\]/gm,"")));for(var x=0;x<h.length&&h[x]==y[x];x++);const S=[];for(let e=x-1;e<h.length;e++)h[e]&&S.push(g[e]);const k=[];for(let e="descendant"===l?x:x-1;e<y.length;e++)y[e]&&(k.length?k.push(N[e]):k.push(N[e].replace(/\[([0-9]+)\]/gm,"")));let w;if(ae=a,e[e.length-2].textContent){w=le.test(e[e.length-2].textContent)?$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and .=${u(s(e[e.length-2]))}]`:`${e[e.length-2].tagName}[.=${u(s(e[e.length-2]))}]`:$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and ${R(e[e.length-2])})]`:`${e[e.length-2].tagName}[${R(e[e.length-2])}]`,S[S.length-1]=w;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;if(s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,s)return re(e,s,l,f||t,r,k,i,a,o)}}if(e[e.length-2].attributes){for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=n.name;w=$(e[e.length-2])?`*[local-name()='${e[e.length-2].tagName}' and @${s}=${u(a)}]`:`${e[e.length-2].tagName}[@${s}=${u(a)}]`,S[S.length-1]=w;const i=S.join("["),c=S.length-1,m=i;for(let n=0;n<ae.length;n++){let a;return a=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,a,l,f||t,r,k,m,c,o)}}}for(const n of Array.from(e[e.length-2].attributes))if(p(n,e[e.length-2],!1)){let a=n.nodeValue;if(a){a=a.replace("removePointers","");const s=E(n,e[e.length-2]);if(s){w=s.startsWith("//")?s.substring(s.indexOf("//")+2):s,S[S.length-1]=w;const n=S.join("["),a=S.length-1,i=n;for(let n=0;n<ae.length;n++){let s;return s=ae[n].value.startsWith("//")?ae[n].value.substring(ae[n].value.indexOf("//")+2):ae[n].value,re(e,s,l,f||t,r,k,i,a,o)}}}}}const C=S.join("["),P=S.length-1,A=ie(`${C+(P?"]".repeat(P):"")}`,k,e[e.length-1],e,t,l,r,o);if(A)return A},se=(e,t,n,a,l,r,o)=>{let s,i;console.log("getXpathRelationExpression",n);const u=[];try{s=a.filter(e=>!e?.key?.includes("absolute")),i=l.filter(e=>!e?.key?.includes("absolute"));for(let e=0;e<s.length;e++)for(let a=0;a<i.length;a++){let l=`//${0!==s[e].value.indexOf("//")?P(s[e].value):P(s[e].value.substring(s[e].value.indexOf("//")+2))}/${n}::${0!==i[a].value.indexOf("//")?P(i[a].value):P(i[a].value.substring(i[a].value.indexOf("//")+2))}`;console.log("getXpathRelationExpression",l);const o=c(l,t,t.ownerDocument);if(o>1)if(r){if(l=m(l,t,t.ownerDocument,o),l)return u.push({key:`dynamic ${n}${r?" index":""}`,value:v(l)}),u}else o>1&&(ne.length?o<ne[0].count&&(ne.pop(),ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o})):ne.push({key:"relative xpath by relative child "+(r?"index":""),value:l,count:o}));else if(1===o)return u.push({key:`dynamic ${n}`,value:v(l)}),u}if(!u.length)for(let a=0;a<s.length;a++)for(let l=0;l<i.length;l++){const c=`${0!==i[l].value.indexOf("//")?i[l].value:i[l].value.substring(i[l].value.indexOf("//")+2)}`.split(/\/(?=(?:[^']*\'[^\']*\')*[^\']*$)/g);if(c.length>1){const l=ie(`${0!==s[a].value.indexOf("//")?P(s[a].value):P(s[a].value.substring(s[a].value.indexOf("//")+2))}`,c,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},ie=(e,t,n,a,l,r,o,s)=>{let i;if(s){const s=t.join("/");i=`//${e}/${r}::${P(s)}`;const u=c(i,n,l);if(1===u)return[{key:`dynamic ${r}`,value:v(i)}];if(u>1&&o&&(i=m(i,a[a.length-1],l,u),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}else for(let s=1;s<=t.length;s++){const u=t.slice(t.length-s,t.length).join("/");i=`//${e}/${r}::${P(u)}`;const f=c(i,n,l);if(1===f)return[{key:`dynamic ${r}`,value:v(i)}];if(f>1&&o&&(i=m(i,a[a.length-1],l,f),i))return[{key:`dynamic ${r}${o?" index":""}`,value:v(i)}]}},ce={findRelativeXpath:(e,t,n,a,l,r,o=!1)=>{const s=e.parentElement,i=t.parentElement;let c,u=[],f=[];if(r&&ne.length){const e=m(ne[0].value,t,t.ownerDocument,ne[0].count);e&&(f=f.concat({key:`${ne[0]?.key?ne[0]?.key:"xpath with "} index`,value:e}),ne.pop())}if(!f.length){for(e.isSameNode(t)&&(u=se(e,t,"self",a,l,r,o),u&&(f=f.concat(u))),c=e.parentElement,c===t&&(u=se(e,t,"parent",a,l,r,o),u&&(f=f.concat(u))),c=e.parentElement;null!==c;){if(c===t&&(u=se(e,t,"ancestor",a,l,r,o),u)){f=f.concat(u);break}c=c.parentNode}c=e;do{if(c===t&&(u=se(e,t,"ancestor-or-self",a,l,r,o),u)){f=f.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=se(e,t,"following-sibling",a,l,r,o),u)){f=f.concat(u);break}for(let n=e.previousElementSibling;null!=n;n=n.previousElementSibling)if(null!=n&&n.isSameNode(t)&&(u=se(e,t,"preceding-sibling",a,l,r,o),u)){f=f.concat(u);break}}if(e?.children?.length)for(let n=e.children[0];null!==n;n=n?.nextElementSibling)if(n===t&&(u=se(e,t,"child",a,l,r,o),u)){f=f.concat(u);break}const m=e.compareDocumentPosition(t);2===m&&(u=se(e,t,"preceding",a,l,r,o)),4===m&&(u=se(e,t,"following",a,l,r,o)),u&&(f=f.concat(u));const h=oe([e,t],n,a,l,"descendant",r,o);h&&(f=f.concat(h));const g=oe([e,t],n,a,l,"descendant-or-self",r,o);g&&(f=f.concat(g))}if(f.length)return f.length>1&&f.sort(function(e,t){return e.value.length-t.value.length}),f.filter(e=>!e.key?.includes("index"))?.length?[f.filter(e=>!e.key?.includes("index"))[0]]:[f[0]]},getDescendantXpath:oe,getXpathRelationExpression:se,getTraverseXpathExpression:ie,getReferenceElementXpath:e=>{let t=[];if(t=ee(e,e.ownerDocument,!1,!1),t?.length){let n=ee(e,e.ownerDocument,!0,!1);n?.length&&(n=n?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(e.value)}:{key:"",value:e.value}),t=t.concat(n))}else t=ee(e,e.ownerDocument,!0,!1),t=t?.map(e=>"("==e.value.charAt(0)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(e.value)}:{key:"",value:e.value});if(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)&&O(e.value,0)+1===e.value.lastIndexOf("[")?{key:"",value:f(e.value)}:{key:"",value:e.value})),t?.length){const n=A(e,e.ownerDocument,!1);n?.length&&(t=t.concat(n))}else t=A(e,e.ownerDocument,!1);const n=b(e,e.ownerDocument);return t=t.filter(e=>e.value!==n),t.push({key:"absolute xpath",value:n.slice(1)}),t}};let ue=[];const fe=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},me=(e,t="single")=>{const n=[],a=e.getRootNode();try{const l=he(e);if(l&&fe(l,e,a)&&(n.push({key:"cssSelector by id",value:l}),"single"===t))return n;const r=$e(e);r&&fe(r,e,a)&&n.push({key:"cssSelector by class",value:r});const o=pe(e);o&&n.push({key:"cssSelector by name",value:o});const s=ve(e);s&&fe(s,e,a)&&n.push({key:"Absolute cssSelector",value:s})}catch(e){console.error(e)}return n},he=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&&!o(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(" > ")},ge=new Set(["id","class","style"]);function de(e){return Array.from(e.attributes).filter(e=>!ge.has(e?.name?.toLowerCase())&&e.value&&!o(e.value)).map(e=>{return`[${e.name}="${t=e.value,String(t).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"]`;var t})}const pe=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=de(e);for(const t of l){const l=`${a}${t}`;if(fe(l,e,n))return l}},$e=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||o(e.className)||ue?.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(" > ")},ve=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(" > ")},ye={parseCssSelectors:me,getIdCssPath:he,getAttributeCssPath:pe,getClassCssPath:$e,getAbsoluteCssPath:ve},Ne=(e,t,n)=>{const a=D(e);if(Ae(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},be=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return Se(e.body,t)},xe=(e,t,n)=>be(t,e)===n,Ee=e=>e.name?.toLowerCase().includes("cssselector")??!1,Se=(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=Se(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},ke=e=>e?.id||null,we=e=>e.className||null,Re=e=>e.textContent?.trim()||null,Ce=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Pe=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function Ae(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 De(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 Oe=(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 r(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(Ee(t))return be(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=Ae(e,D(n));return a&&r(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)r(e);const f=String(n.value||n.type||"");if(f.includes("dynamic")||f.match("dynamic")||f.includes("{")||f.includes("}")){r(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=Se(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=>Ee(e)&&e.value);for(const e of n)Ne(e.value,t,u)&&r(e,{isSelfHealed:null});for(const e of a)xe(e.value,t,u)&&r(e,{isSelfHealed:null});const s=l.filter(e=>"xpath"===e.name&&e.value),i=new Set(s.map(e=>X(e.value))),f=[],h=ke(u);if(h&&!m("id",h)&&!o(h)){const n=e.locators.find(e=>"id"===e.name);j(t,"id",h,u)&&(f.push("id"),r(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);j(t,"tagName",g,u)&&(f.push("tagName"),r(n,{name:"tagName",type:"static",isRecorded:"Y",value:g}))}const d=Re(u);if(d&&!o(d)){const n=e.locators.find(e=>"linkText"===e.name);j(t,"linkText",d,u)&&(f.push("linkText"),r(n,{name:"linkText",type:"static",isRecorded:"Y",value:d}))}const p=Ce(u);if(p&&!m("name",p)&&!o(p)){const n=e.locators.find(e=>"name"===e.name);j(t,"name",p,u)&&(f.push("name"),r(n,{name:"name",type:"static",isRecorded:"Y",value:p}))}const $=we(u);if($&&""!==$.trim()&&!$.includes(" ")&&!m("className",$)&&!o($)){const n=e.locators.find(e=>"className"===e.name);j(t,"className",$,u)&&(f.push("className"),r(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}me(u,"single").forEach(e=>{e.value&&!m("cssSelector",e.value)&&r(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=ee(u,t,!1,!0,v)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==y?.length){const e=n.filter(e=>!Ne(e.value,t,u));let a=0;for(const t of e){if(a>=e.length)break;const n=X(t.value);if(i.has(n))continue;const l=y.find(e=>e.value&&X(e.value)===n);l?.value&&(r(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=X(t.value);i.has(n)||(r(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 Pe)if(a.value.includes(e)){const l=De(a.value,e,t);if(l){r(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:ke(u)},{name:"name",value:Ce(u)},{name:"className",value:we(u)},{name:"tagName",value:u.tagName},{name:"linkText",value:Re(u)}];for(const n of e){if(l.length>4)break;const{name:e,value:a}=n;a&&(o(a)||m(e,a)||"className"===e&&a.includes(" ")||j(t,e,a,u)&&r(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&me(u,"multiple").forEach(e=>{l.length>4||e.value&&(m("cssSelector",e.value)||j(t,"cssSelector",e.value,u)&&r(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},Xe=()=>({xpath:te,referenceXpaths:ce,xpathUtils:L,getElementsFromHTML:Oe,cssSelectors:ye});e.createXPathAPI=Xe,e.default=Xe,Object.defineProperty(e,"__esModule",{value:!0})}(this.XpathLib=this.XpathLib||{});
|
|
@@ -101,7 +101,7 @@ export declare const createXPathAPI: () => {
|
|
|
101
101
|
relativeXpath?: string | null;
|
|
102
102
|
} | null;
|
|
103
103
|
cssSelectors: {
|
|
104
|
-
parseCssSelectors: (el: Element) => {
|
|
104
|
+
parseCssSelectors: (el: Element, mode?: import("../types/locator.ts").SelectorMode) => {
|
|
105
105
|
key: string;
|
|
106
106
|
value: string;
|
|
107
107
|
}[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { SelectorMode } from "../types/locator.ts";
|
|
2
|
+
export declare const parseCssSelectors: (el: Element, mode?: SelectorMode) => {
|
|
2
3
|
key: string;
|
|
3
4
|
value: string;
|
|
4
5
|
}[];
|
|
@@ -7,7 +8,7 @@ export declare const getAttributeCssPath: (el: Element) => string | undefined;
|
|
|
7
8
|
export declare const getClassCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
8
9
|
export declare const getAbsoluteCssPath: (el: Element) => string | undefined;
|
|
9
10
|
export declare const cssSelectors: {
|
|
10
|
-
parseCssSelectors: (el: Element) => {
|
|
11
|
+
parseCssSelectors: (el: Element, mode?: SelectorMode) => {
|
|
11
12
|
key: string;
|
|
12
13
|
value: string;
|
|
13
14
|
}[];
|
|
@@ -57,7 +57,7 @@ export declare function extractXPathSignatureParts(xpath: string): {
|
|
|
57
57
|
export declare function getXPathPattern(xpath: string): string;
|
|
58
58
|
export declare function escapeAttrValue(value: string): string;
|
|
59
59
|
export declare function shouldUseSnapshot(xpath: string): boolean;
|
|
60
|
-
export declare function isUniqueInDOM(docmt: Document, name: string, value: string): boolean;
|
|
60
|
+
export declare function isUniqueInDOM(docmt: Document, name: string, value: string, element?: Element | null): boolean;
|
|
61
61
|
export declare const xpathUtils: {
|
|
62
62
|
parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
63
63
|
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { SelectorMode } from "../types/locator.ts";
|
|
2
|
+
export declare const parseCssSelectors: (el: Element, mode?: SelectorMode) => {
|
|
2
3
|
key: string;
|
|
3
4
|
value: string;
|
|
4
5
|
}[];
|
|
@@ -7,7 +8,7 @@ export declare const getAttributeCssPath: (el: Element) => string | undefined;
|
|
|
7
8
|
export declare const getClassCssPath: (el: HTMLElement | Element) => string | undefined;
|
|
8
9
|
export declare const getAbsoluteCssPath: (el: Element) => string | undefined;
|
|
9
10
|
export declare const cssSelectors: {
|
|
10
|
-
parseCssSelectors: (el: Element) => {
|
|
11
|
+
parseCssSelectors: (el: Element, mode?: SelectorMode) => {
|
|
11
12
|
key: string;
|
|
12
13
|
value: string;
|
|
13
14
|
}[];
|
|
@@ -57,7 +57,7 @@ export declare function extractXPathSignatureParts(xpath: string): {
|
|
|
57
57
|
export declare function getXPathPattern(xpath: string): string;
|
|
58
58
|
export declare function escapeAttrValue(value: string): string;
|
|
59
59
|
export declare function shouldUseSnapshot(xpath: string): boolean;
|
|
60
|
-
export declare function isUniqueInDOM(docmt: Document, name: string, value: string): boolean;
|
|
60
|
+
export declare function isUniqueInDOM(docmt: Document, name: string, value: string, element?: Element | null): boolean;
|
|
61
61
|
export declare const xpathUtils: {
|
|
62
62
|
parseXml: (xmlStr: string, type: DOMParserSupportedType) => Document | null;
|
|
63
63
|
getReferenceElementsXpath: (domNode: HTMLElement | Element, docmt: Document, isTarget: boolean) => {
|
package/dist/xpath.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{VirtualConsole as e,JSDOM as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i,l={};let a=[];const r=e=>/\d/.test(e),o=e=>e?.childNodes[0]?.nodeValue||"",s=(e,t,n,a=!1)=>{try{let r;if(void 0!==l[e])r=l[e];else{r=(9===n.nodeType?n:n.ownerDocument).evaluate(`count(${e})`,n,null,XPathResult.NUMBER_TYPE,null).numberValue,l[e]=r}if(a&&Array.isArray(t)){if(r>1){const l=d(e,n,!0);let a,r=0;if(l instanceof XPathResult)for(;(a=l?.iterateNext())&&(!t.includes(a)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return d(e,n)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},i=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},c=(e,t,n,l)=>{try{const a=9===n.nodeType?n:n.ownerDocument;let r=0;if(l){if(1===s(`${e}[${l}]`,t,n))return`${e}[${l}]`;if(1===s(`(${e})[${l}]`,t,n))return`(${e})[${l}]`}const o=a.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let i;for(;i=o.iterateNext();)if(r++,i.isSameNode(t))return 1===s(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===s(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},u=e=>e?e.replace(/\s\s+/g," ").trim():e,m=(e,t,n)=>{if(!e?.value||"boolean"==typeof e?.value)return!1;if(["true","false","on","off","flntooltip"].some(t=>t===e.value))return!1;if(["type","style","locator-data-tooltip","value"].some(t=>t===e.name))return!1;const l=a?.find(n=>n.doc===t.ownerDocument&&n.element===t&&n.attributeName===e.name);return!l&&(!(0===e?.name?.indexOf("on")&&e?.name?.length>3)&&("function"!=typeof e.value&&(!n||!r(e.value))))},f=e=>e instanceof SVGElement,d=(e,t,n=!1)=>{let l=t;t.nodeType===Node.DOCUMENT_FRAGMENT_NODE&&(l=t.host??t);const a=l.nodeType===Node.DOCUMENT_NODE?l:l.ownerDocument;return n?a.evaluate(e,l,null,XPathResult.ANY_TYPE,null):a.evaluate(e,l,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue},h=(e,t,l,a,o,c)=>{if(a){const{tagName:m}=e;let d,h="";const p=[];let g;if(a&&(!c||!r(a))&&(g=n.test(a)?`//${m}[${l}=${i(a)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${l})=${i(u(a)).trim()}`,f(e),e.tagName.toLowerCase()),d=s(g,e,t),1===d&&!o))return g;if(a&&c){const r=a.split(" ");if(r?.length)if(1===r.length){const c=[...new Set(r[0].match(/([^0-9]+)/g))];if(c?.length>=1&&c[0]&&u(c[0].trim())?.length>1&&a.startsWith(c[0])&&(h=n.test(c[0])?`starts-with(${l},${i(c[0]).trim()})`:`starts-with(${l},${i(u(c[0])).trim()})`),c?.length>1&&c[c.length-1]&&u(c[c.length-1].trim())?.length>1&&a.endsWith(c[c.length-1])&&(h=n.test(c[c.length-1])?`ends-with(${l},${i(c[c.length-1]).trim()})`:`ends-with(${l},${i(u(c[c.length-1])).trim()})`),h?.length&&(g=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(g,e,t),1===d&&!o))return g}else{const c=r.length%2==0?r.length/2:r.length%2,p=r.slice(0,c).join(" ");let $=[...new Set(p.match(/([^0-9]+)/g))];if($?.length&&$[0]&&u($[0].trim())?.length&&a.startsWith($[0])&&(h=n.test($[0])?`starts-with(${l},${i($[0]).trim()})`:`starts-with(${l},${i(u($[0])).trim()})`),h?.length&&(g=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(g,e,t),1===d&&!o))return g;const y=r.slice(c,r.length-1).join(" ");if($=[...new Set(y.match(/([^0-9]+)/g))],$?.length&&$[0]&&u($[0].trim())?.length>3&&a.endsWith($[0])&&(h=n.test($[0])?`ends-with(${l},${i($[0]).trim()})`:`ends-with(${l},${i(u($[0])).trim()})`),h?.length&&(g=f(e)?`//*[local-name()='${m}' and ${h}]`:`//${m}[${h}]`,d=s(g,e,t),1===d&&!o))return g}}if(a&&c&&r(a)){const r=[...new Set(a.match(/([^0-9]+)/g))];if(r?.length)for(let e=0;e<r?.length;e++)r[e]&&u(r[e].trim())?.length>1&&(n.test(r[e])?p.push(`contains(${l},${i(r[e].trim()).trim()})`):p.push(`contains(${l},${i(u(r[e])).trim()})`));if(p?.length&&(g=f(e)?`//*[local-name()='${m}' and ${p.join(" and ")}]`:`//${m}[${p.join(" and ")}]`,d=s(g,e,t),1===d&&!o))return g}if(g=f(e)?`//*[local-name()='${m}' and text()]`:`//${m}[text()]`,d=s(g,e,t),1===d&&!o)return g}},p=(e,t,l)=>{let a=f(e),r="";if(m(t,e,l)){let l=t.value;l=l.replace("removePointers","");const o=t.name;r=n.test(l)?a?`*[local-name()='${e.tagName}' and @${o}=${i(l)}]`:`${e.tagName||"*"}[@${o}=${i(l)}]`:a?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${i(l)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${i(l)}]`}return r},g=(e,t)=>{if(!e.textContent)return"";const l=o(e);let a;return a=n.test(l)?f(e)?`//*[local-name()='${e.tagName}' and .=${i(l)}]`:`//${e.tagName||"*"}[.=${i(l)}]`:f(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${i(l)}]`:`//${e.tagName||"*"}[normalize-space(.)=${i(l)}]`,a},$=(e,t,n)=>{const l=new RegExp(/^[\S]+( [\S]+)*$/gi);let a="";return n&&(a=l.test(n)?"class"===t?f(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`:f(e)?`//*[local-name()='${e.tagName}' and @${t}=${i(n)}]`:`//${e.tagName||"*"}[@${t}=${i(n)}]`:f(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`),a},y=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function v(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)::/),l=n?.[1]??"none",a=t.match(/@([a-z0-9:-]+)/);return{axis:l,attribute:a?.[1]??"none",usesNormalize:t.includes("normalize-space")}}(e);return["XPATH",`axis:${n.axis}`,`attr:${n.attribute}`,`normalize:${n.usesNormalize}`,`shape:${t}`].join("|")}function N(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function E(e,t,n){try{switch(t){case"id":return null!==e.getElementById(n)&&1===e.querySelectorAll(`#${N(n)}`).length;case"name":return 1===e.querySelectorAll(`[name="${N(n)}"]`).length;case"className":return 1===e.getElementsByClassName(n).length;case"tagName":return 1===e.getElementsByTagName(n).length;case"linkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.trim()===n).length;case"partialLinkText":return 1===Array.from(e.querySelectorAll("a")).filter(e=>e.textContent?.includes(n)).length;case"cssSelector":return 1===e.querySelectorAll(n).length;default:return!1}}catch{return!1}}let x=[],b=[],S=new Map,w=new Map;const R=new Map,k=(e,t,n,l,a,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){S?.get(e)||S.set(e,s(e,n,l));const t=S?.get(e);if(1===t)return e;if(t>1&&(b.length?t<b[0].count&&(b.pop(),b.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})):b.push({key:"relative xpath by unique parent "+(a?"index":""),value:e,count:t})),t>1&&a&&!x.length){const r=c(e,n,l,t);r&&1===s(r,n,l)&&x.push({key:"relative xpath by unique parent "+(a?"index":""),value:r})}}}return null},C=(e,t,l,a,c,d)=>{try{if(R.has(e))return R.get(e);const h=[];let p=e;for(;p&&1===p.nodeType;){const e=!1;for(const e of Array.from(p.attributes))if(m(e,p,a)){let n=e.nodeValue;n=n?.replace("removePointers","")??"";const a=e.name,r=$(p,a,n);let o;try{o=k(r,c,l,t,d,"parent")}catch(e){continue}if(o)return o}if(p.textContent&&!p.textContent)if(!a||a&&!r(p.textContent)){let e;e=n.test(p.textContent)?f(p)?`//*[local-name()='${p.tagName}' and .=${i(o(p))}]`:`//${p.tagName||"*"}[.=${i(o(p))}]`:f(p)?`//*[local-name()='${p.tagName}' and normalize-space(.)=${i(o(p))}]`:`//${p.tagName||"*"}[normalize-space(.)=${i(o(p))}]`;const a=k(e,c,l,t,d,"parent");if(a)return a}else{const e=[],n=[...new Set(o(p).match(/([^0-9]+)/g))],a=new RegExp(/^[\S]+( [\S]+)*$/gi);if(n?.length)for(let t=0;t<n?.length;t++)n[t]&&u(n[t].trim())&&(a.test(n[t])?e.push(`contains(.,${i(n[t].trim()).trim()})`):e.push(`contains(.,${i(u(n[t])).trim()})`));if(e?.length){const n=f(p)?`//*[local-name()='${p.tagName}' and ${e.join(" and ")}]`:`//${p.tagName||"*"}[${e.join(" and ")}]`,a=k(n,c,l,t,d,"parent");if(a)return a}}if(!e){const e=f(p)?`/*[local-name()='${p.tagName}']`:`/${p.tagName}`;h.unshift(e)}p=p.parentElement}const g=h.join("")+c;if(1===s(g,e,t))return R.set(e,g),g}catch(e){return console.error(e),null}},T=(e,t,n,l)=>{const a=new Map;if(a.has(e))return a.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(m(n,o,l)){let l=n.nodeValue;l=l?.replace("removePointers","")??"";const a=n.name,i=$(o,a,l);let c;try{c=s(i,o,t)}catch(e){continue}if(1===c){r.unshift(i),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=g(o);if(n){if(1===s(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=f(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}const i=r.join("");return a.set(e,i),i}catch(e){return console.log(e),null}},A=(e,t,n)=>{const l=[];let a;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(a=r.pop();null!==a;){for(const n of Array.from(a.attributes))if(m(n,a,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,i=$(a,o,r);let c;try{c=s(i,a,t)}catch(e){continue}if(1===c){e=!0,l.push(i);break}}if(!e&&a.textContent&&!n.textContent){const n=g(a);if(n){if(1===s(n,a,t)){e=!0,l.push(n);break}}}if(e)break;{const e=f(a)?`/*[local-name()='${a.tagName}']`:`/${a.tagName}`;l.push(e),null!=a.firstElementChild?(r.push(a.nextElementSibling),a=a.firstElementChild):a=a.nextElementSibling}}}while(r.length>0);const o=l.join("");return w.set(e,o),o}catch(e){return console.log(e),null}},P=(e,t,n,l)=>{try{const a=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==a;r=r.nextElementSibling)D(r,e,t,l,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==a;r=r.previousElementSibling)D(r,e,t,l,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},D=(e,t,n,l,a,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=p(e,{name:t.name,value:t.value},r);if(o){o+=`/${a}::${l}`;const t=s(o,e,n);if(1===t)return void x.push({key:`xpath by ${a}`,value:o});t>1&&(b.length?t<b[0].count&&(b.pop(),b.push({key:`relative xpath by ${a}`,value:o,count:t})):b.push({key:`relative xpath by ${a}`,value:o,count:t}))}}if(!r){let t;if(t=p(e,{name:"text",value:e.textContent},r),t){const l=s(t,e,n);if(1===l)return void x.push({key:`xpath by ${a}`,value:t});l>1&&(b.length?l<b[0].count&&(b.pop(),b.push({key:`relative xpath by ${a}`,value:t,count:l})):b.push({key:`relative xpath by ${a}`,value:t,count:l}))}}}catch(e){console.log(`${a} xpath-error`,e)}};const Y=(e,t,n,l)=>{if(""!=e.textContent){const a=(e=>{const t=e?.textContent;return t})(e);if(a)return h(e,t,".",a,n,l)}},L=(e,t,l,a,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&m(e,t,r)){const n=((e,t,n,l,a)=>{let r;return r=e.name,h(t,n,`@${r}`,e.value,l,a)})(e,t,l,a,r);n&&x.push({key:`xpath by ${e.name}${a?" index":""}`,value:n})}});const i=Y(t,l,a,r);if(i&&x.push({key:"xpath by text"+(a?" index":""),value:i}),o.find(e=>"className"===e.name)&&m(o?.find(e=>"className"===e.name),t,r)){let e=((e,t,n,l)=>{let a=e.className;if("string"!=typeof a&&(a=""),a=a?.replace("flndisabled","disabled"),a=a?.replace("removePointers",""),a=a?.trim(),a)return h(e,t,"@class",a,n,l)})(t,l,a,r);e&&x.push({key:"xpath by class",value:e})}if(!x.length){const n=function(e,t,n,l){const{tagName:a}=t,r=t.textContent.trim();for(const o of e)if(m(o,t,l)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const l=`//${a}[@${o.name}='${e}' and text()='${r}']`;if(l&&1==s(l,t,n))return l}}(e,t,l,r);n&&x.push({key:"xpath by textAttribute",value:n})}if(!x.length&&o.length>1){const e=((e,t,l,a)=>{try{const r=[];if(l.length>1)for(const o of l)if(m(o,e,a)){const l=o.nodeValue;n.test(l)?"class"===o.nodeName?r.push(`contains(@${o.nodeName},"${l}")`):r.push(`@${o.nodeName}="${l}"`):r.push(`normalize-space(@${o.nodeName})="${l}"`);const a=f(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let i;try{i=s(a,e,t)}catch(e){continue}if(1===i&&!a.includes("and"))return"";if(1===i&&a.includes("and"))return a}}catch(e){console.log(`'${JSON.stringify(e,null,2)}'`)}})(t,l,o,r);e&&x.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},_=(e,t,n,l,a=[])=>{x=[],console.log(e);const r=e,o=r?.ownerDocument||t,i=r.tagName,{attributes:u}=r,m=a.length>0?a:Array.from(u);if(L(m,r,o,n,l),x.length){const t=x.length;for(let n=0;n<t;n++){let t=x[n].value;t="//*"+t.substring(t.indexOf("//")+2+i.length);1===s(t,e,o)&&x.push({key:`${x[n].key} regex`,value:t})}}return x.length||((e,t,n,l,a)=>{try{let r,o,i=[];if(x=[],console.log(a),a)for(const t of a){let n=p(e,{name:t.name,value:t.value},l);console.log(n),n&&i.push(n)}if(e.textContent){let t=p(e,{name:"text",value:e.textContent},l);console.log(t),t&&i.push(t)}if(i.push(e.tagName),i?.length)for(let a=0;a<i.length;a++)if(!x.length){if(P(e,t,l,i[a]),!x.length&&(r||(r=T(e.parentElement,t,e,l)),console.log(r),r&&(r.includes("@")||r.includes("text()")||r.includes(".="))&&r.match(/\//g)?.length-2<5)){const l=r+`/${i[a]}`,o=s(l,e,t);if(1===o)x.push({key:"relative xpath by relative parent",value:l});else if(o>1&&n){const a=c(l,e,t,o);a&&1===s(a,e,t)&&x.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(!x.length&&(o||(o=A(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const l=`/${i[a]+o.substring(1)}`,r=s(l,e,t);if(1===r)x.push({key:"relative xpath by relative child",value:l});else if(r>1&&n){const a=c(l,e,t,r);a&&1===s(a,e,t)&&x.push({key:"relative xpath by relative parent "+(n?"index":""),value:a})}}if(1===x?.length&&x?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const l=Y(e,t,n,!1);l&&x.unshift({key:"xpath by text"+(n?"index":""),value:l})}if(!x.length){let r=C(e.parentElement,t,e,l,i[a],n);r&&x.push({key:"xpath by unique parent",value:r})}}return x}catch(e){console.log(e)}})(r,o,n,l,Array.from(r.attributes)),x};let O=[];const q=(e,t,n)=>{try{const l=n.querySelectorAll(e);return 1===l.length&&l[0]===t}catch{return!1}},j=e=>{const t=[],n=e.getRootNode();try{const l=V(e);if(l&&q(l,e,n))return t.push({key:"cssSelector by id",value:l}),t;const a=I(e);a&&q(a,e,n)&&t.push({key:"cssSelector by class",value:a});const r=X(e);r&&t.push({key:"cssSelector by name",value:r});const o=H(e);o&&q(o,e,n)&&t.push({key:"Absolute cssSelector",value:o})}catch(e){console.error(e)}return t},V=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 l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if(e.id&&!r(e.id)){t+=`#${CSS.escape(e.id)}`,l.unshift(t);break}{let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}l.unshift(t),e=e.parentElement}return l.join(" > ")},z=new Set(["id","class","style"]);const X=e=>{const t=e.ownerDocument?.defaultView;if(!(t&&e instanceof t.Element))return;const n=e.getRootNode(),l=e.tagName.toLowerCase();if("style"===l||"script"===l)return;const a=function(e){return Array.from(e.attributes).filter(e=>!z.has(e?.name?.toLowerCase())&&e.value&&!r(e.value)).map(e=>`[${e.name}="${CSS.escape(e.value)}"]`)}(e);for(const t of a){const a=`${l}${t}`;if(q(a,e,n))return a}},I=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 l=[];for(;e?.nodeType===Node.ELEMENT_NODE;){let t=e.nodeName?.toLowerCase();if("string"!=typeof e.className||!e.className||r(e.className)||O?.find(t=>t.element===e&&"class"===t.attributeName)){let n=e,l=1;if(n.previousElementSibling)for(;n=n.previousElementSibling;)n.nodeName?.toLowerCase()===t&&l++;1!==l&&(t+=`:nth-of-type(${l})`),1===l&&n?.parentElement?.childElementCount>1&&(t+=`:nth-child(${l})`)}else if(e.classList.remove("marked-element-temp"),e.classList.remove("removePointers"),e.className){t+=`.${e.className.trim().replace(/\s+/g,".")}`,l.unshift(t);break}l.unshift(t),e=e.parentElement}return l.join(" > ")},H=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 l=t;const a=e.parentNode;if(a){const t=Array.from(a.children).filter(t=>t.tagName===e.tagName);t.length>1&&(l+=`:nth-of-type(${t.indexOf(e)+1})`)}n.unshift(l),e=e.parentElement}return n.join(" > ")},M=(e,t,n)=>{const l=y(e);if(ee(t,l)===n)return!0;if(function(e){return/\[(?:\s*\.|\s*contains\s*\(\s*\.|\s*normalize-space\s*\(\s*\.)/.test(e)}(l)){const e=t.evaluate(l,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},W=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return G(e.body,t)},F=(e,t,n)=>W(t,e)===n,B=e=>e.name?.toLowerCase().includes("cssselector")??!1,G=(e,t)=>{const n=Array.from(e.querySelectorAll("*"));try{for(let e=0;e<n.length;e++)if(n[e].shadowRoot){const{shadowRoot:l}=n[e];if(l){const e=G(l,t);if(e)return e;if(l&&!t.includes("dynamic"))return l.querySelector(t)}}}catch(e){console.log(e)}return null},U=e=>e?.id||null,J=e=>e.className||null,K=e=>e.textContent?.trim()||null,Q=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},Z=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function ee(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 te(e,t,n){if(e.includes(t)){const l=e.split(t)[0].trim(),a=n.defaultView;if(!a)return null;if(!e.includes("dynamic")){const t=new a.XPathEvaluator;if(t.evaluate(l,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue){let l;return t.evaluate(e,n,null,a.XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue?(l=e,l):(console.error("Complete Locator is Invalid:",e),l=e,l)}console.error("Source Locator Not Found:",l)}}return null}const ne=(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 l=new Set;let a=[];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}`;l.has(t)||(l.add(t),a.push(e))}(o)}const s=(e,t,n)=>{if(!e)return null;let l=e.trim();return l&&"null"!==l.toLowerCase()?(l=l.replace(/\\"/g,'"').replace(/\\'/g,"'"),l=l.replace(/^['"](.+?)['"]$/,"$1"),l=l.replace(/''/g,"'"),l=l.replace(/\[@(id|name)=['"]{2}(.+?)['"]{2}\]/g,"[@$1='$2']"),"id"!==t&&"name"!==t||(l=l.replace(/['"]/g,"").trim()),"xpath"!==t||"Y"!==n||e.startsWith("//")?!l||/^['"]{2}$/.test(l)?null:l:null):null};e:for(const n of e.locators)try{String(n.isRecorded||"");const i=e.locators.filter(e=>"N"===e.isRecorded);if(i.length>0)for(const e of i)o(e);const c=String(n.value||n.type||"");if(c.includes("dynamic")||c.match("dynamic")||c.includes("{")||c.includes("}")){o(n);continue}if(e.isShared.includes("Y"))break e;try{let i=null;if(n.value.startsWith("iframe")){const e=t.querySelector(n.value);if(e){const t=e.contentDocument||e.contentWindow?.document;t&&(i=t.querySelector(n.value.slice(6)))}}else{const e=n.value.split(">>>");for(const l of e){if(!t){console.error("Element not found at:",l);break}{const e=l.trim();if(B(n))i=W(t,e);else if(n.name.includes("id")||e.startsWith("#"))i=t.querySelector("#"+N(e));else if(n.name.includes("className")||e.startsWith("."))i=t.querySelector("."+e);else if("name"===n.name){const n=N(e);i=t.querySelector(`[name="${n}"]`)}else if("tagName"===n.name)i=t.querySelector(e);else if("linkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.trim()===e)||null;else if("partialLinkText"===n.name)i=Array.from(t.querySelectorAll("a")).find(t=>t.textContent?.includes(e))||null;else if(!n.name.includes("xpath")&&!e.startsWith("//")||n.type.match("dynamic"))i=t.querySelector(e),i||(i=G(t.body,e));else{const l=y(e);i=ee(t,l),i&&o(n,{value:e,isRecorded:String(n.isRecorded).includes("N")?"N":"Y"})}}}}const c=(e,t)=>{const n=`${e}:${t}`;return l.has(n)};if(i){const n=e.locators.filter(e=>"xpath"===e.name&&e.value),l=e.locators.filter(e=>B(e)&&e.value);for(const e of n)M(e.value,t,i)&&o(e,{isSelfHealed:null});for(const e of l)F(e.value,t,i)&&o(e,{isSelfHealed:null});const u=a.filter(e=>"xpath"===e.name&&e.value),m=new Set(u.map(e=>v(e.value))),f=[],d=U(i);if(d&&!c("id",d)&&!r(d)){const n=e.locators.find(e=>"id"===e.name);E(t,"id",d)&&(f.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:d}))}const h=i.tagName;if(h&&!c("tagName",h)){const n=e.locators.find(e=>"tagName"===e.name);E(t,"tagName",h)&&(f.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:h}))}const p=K(i);if(p&&!r(p)){const n=e.locators.find(e=>"linkText"===e.name);E(t,"linkText",p)&&(f.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:p}))}const g=Q(i);if(g&&!c("name",g)&&!r(g)){const n=e.locators.find(e=>"name"===e.name);E(t,"name",g)&&(f.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:g}))}const $=J(i);if($&&""!==$.trim()&&!$.includes(" ")&&!c("className",$)&&!r($)){const n=e.locators.find(e=>"className"===e.name);E(t,"className",$)&&(f.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}j(i).forEach(e=>{e.value&&!c("cssSelector",e.value)&&E(t,"cssSelector",e.value)&&o(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const y=Array.from(i.attributes).filter(e=>!f.includes(e.name));let N=[];try{N=_(i,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==N?.length){const e=n.filter(e=>!M(e.value,t,i));let l=0;for(const t of e){if(l>=e.length)break;const n=v(t.value);if(m.has(n))continue;const a=N.find(e=>e.value&&v(e.value)===n);a?.value&&(o(t,{name:"xpath",value:a.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),m.add(n),l++)}if(l<e.length)for(const t of N){if(l>=e.length)break;if(!t.value)continue;const n=v(t.value);m.has(n)||(o(t,{name:"xpath",value:t.value,type:"static",isRecorded:"Y",isSelfHealed:"Y"}),m.add(n),l++)}}for(const n of e.locators)try{for(const l of e.locators)if(l.value)for(const e of Z)if(l.value.includes(e)){const a=te(l.value,e,t);if(a){o(l,{name:"xpath",value:a,isRecorded:""!==n.isRecorded&&null!==n.isRecorded?n.isRecorded:"Y"});break}}}catch(e){console.error("Error processing locator:",n,e)}if(a.length<5){const e=[{name:"id",value:U(i)},{name:"name",value:Q(i)},{name:"className",value:J(i)},{name:"tagName",value:i.tagName},{name:"linkText",value:K(i)}];for(const n of e){if(a.length>4)break;const{name:e,value:l}=n;l&&(r(l)||c(e,l)||"className"===e&&l.includes(" ")||E(t,e,l)&&o(void 0,{name:e,type:"static",value:l,isRecorded:"Y",isSelfHealed:"Y"}))}}const x=a.map(e=>({...e,value:s(e.value,e.name,e.isRecorded)})),b=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:x.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};async function le(){return{fromHTML:async n=>{const l=new e,a=new t(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"outside-only",virtualConsole:l}),{window:r}=a;return global.document=r.document,global.Node=r.Node,global.Element=r.Element,global.HTMLElement=r.HTMLElement,global.SVGElement=r.SVGElement,global.XPathResult=r.XPathResult,global.XPathEvaluator=r.XPathEvaluator,{autoHeal:async e=>ne(e,r.document)}}}}export{le as default};
|
|
1
|
+
import{VirtualConsole as e,JSDOM as t}from"jsdom";const n=/^[\S]+( [\S]+)*$/i,a={};let l=[];const r=e=>/\d/.test(e),o=e=>e?.childNodes[0]?.nodeValue||"",s=(e,t,n,l=!1)=>{try{let r;if(void 0!==a[e])r=a[e];else{r=(9===n.nodeType?n:n.ownerDocument).evaluate(`count(${e})`,n,null,XPathResult.NUMBER_TYPE,null).numberValue,a[e]=r}if(l&&Array.isArray(t)){if(r>1){const a=d(e,n,!0);let l,r=0;if(a instanceof XPathResult)for(;(l=a?.iterateNext())&&(!t.includes(l)||(r+=1,2!==r)););if(2!==r)return 0}}else if(1===r){return d(e,n)===t?r:0}return r}catch(t){return console.error(`Error evaluating XPath: ${e}`,t),0}},i=e=>{if(e){if(-1!==e.indexOf('"'))return`'${e}'`;if(-1!==e.indexOf("'"))return`"${e}"`}return`'${e}'`},c=(e,t,n,a)=>{try{const l=9===n.nodeType?n:n.ownerDocument;let r=0;if(a){if(1===s(`${e}[${a}]`,t,n))return`${e}[${a}]`;if(1===s(`(${e})[${a}]`,t,n))return`(${e})[${a}]`}const o=l.evaluate(e,n,null,XPathResult.ANY_TYPE,null);let i;for(;i=o.iterateNext();)if(r++,i.isSameNode(t))return 1===s(`${e}[${r}]`,t,n)?`${e}[${r}]`:1===s(`(${e})[${r}]`,t,n)?`(${e})[${r}]`:void 0}catch(e){console.log(e)}},u=e=>e?e.replace(/\s\s+/g," ").trim():e,f=(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))))},m=e=>e instanceof SVGElement,d=(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},h=(e,t,a,l,o,c)=>{if(l){const{tagName:f}=e;let d,h="";const p=[];let g;if(l&&(!c||!r(l))&&(g=n.test(l)?`//${f}[${a}=${i(l)}]`:((e,t,n)=>t?`//*[local-name()='${n}' and ${e}]`:`//${n}[${e}]`)(`normalize-space(${a})=${i(u(l)).trim()}`,m(e),e.tagName.toLowerCase()),d=s(g,e,t),1===d&&!o))return g;if(l&&c){const r=l.split(" ");if(r?.length)if(1===r.length){const c=[...new Set(r[0].match(/([^0-9]+)/g))];if(c?.length>=1&&c[0]&&u(c[0].trim())?.length>1&&l.startsWith(c[0])&&(h=n.test(c[0])?`starts-with(${a},${i(c[0]).trim()})`:`starts-with(${a},${i(u(c[0])).trim()})`),c?.length>1&&c[c.length-1]&&u(c[c.length-1].trim())?.length>1&&l.endsWith(c[c.length-1])&&(h=n.test(c[c.length-1])?`ends-with(${a},${i(c[c.length-1]).trim()})`:`ends-with(${a},${i(u(c[c.length-1])).trim()})`),h?.length&&(g=m(e)?`//*[local-name()='${f}' and ${h}]`:`//${f}[${h}]`,d=s(g,e,t),1===d&&!o))return g}else{const c=r.length%2==0?r.length/2:r.length%2,p=r.slice(0,c).join(" ");let $=[...new Set(p.match(/([^0-9]+)/g))];if($?.length&&$[0]&&u($[0].trim())?.length&&l.startsWith($[0])&&(h=n.test($[0])?`starts-with(${a},${i($[0]).trim()})`:`starts-with(${a},${i(u($[0])).trim()})`),h?.length&&(g=m(e)?`//*[local-name()='${f}' and ${h}]`:`//${f}[${h}]`,d=s(g,e,t),1===d&&!o))return g;const y=r.slice(c,r.length-1).join(" ");if($=[...new Set(y.match(/([^0-9]+)/g))],$?.length&&$[0]&&u($[0].trim())?.length>3&&l.endsWith($[0])&&(h=n.test($[0])?`ends-with(${a},${i($[0]).trim()})`:`ends-with(${a},${i(u($[0])).trim()})`),h?.length&&(g=m(e)?`//*[local-name()='${f}' and ${h}]`:`//${f}[${h}]`,d=s(g,e,t),1===d&&!o))return g}}if(l&&c&&r(l)){const r=[...new Set(l.match(/([^0-9]+)/g))];if(r?.length)for(let e=0;e<r?.length;e++)r[e]&&u(r[e].trim())?.length>1&&(n.test(r[e])?p.push(`contains(${a},${i(r[e].trim()).trim()})`):p.push(`contains(${a},${i(u(r[e])).trim()})`));if(p?.length&&(g=m(e)?`//*[local-name()='${f}' and ${p.join(" and ")}]`:`//${f}[${p.join(" and ")}]`,d=s(g,e,t),1===d&&!o))return g}if(g=m(e)?`//*[local-name()='${f}' and text()]`:`//${f}[text()]`,d=s(g,e,t),1===d&&!o)return g}},p=(e,t,a)=>{let l=m(e),r="";if(f(t,e,a)){let a=t.value;a=a.replace("removePointers","");const o=t.name;r=n.test(a)?l?`*[local-name()='${e.tagName}' and @${o}=${i(a)}]`:`${e.tagName||"*"}[@${o}=${i(a)}]`:l?`*[local-name()='${e.tagName}' and normalize-space(@${o})=${i(a)}]`:`${e.tagName||"*"}[normalize-space(@${o})=${i(a)}]`}return r},g=(e,t)=>{if(!e.textContent)return"";const a=o(e);let l;return l=n.test(a)?m(e)?`//*[local-name()='${e.tagName}' and .=${i(a)}]`:`//${e.tagName||"*"}[.=${i(a)}]`:m(e)?`//*[local-name()='${e.tagName}' and normalize-space(.)=${i(a)}]`:`//${e.tagName||"*"}[normalize-space(.)=${i(a)}]`,l},$=(e,t,n)=>{const a=new RegExp(/^[\S]+( [\S]+)*$/gi);let l="";return n&&(l=a.test(n)?"class"===t?m(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`:m(e)?`//*[local-name()='${e.tagName}' and @${t}=${i(n)}]`:`//${e.tagName||"*"}[@${t}=${i(n)}]`:m(e)?`//*[local-name()='${e.tagName}' and contains(@${t},${i(n)})]`:`//${e.tagName||"*"}[contains(@${t},${i(n)})]`),l},y=e=>e=(e=e.replace(/text\(\)\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1")).replace(/\.\s*=\s*(['"])(.*?)\1/g,"normalize-space(.)=$1$2$1");function v(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 N(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/ /g,"\\ ")}function E(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(`#${N(n)}`).length;case"name":return 1===r(`[name="${N(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}}let x=[],b=[],S=new Map,w=new Map;const R=new Map,k=(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){S?.get(e)||S.set(e,s(e,n,a));const t=S?.get(e);if(1===t)return e;if(t>1&&(b.length?t<b[0].count&&(b.pop(),b.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})):b.push({key:"relative xpath by unique parent "+(l?"index":""),value:e,count:t})),t>1&&l&&!x.length){const r=c(e,n,a,t);r&&1===s(r,n,a)&&x.push({key:"relative xpath by unique parent "+(l?"index":""),value:r})}}}return null},C=(e,t,a,l,c,d)=>{try{if(R.has(e))return R.get(e);const h=[];let p=e;for(;p&&1===p.nodeType;){const e=!1;for(const e of Array.from(p.attributes))if(f(e,p,l)){let n=e.nodeValue;n=n?.replace("removePointers","")??"";const l=e.name,r=$(p,l,n);let o;try{o=k(r,c,a,t,d,"parent")}catch(e){continue}if(o)return o}if(p.textContent&&!p.textContent)if(!l||l&&!r(p.textContent)){let e;e=n.test(p.textContent)?m(p)?`//*[local-name()='${p.tagName}' and .=${i(o(p))}]`:`//${p.tagName||"*"}[.=${i(o(p))}]`:m(p)?`//*[local-name()='${p.tagName}' and normalize-space(.)=${i(o(p))}]`:`//${p.tagName||"*"}[normalize-space(.)=${i(o(p))}]`;const l=k(e,c,a,t,d,"parent");if(l)return l}else{const e=[],n=[...new Set(o(p).match(/([^0-9]+)/g))],l=new RegExp(/^[\S]+( [\S]+)*$/gi);if(n?.length)for(let t=0;t<n?.length;t++)n[t]&&u(n[t].trim())&&(l.test(n[t])?e.push(`contains(.,${i(n[t].trim()).trim()})`):e.push(`contains(.,${i(u(n[t])).trim()})`));if(e?.length){const n=m(p)?`//*[local-name()='${p.tagName}' and ${e.join(" and ")}]`:`//${p.tagName||"*"}[${e.join(" and ")}]`,l=k(n,c,a,t,d,"parent");if(l)return l}}if(!e){const e=m(p)?`/*[local-name()='${p.tagName}']`:`/${p.tagName}`;h.unshift(e)}p=p.parentElement}const g=h.join("")+c;if(1===s(g,e,t))return R.set(e,g),g}catch(e){return console.error(e),null}},T=(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(f(n,o,a)){let a=n.nodeValue;a=a?.replace("removePointers","")??"";const l=n.name,i=$(o,l,a);let c;try{c=s(i,o,t)}catch(e){continue}if(1===c){r.unshift(i),e=!0;break}}if(!e&&o.textContent&&!n.textContent){const n=g(o);if(n){if(1===s(n,o,t)){e=!0,r.unshift(n);break}}}if(e)break;{const e=m(o)?`/*[local-name()='${o.tagName}']`:`/${o.tagName}`;r.unshift(e)}o=o.parentElement}const i=r.join("");return l.set(e,i),i}catch(e){return console.log(e),null}},P=(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(f(n,l,!0)){let r=n.nodeValue;r=r?.replace("removePointers","")??"";const o=n.name,i=$(l,o,r);let c;try{c=s(i,l,t)}catch(e){continue}if(1===c){e=!0,a.push(i);break}}if(!e&&l.textContent&&!n.textContent){const n=g(l);if(n){if(1===s(n,l,t)){e=!0,a.push(n);break}}}if(e)break;{const e=m(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 w.set(e,o),o}catch(e){return console.log(e),null}},A=(e,t,n,a)=>{try{const l=document.querySelector(".flntooltip");for(let r=e.nextElementSibling;null!==r&&r!==l;r=r.nextElementSibling)D(r,e,t,a,"preceding-sibling",n);for(let r=e.previousElementSibling;null!==r&&r!==l;r=r.previousElementSibling)D(r,e,t,a,"following-sibling",n)}catch(e){return console.error("sibling error",e),null}},D=(e,t,n,a,l,r)=>{try{if(e.hasAttributes())for(const t of Array.from(e.attributes)){let o=p(e,{name:t.name,value:t.value},r);if(o){o+=`/${l}::${a}`;const t=s(o,e,n);if(1===t)return void x.push({key:`xpath by ${l}`,value:o});t>1&&(b.length?t<b[0].count&&(b.pop(),b.push({key:`relative xpath by ${l}`,value:o,count:t})):b.push({key:`relative xpath by ${l}`,value:o,count:t}))}}if(!r){let t;if(t=p(e,{name:"text",value:e.textContent},r),t){const a=s(t,e,n);if(1===a)return void x.push({key:`xpath by ${l}`,value:t});a>1&&(b.length?a<b[0].count&&(b.pop(),b.push({key:`relative xpath by ${l}`,value:t,count:a})):b.push({key:`relative xpath by ${l}`,value:t,count:a}))}}}catch(e){console.log(`${l} xpath-error`,e)}};const Y=(e,t,n,a)=>{if(""!=(e.textContent??"").trim()){const l=(e=>{const t=e?.textContent;return t})(e);if(l)return h(e,t,".",l,n,a)}},L=(e,t,a,l,r)=>{const o=e;try{o.map(e=>{if("className"!==e.name&&"class"!==e.name&&f(e,t,r)){const n=((e,t,n,a,l)=>{let r;return r=e.name,h(t,n,`@${r}`,e.value,a,l)})(e,t,a,l,r);n&&x.push({key:`xpath by ${e.name}${l?" index":""}`,value:n})}});const i=Y(t,a,l,r);if(i&&x.push({key:"xpath by text"+(l?" index":""),value:i}),o.find(e=>"className"===e.name)&&f(o?.find(e=>"className"===e.name),t,r)){let e=((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 h(e,t,"@class",l,n,a)})(t,a,l,r);e&&x.push({key:"xpath by class",value:e})}if(!x.length){const n=function(e,t,n,a){const{tagName:l}=t,r=t.textContent.trim();for(const o of e)if(f(o,t,a)){let e=o.nodeValue;e=e?.replace("removePointers","")??"";const a=`//${l}[@${o.name}='${e}' and text()='${r}']`;if(a&&1==s(a,t,n))return a}}(e,t,a,r);n&&x.push({key:"xpath by textAttribute",value:n})}if(!x.length&&o.length>1){const e=((e,t,a,l)=>{try{const r=[];if(a.length>1)for(const o of a)if(f(o,e,l)){const a=o.nodeValue;n.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=m(e)?`//*[local-name()='${e.tagName}' and ${r.join(" and ")}]`:`//${e.tagName}[${r.join(" and ")}]`;let i;try{i=s(l,e,t)}catch(e){continue}if(1===i&&!l.includes("and"))return"";if(1===i&&l.includes("and"))return l}}catch(e){console.log(`'${JSON.stringify(e,null,2)}'`)}})(t,a,o,r);e&&x.push({key:"xpath by combination",value:e})}}catch(e){console.log(e)}},_=(e,t,n,a,l=[])=>{x=[],console.log(e);const r=e,o=r?.ownerDocument||t,i=r.tagName,{attributes:u}=r,f=l.length>0?l:Array.from(u);if(L(f,r,o,n,a),x.length){const t=x.length;for(let n=0;n<t;n++){let t=x[n].value;t="//*"+t.substring(t.indexOf("//")+2+i.length);1===s(t,e,o)&&x.push({key:`${x[n].key} regex`,value:t})}}return x.length||((e,t,n,a,l)=>{try{let r,o,i=[];if(x=[],console.log(l),l)for(const t of l){let n=p(e,{name:t.name,value:t.value},a);console.log(n),n&&i.push(n)}if(e.textContent){let t=p(e,{name:"text",value:e.textContent},a);console.log(t),t&&i.push(t)}if(i.push(e.tagName),i?.length)for(let l=0;l<i.length;l++)if(!x.length){if(A(e,t,a,i[l]),!x.length&&(r||(r=T(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+`/${i[l]}`,o=s(a,e,t);if(1===o)x.push({key:"relative xpath by relative parent",value:a});else if(o>1&&n){const l=c(a,e,t,o);l&&1===s(l,e,t)&&x.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(!x.length&&(o||(o=P(e,t,e)),o&&(o.includes("@")||o.includes("text()")||o.includes(".=")))){const a=`/${i[l]+o.substring(1)}`,r=s(a,e,t);if(1===r)x.push({key:"relative xpath by relative child",value:a});else if(r>1&&n){const l=c(a,e,t,r);l&&1===s(l,e,t)&&x.push({key:"relative xpath by relative parent "+(n?"index":""),value:l})}}if(1===x?.length&&x?.[0]?.value?.match(/\[([0-9]+)\]/gm)?.length>3&&e.textContent){const a=Y(e,t,n,!1);a&&x.unshift({key:"xpath by text"+(n?"index":""),value:a})}if(!x.length){let r=C(e.parentElement,t,e,a,i[l],n);r&&x.push({key:"xpath by unique parent",value:r})}}return x}catch(e){console.log(e)}})(r,o,n,a,Array.from(r.attributes)),x};let O=[];const j=(e,t,n)=>{try{const a=n.querySelectorAll(e);return 1===a.length&&a[0]===t}catch{return!1}},V=(e,t="single")=>{const n=[],a=e.getRootNode();try{const l=q(e);if(l&&j(l,e,a)&&(n.push({key:"cssSelector by id",value:l}),"single"===t))return n;const r=I(e);r&&j(r,e,a)&&n.push({key:"cssSelector by class",value:r});const o=H(e);o&&n.push({key:"cssSelector by name",value:o});const s=M(e);s&&j(s,e,a)&&n.push({key:"Absolute cssSelector",value:s})}catch(e){console.error(e)}return n},q=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(" > ")},z=new Set(["id","class","style"]);function X(e){return Array.from(e.attributes).filter(e=>!z.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 H=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=X(e);for(const t of l){const l=`${a}${t}`;if(j(l,e,n))return l}},I=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)||O?.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(" > ")},M=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(" > ")},W=(e,t,n)=>{const a=y(e);if(te(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},F=(e,t)=>{try{const n=e.querySelector(t);if(n)return n}catch(e){return console.error("Invalid CSS selector:",t,e),null}return B(e.body,t)},G=(e,t,n)=>F(t,e)===n,U=e=>e.name?.toLowerCase().includes("cssselector")??!1,B=(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=B(a,t);if(e)return e;if(a&&!t.includes("dynamic"))return a.querySelector(t)}}}catch(e){console.log(e)}return null},J=e=>e?.id||null,Z=e=>e.className||null,K=e=>e.textContent?.trim()||null,Q=e=>{const t=e;if(t.hasAttribute("name")){return`${t.getAttribute("name")}`||null}return null},ee=["/preceding-sibling","/following-sibling","/parent","/descendant","/ancestor","/self","/ancestor-or-self","/child","/preceding","/following"];function te(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 ne(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 ae=(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(U(t))return F(e,n);if(t.name.includes("id")||n.startsWith("#"))return e.querySelector("#"+N(n));if(t.name.includes("className")||n.startsWith("."))return e.querySelector("."+n);if("name"===t.name){const t=N(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=te(e,y(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=B(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=>U(e)&&e.value);for(const e of n)W(e.value,t,u)&&o(e,{isSelfHealed:null});for(const e of a)G(e.value,t,u)&&o(e,{isSelfHealed:null});const s=l.filter(e=>"xpath"===e.name&&e.value),i=new Set(s.map(e=>v(e.value))),f=[],d=J(u);if(d&&!m("id",d)&&!r(d)){const n=e.locators.find(e=>"id"===e.name);E(t,"id",d,u)&&(f.push("id"),o(n,{name:"id",type:"static",isRecorded:"Y",value:d}))}const h=u.tagName;if(h&&!m("tagName",h)){const n=e.locators.find(e=>"tagName"===e.name);E(t,"tagName",h,u)&&(f.push("tagName"),o(n,{name:"tagName",type:"static",isRecorded:"Y",value:h}))}const p=K(u);if(p&&!r(p)){const n=e.locators.find(e=>"linkText"===e.name);E(t,"linkText",p,u)&&(f.push("linkText"),o(n,{name:"linkText",type:"static",isRecorded:"Y",value:p}))}const g=Q(u);if(g&&!m("name",g)&&!r(g)){const n=e.locators.find(e=>"name"===e.name);E(t,"name",g,u)&&(f.push("name"),o(n,{name:"name",type:"static",isRecorded:"Y",value:g}))}const $=Z(u);if($&&""!==$.trim()&&!$.includes(" ")&&!m("className",$)&&!r($)){const n=e.locators.find(e=>"className"===e.name);E(t,"className",$,u)&&(f.push("className"),o(n,{name:"className",type:"static",isRecorded:"Y",value:$}))}V(u,"single").forEach(e=>{e.value&&!m("cssSelector",e.value)&&o(void 0,{name:"cssSelector",value:e.value,type:"static",isRecorded:"Y"})});const y=Array.from(u.attributes).filter(e=>!f.includes(e.name));let N=[];try{N=_(u,t,!1,!0,y)??[]}catch(e){console.error("Error generating XPath candidates:",e)}if(0!==N?.length){const e=n.filter(e=>!W(e.value,t,u));let a=0;for(const t of e){if(a>=e.length)break;const n=v(t.value);if(i.has(n))continue;const l=N.find(e=>e.value&&v(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 N){if(a>=e.length)break;if(!t.value)continue;const n=v(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 ee)if(a.value.includes(e)){const l=ne(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:J(u)},{name:"name",value:Q(u)},{name:"className",value:Z(u)},{name:"tagName",value:u.tagName},{name:"linkText",value:K(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(" ")||E(t,e,a,u)&&o(void 0,{name:e,type:"static",value:a,isRecorded:"Y",isSelfHealed:"Y"}))}l.length<5&&V(u,"multiple").forEach(e=>{l.length>4||e.value&&(m("cssSelector",e.value)||E(t,"cssSelector",e.value,u)&&o(void 0,{name:"cssSelector",type:"static",value:e.value,isRecorded:"Y",isSelfHealed:"Y"}))})}const x=l.map(e=>({...e,value:c(e.value,e.name,e.isRecorded)})),b=[{name:`${e.name}`,desc:`${e.desc}`,type:`${e.type}`,locators:x.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};async function le(){return{fromHTML:async n=>{const a=new e,l=new t(n.replace(/\\"/g,'"').replace(/\\r/g,"\r").replace(/\\n/g,"\n").replace(/\\t/g,"\t"),{pretendToBeVisual:!0,runScripts:"dangerously",resources:"usable",virtualConsole:a}),{window:r}=l;global.document=r.document,global.Node=r.Node,global.Element=r.Element,global.HTMLElement=r.HTMLElement,global.SVGElement=r.SVGElement;const o=r.CSS??{};return o.escape||(o.escape=e=>String(e).replace(/[^a-zA-Z0-9_-]/g,"\\$&")),global.CSS=o,global.XPathResult=r.XPathResult,global.XPathEvaluator=r.XPathEvaluator,{autoHeal:async e=>ae(e,r.document)}}}}export{le as default};
|
|
2
2
|
//# sourceMappingURL=xpath.mjs.map
|