@nodebug/browser-element-finder 1.2.4 → 1.2.5
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/index.js +1 -1
- package/index.min.js +2 -2
- package/package.json +1 -1
- package/src/element-finder.js +3 -2
package/index.js
CHANGED
|
@@ -919,7 +919,7 @@ var ElementFinder = (() => {
|
|
|
919
919
|
const hasType = elementType !== null && elementType !== void 0 && elementType !== "";
|
|
920
920
|
const hasText = attributeText !== null && attributeText !== void 0 && attributeText !== "";
|
|
921
921
|
if (hasType && !hasText) {
|
|
922
|
-
return
|
|
922
|
+
return findElements(elementType, null, false, parent, options);
|
|
923
923
|
}
|
|
924
924
|
if (!hasType && hasText) {
|
|
925
925
|
return findElementsByAttribute(attributeText, exact, parent);
|
package/index.min.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ElementFinder=(()=>{var D=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var J=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of G(t))!Q.call(e,r)&&r!==n&&D(e,r,{get:()=>t[r],enumerable:!(o=Z(t,r))||o.enumerable});return e};var v=e=>K(D({},"__esModule",{value:!0}),e);var Te={};J(Te,{ELEMENT_DEFINITIONS:()=>g,findElements:()=>X,findElementsByAttribute:()=>W,findElementsByType:()=>z,findProbableElements:()=>ge,getAllElements:()=>y,getAllFrames:()=>T,getBoundingBox:()=>S,getElementCounts:()=>me,getElementDescriptor:()=>ce,getSearchableAttributeValues:()=>H,getSearchableAttributes:()=>oe,getValidAttributes:()=>xe,getValidTypes:()=>Ee,highlight:()=>pe,isHidden:()=>A,matchesAttribute:()=>N,matchesType:()=>p,parseCondition:()=>V,parseXPath:()=>w,pauseAnimations:()=>be,resumeAnimations:()=>we,setSearchableAttributes:()=>re,splitByOperator:()=>B,unhighlight:()=>ye});var P={link:"self::a or @role='link' or @href",navigation:"@role='navigation' or self::nav",heading:"@role='heading' or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6",button:"self::button or @role='button' or @type='button' or @type='submit'",checkbox:"(self::input and @type='checkbox') or @role='checkbox'",switch:"(self::input and @type='checkbox') or @role='switch' or (self::button and (contains(@class, 'switch') or @data-state))",slider:"self::input[@type='range'] or @role='slider'",datepicker:"self::input[@type='date'] or @role='date'",colorpicker:"self::input[@type='color'] or @role='color'",radio:"(self::input and @type='radio') or @role='radio'",dropdown:"(self::select[descendant::option] or @role='combobox' or @role='listbox' or contains(@class, 'dropdown') or contains(@class, 'trigger') or ancestor::*[contains(@class, 'dropdown') or @role='combobox'])",textbox:"self::textarea or (self::input and (@type='text' or @type='password' or @type='search' or @type='email' or @type='number' or @type='tel' or @type='url')) or @role='textbox'",file:"self::input and @type='file'",list:"self::ul or self::ol or @role='list'",listitem:"self::li or @role='listitem'",menu:"self::menu or @role='menu'",menuitem:"@role='menuitem'",toolbar:"@role='toolbar'",dialog:"@role='dialog' or @role='alertdialog'",table:"self::table or @role='table'",row:"self::tr or @role='row'",column:"self::td or self::th or @role='cell' or @role='gridcell' or @role='columnheader'",cell:"self::td or @role='cell' or @role='gridcell'",image:"self::img or @role='img' or @alt",element:"true()"};var R=["placeholder","value","data-value","data-test-id","data-testid","id","resource-id","name","aria-label","hint","title","tooltip","alt","src","aria-labelledby"];var b={selfWithTag:/^self::([a-zA-Z0-9-]+)(?:\[([^\]]+)\])?$/,contains:/contains\(@([a-zA-Z0-9-]+),\s*['"]([^'"]+)['"]\)/i,attrEquals:/@([a-zA-Z0-9-]+)\s*=\s*['"]([^'"]*)['"]/,attrExists:/^@([a-zA-Z0-9-]+)$/,descendant:/descendant::([a-zA-Z0-9-]+)/i,ancestor:/ancestor::\*\[([^\]]+)\]/i,operatorOr:/^\s*\bor\b\s*/i,operatorAnd:/^\s*\band\b\s*/i},ne=100,U=25,C=new Map;for(let[e,t]of Object.entries(P))t==="true()"?C.set(e,()=>!0):C.set(e,n=>w(t,n));var E=R;function re(e){if(!Array.isArray(e))throw new TypeError("attributes must be an array");E=e}function oe(){return[...E]}function H(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{};let t={},n=E;for(let o=0;o<n.length;o++){let r=n[o],i;try{i=e.getAttribute(r)}catch(s){continue}i!=null&&i!==""&&(t[r]=i)}return t}function I(e){return e==null?"":String(e).replace(/\s+/g," ").trim()}function j(e){if(e==null)return"";let t=String(e).split(/\r\n|\r|\n/),n="";for(let i=0;i<t.length&&(n=I(t[i]),!n);i++);if(!n||n.length<=U)return n;let o=n.slice(0,U),r=o.lastIndexOf(" ");return r>0?o.slice(0,r):n}function ie(e){let t=I(e);if(!t)return"";let n=t.split(/[?#]/)[0],o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\")),r=o>=0?n.slice(o+1):n,i=r.lastIndexOf(".");return i>0?r.slice(0,i):r}function se(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o=e.ownerDocument||document,r="";for(let i of n)try{let s=o.getElementById(i);if(!s)continue;let l=I(s.textContent);l&&(r=r?`${r} ${l}`:l)}catch(s){}return r}function _(e){let t=H(e),n=E;for(let i=0;i<n.length;i++){let s=n[i];if(!Object.prototype.hasOwnProperty.call(t,s))continue;let l=s==="aria-labelledby"?se(e):s==="src"?ie(t[s]):t[s],a=I(l);if(a)return{attributeName:s,identifiableText:a}}let o=j($(e));if(o)return{attributeName:"text",identifiableText:o};let r=j(e.textContent);return r?{attributeName:"text",identifiableText:r}:null}function le(e){if(!e||!e.ownerDocument)return null;try{let t=T(window);for(let n=0;n<t.length;n++)if(t[n].document===e.ownerDocument)return t[n].document}catch(t){}return e.ownerDocument}function ae(e,t){let n=le(e);if(!n)return{index:1};let o=y(n),r=1,i=0;for(let s=0;s<o.length;s++){let l=o[s];if(l!==e&&(l===n.documentElement||l.tagName==="BODY"))continue;let a=_(l);!a||a.identifiableText!==t||(i++,l===e&&(r=i))}return{index:r}}function fe(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return null;let t=Object.keys(g);for(let n=0;n<t.length;n++){let o=t[n];if(o!=="element"&&p(e,o))return o}return"element"}function ce(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{identifiableText:null,attributeName:null,index:1,type:null,tagName:null};let t=fe(e),n=_(e);if(!n)return{identifiableText:null,attributeName:null,index:1,type:t,tagName:e.tagName.toLowerCase()};let o=ae(e,n.identifiableText);return{identifiableText:n.identifiableText,attributeName:n.attributeName,index:o.index,type:t,tagName:e.tagName.toLowerCase()}}function w(e,t,n=0){if(e==null||t==null)return!1;if(n>ne)throw new Error("XPath expression exceeds maximum recursion depth");if(e=e.trim(),e==="true()")return!0;if(e[0]==="("&&e[e.length-1]===")"){let i=1,s=!0;for(let l=1;l<e.length-1;l++)if(e[l]==="("?i++:e[l]===")"&&i--,i===0){s=!1;break}if(s)return w(e.slice(1,-1),t,n+1)}let o=B(e,"or");if(o.length>1){for(let i of o)if(w(i,t,n+1))return!0;return!1}let r=B(e,"and");if(r.length>1){for(let i of r)if(!w(i,t,n+1))return!1;return!0}return V(e,t,n)}function B(e,t){let n=[],o=0,r="",i=!1,s="",l=t==="or"?b.operatorOr:b.operatorAnd;for(let a=0;a<e.length;a++){let f=e[a];if((f==="'"||f==='"')&&(a===0||e[a-1]!=="\\")&&(i?f===s&&(i=!1):(i=!0,s=f)),!i&&(f==="("?o++:f===")"&&o--,o===0)){let c=e.slice(a).match(l);if(c){n.push(r.trim()),a+=c[0].length-1,r="";continue}}r+=f}return r.trim()&&n.push(r.trim()),n}function V(e,t,n=0){if(e==null||t==null)return!1;e=e.trim();let o=e.match(b.selfWithTag);if(o){let f=o[1].toUpperCase();return t.tagName!==f?!1:o[2]?w(o[2],t,n+1):!0}let r=e.match(b.contains);if(r)return(t.getAttribute(r[1])||"").toLowerCase().includes(r[2].toLowerCase());let i=e.match(b.attrEquals);if(i)return t.getAttribute(i[1])===i[2];let s=e.match(b.attrExists);if(s)return t.hasAttribute(s[1]);let l=e.match(b.descendant);if(l)return t.querySelector(l[1])!==null;let a=e.match(b.ancestor);if(a){let f=t.parentElement;for(;f;){if(w(a[1],f,n+1))return!0;f=f.parentElement}return!1}return!1}var g=Object.freeze(P);function $(e){let t="";for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];o.nodeType===Node.TEXT_NODE&&(t+=o.textContent)}return t.trim()}function ue(e){if(e.tagName==="STYLE"||e.tagName==="SCRIPT"||e.querySelector("STYLE, SCRIPT"))return!0;let t=e.parentElement;for(;t;){if(t.tagName==="STYLE"||t.tagName==="SCRIPT")return!0;t=t.parentElement}return!1}function F(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o="";for(let r of n)try{let i=document.getElementById(r);i&&(o+=i.textContent)}catch(i){}return o}function N(e,t,n=!1){if(e==null)return!1;if(t==null||t==="")return!0;if(ue(e))return!1;let o=E;for(let s=0;s<o.length;s++){let l=o[s],a;try{a=e.getAttribute(l)}catch(f){continue}if(a){if(l==="aria-labelledby"){if(n?a===t:a.includes(t))return!0;let f=F(e);if(f&&(n?f===t:f.includes(t)))return!0}else if(n?a===t:a.includes(t))return!0}}let r=$(e);if(n?r===t:r.includes(t))return!0;let i=e.textContent;return!!(n?i.trim()===t:i.includes(t))}function p(e,t){if(e==null)return!1;let n=C.get(t);return n?n(e):!1}function y(e=document){let t=[];if(e==null)return t;let n=e.nodeType===Node.DOCUMENT_NODE?e.documentElement:e;if(!n)return t;let o=[n];for(;o.length>0;){let r=o.pop();if(r.nodeType!==Node.ELEMENT_NODE||r.tagName==="SCRIPT"||r.tagName==="STYLE")continue;t.push(r);let i=r.children;for(let s=i.length-1;s>=0;s--)o.push(i[s]);try{if(r.shadowRoot){let s=r.shadowRoot.children;for(let l=s.length-1;l>=0;l--)o.push(s[l])}}catch(s){}}return t}function T(e=window){let t=[];try{t.push({window:e,document:e.document,isMainFrame:!0,frameIndex:-1});let n=e.document.querySelectorAll("iframe");for(let o=0;o<n.length;o++){let r=n[o];try{r.contentWindow&&r.contentDocument&&t.push({window:r.contentWindow,document:r.contentDocument,isMainFrame:!1,frameElement:r,frameIndex:o})}catch(i){i.name==="SecurityError"?console.warn("Skipping cross-origin iframe:",i.message):console.warn("Error accessing iframe:",i.message)}}}catch(n){console.warn("Error getting frames:",n.message)}return t}function S(e){let t=e.getBoundingClientRect();return{x:t.x,y:t.y,width:t.width,height:t.height,top:t.top,bottom:t.bottom,left:t.left,right:t.right,midx:t.x+t.width/2,midy:t.y+t.height/2,tagName:e.tagName.toLowerCase()}}function A(e){if(e==null)return!0;let t=e;for(;t;){if(de(t))return!0;t=t.parentElement}return!1}function de(e){if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true"||e.inert||e.offsetWidth===0&&e.offsetHeight===0)return!0;if(typeof e.checkVisibility=="function")return!e.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0,contentVisibilityAuto:!0});try{let t=window.getComputedStyle(e);if(t.visibility==="hidden"||t.visibility==="collapse"||t.display==="none"||t.opacity==="0")return!0}catch(t){}return!1}function z(e="element",t=null,n=null){if(e==null&&(e="element"),typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);let o=n&&n.failOnUnknownType===!0;if(e&&!g[e]){let a=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(o)throw new TypeError(`Unknown element type: ${e}`);return console.warn(a),{elements:[]}}let r=[],i=T(window);for(let a of i){let f=y(t||a.document);for(let u=0;u<f.length;u++){let c=f[u];e&&!p(c,e)||r.push({element:c,frame:a})}}let s=[];if(r.length>0){let a=new Set(r.map(u=>u.element)),f=new Set;for(let u=r.length-1;u>=0;u--){let c=r[u],d=c.element;if(!f.has(d)){s.unshift(c);let m=d.parentElement;for(;m;)a.has(m)&&f.add(m),m=m.parentElement}}}return{elements:s.map(a=>{let f=S(a.element),u=a.element.tagName.toLowerCase(),c=A(a.element);return a.frame.isMainFrame?{element:a.element,boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}:{boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}})}}function W(e,t=!1,n=null){if(e==null&&(e=""),typeof e!="string")throw new TypeError(`value must be a string, got ${typeof e}`);let o=[],r=T(window);for(let l of r){let a=y(n||l.document);for(let f=0;f<a.length;f++){let u=a[f];N(u,e,t)&&o.push({element:u,frame:l})}}return{elements:o.filter(l=>{let a=l.element;if(k(a,e,t))return!0;for(let u of o)if(u.element!==a&&a.contains(u.element))return!1;return!0}).map(l=>{let a=S(l.element),f=l.element.tagName.toLowerCase(),u=A(l.element);return l.frame.isMainFrame?{element:l.element,boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}:{boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}})}}function k(e,t,n=!1){if(t==null||t==="")return!0;let o=E;for(let i=0;i<o.length;i++){let s=o[i],l;try{l=e.getAttribute(s)}catch(a){continue}if(l){if(s==="aria-labelledby"){if(n?l===t:l.includes(t))return!0;let a=F(e);if(a&&(n?a===t:a.includes(t)))return!0}else if(n?l===t:l.includes(t))return!0}}let r=$(e);return!!(n?r===t:r.includes(t))}function me(e=null,t=null,n=null){let o=e!=null,r=o?[e]:Object.keys(g);if(o){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let s=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(n&&n.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(s),{[e]:{visible:0,hidden:0,total:0}}}}let i={};for(let s=0;s<r.length;s++)i[r[s]]={visible:0,hidden:0,total:0};for(let s=0;s<r.length;s++){let l=r[s],a=X(l,null,!1,t,n),f=i[l];for(let u=0;u<a.elements.length;u++){let d=a.elements[u].isHidden?"hidden":"visible";f[d]+=1,f.total+=1}}return i}function X(e=null,t=null,n=!1,o=null,r=null){if(t==null&&(t=""),e!=null){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let f=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(f),{elements:[]}}}if(t!==""&&typeof t!="string")throw new TypeError(`text must be a string, got ${typeof t}`);let i=[],s=T(window);for(let f of s){let u=y(o||f.document);for(let c=0;c<u.length;c++){let d=u[c];e!=null&&!p(d,e)||t!==""&&!N(d,t,n)||i.push({element:d,frame:f})}}return{elements:(t!==""?i.filter(f=>{let u=f.element;if(k(u,t,n))return!0;for(let d of i)if(d.element!==u&&u.contains(d.element))return!1;return!0}):i).map(f=>{let u=S(f.element),c=f.element.tagName.toLowerCase(),d=A(f.element);return f.frame.isMainFrame?{element:f.element,boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}:{boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}})}}function L(e){if(e.parentElement)return e.parentElement;try{let t=e.getRootNode();if(t&&t.host)return t.host}catch(t){}return null}function q(e){let t=L(e);if(!t)return[];if(t.shadowRoot)try{return Array.from(t.shadowRoot.children)}catch(n){return[]}return Array.from(t.children)}function he(e,t){let n=L(e);for(;n;){if(p(n,t))return n;n=L(n)}let o=e.children||[];for(let s of o)if(p(s,t))return s;let r=q(e);for(let s of r)if(s!==e&&p(s,t))return s;for(let s of r){if(s===e)continue;let l=y(s);for(let a=0;a<l.length;a++)if(p(l[a],t))return l[a]}let i=e.parentElement;for(;i;){let s=q(i);for(let l of s)if(l!==i){if(p(l,t))return l;let a=y(l);for(let f=0;f<a.length;f++)if(p(a[f],t))return a[f]}i=i.parentElement}return null}function ge(e,t,n=!1,o=null,r=null){let i=e!=null&&e!=="",s=t!=null&&t!=="";if(i&&!s)return z(e,o,r);if(!i&&s)return W(t,n,o);if(i){if(typeof e!="string")throw new TypeError(`elementType must be a string, got ${typeof e}`);if(!g[e]){let c=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(c),{elements:[]}}}if(s&&typeof t!="string")throw new TypeError(`attributeText must be a string, got ${typeof t}`);let l=[],a=T(window);for(let c of a){let d=y(o||c.document);for(let m=0;m<d.length;m++){let h=d[m];i&&!p(h,e)||s&&!N(h,t,n)||l.push({element:h,frame:c})}}if(l.length===0&&i&&s){let c=[];for(let m of a){let h=y(o||m.document);for(let O=0;O<h.length;O++){let M=h[O];N(M,t,n)&&k(M,t,n)&&c.push({element:M,frame:m})}}let d=new Set;for(let m of c){let h=he(m.element,e);h&&!d.has(h)&&(d.add(h),l.push({element:h,frame:m.frame}))}}return{elements:(s?l.filter(c=>{let d=c.element;if(k(d,t,n))return!0;for(let h of l)if(h.element!==d&&d.contains(h.element))return!1;return!0}):l).map(c=>{let d=S(c.element),m=c.element.tagName.toLowerCase(),h=A(c.element);return c.frame.isMainFrame?{element:c.element,boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}:{boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}})}}function Y(e){return e?e&&e.elements&&Array.isArray(e.elements)?e.elements:Array.isArray(e)?e:[e]:[]}function pe(e,t="red",n=3){let o=Y(e);for(let r=0;r<o.length;r++){let i=o[r],s=i.element?i.element:i;s&&s.style&&(s.style.outline=`${n}px solid ${t}`,s.style.outlineOffset="2px",s.style.boxShadow="0 0 0 2px rgba(255, 255, 255, 0.8)",s.classList.add("elementfinder-highlighted"))}}function ye(e){let t=Y(e);for(let n=0;n<t.length;n++){let o=t[n],r=o.element?o.element:o;r&&r.style&&(r.style.outline="",r.style.outlineOffset="",r.style.boxShadow="",r.classList.remove("elementfinder-highlighted"))}}var x=[];function be(){let e=new Map,t=y();for(let r of t)r&&r.style&&r.style.animationPlayState!=="paused"&&(e.set(r,{animationPlayState:r.style.animationPlayState,transitionProperty:r.style.transitionProperty,webkitAnimationPlayState:r.style.webkitAnimationPlayState,webkitTransitionProperty:r.style.webkitTransitionProperty}),r.style.animationPlayState="paused",r.style.transitionProperty="none",r.style.webkitAnimationPlayState="paused",r.style.webkitTransitionProperty="none");let n=document.getElementById("elementfinder-animation-pause");n||(n=document.createElement("style"),n.id="elementfinder-animation-pause",n.textContent=`
|
|
1
|
+
var ElementFinder=(()=>{var D=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var Q=(e,t)=>{for(var n in t)D(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Z(t))!G.call(e,r)&&r!==n&&D(e,r,{get:()=>t[r],enumerable:!(o=Y(t,r))||o.enumerable});return e};var K=e=>J(D({},"__esModule",{value:!0}),e);var Te={};Q(Te,{ELEMENT_DEFINITIONS:()=>g,findElements:()=>R,findElementsByAttribute:()=>W,findElementsByType:()=>de,findProbableElements:()=>ge,getAllElements:()=>y,getAllFrames:()=>T,getBoundingBox:()=>S,getElementCounts:()=>me,getElementDescriptor:()=>fe,getSearchableAttributeValues:()=>_,getSearchableAttributes:()=>re,getValidAttributes:()=>xe,getValidTypes:()=>Ee,highlight:()=>pe,isHidden:()=>A,matchesAttribute:()=>N,matchesType:()=>p,parseCondition:()=>F,parseXPath:()=>w,pauseAnimations:()=>be,resumeAnimations:()=>we,setSearchableAttributes:()=>ne,splitByOperator:()=>B,unhighlight:()=>ye});var P={link:"self::a or @role='link' or @href",navigation:"@role='navigation' or self::nav",heading:"@role='heading' or self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6",button:"self::button or @role='button' or @type='button' or @type='submit'",checkbox:"(self::input and @type='checkbox') or @role='checkbox'",switch:"(self::input and @type='checkbox') or @role='switch' or (self::button and (contains(@class, 'switch') or @data-state))",slider:"self::input[@type='range'] or @role='slider'",datepicker:"self::input[@type='date'] or @role='date'",colorpicker:"self::input[@type='color'] or @role='color'",radio:"(self::input and @type='radio') or @role='radio'",dropdown:"(self::select[descendant::option] or @role='combobox' or @role='listbox' or contains(@class, 'dropdown') or contains(@class, 'trigger') or ancestor::*[contains(@class, 'dropdown') or @role='combobox'])",textbox:"self::textarea or (self::input and (@type='text' or @type='password' or @type='search' or @type='email' or @type='number' or @type='tel' or @type='url')) or @role='textbox'",file:"self::input and @type='file'",list:"self::ul or self::ol or @role='list'",listitem:"self::li or @role='listitem'",menu:"self::menu or @role='menu'",menuitem:"@role='menuitem'",toolbar:"@role='toolbar'",dialog:"@role='dialog' or @role='alertdialog'",table:"self::table or @role='table'",row:"self::tr or @role='row'",column:"self::td or self::th or @role='cell' or @role='gridcell' or @role='columnheader'",cell:"self::td or @role='cell' or @role='gridcell'",image:"self::img or @role='img' or @alt",element:"true()"};var U=["placeholder","value","data-value","data-test-id","data-testid","id","resource-id","name","aria-label","hint","title","tooltip","alt","src","aria-labelledby"];var b={selfWithTag:/^self::([a-zA-Z0-9-]+)(?:\[([^\]]+)\])?$/,contains:/contains\(@([a-zA-Z0-9-]+),\s*['"]([^'"]+)['"]\)/i,attrEquals:/@([a-zA-Z0-9-]+)\s*=\s*['"]([^'"]*)['"]/,attrExists:/^@([a-zA-Z0-9-]+)$/,descendant:/descendant::([a-zA-Z0-9-]+)/i,ancestor:/ancestor::\*\[([^\]]+)\]/i,operatorOr:/^\s*\bor\b\s*/i,operatorAnd:/^\s*\band\b\s*/i},te=100,j=25,C=new Map;for(let[e,t]of Object.entries(P))t==="true()"?C.set(e,()=>!0):C.set(e,n=>w(t,n));var E=U;function ne(e){if(!Array.isArray(e))throw new TypeError("attributes must be an array");E=e}function re(){return[...E]}function _(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{};let t={},n=E;for(let o=0;o<n.length;o++){let r=n[o],i;try{i=e.getAttribute(r)}catch(s){continue}i!=null&&i!==""&&(t[r]=i)}return t}function I(e){return e==null?"":String(e).replace(/\s+/g," ").trim()}function q(e){if(e==null)return"";let t=String(e).split(/\r\n|\r|\n/),n="";for(let i=0;i<t.length&&(n=I(t[i]),!n);i++);if(!n||n.length<=j)return n;let o=n.slice(0,j),r=o.lastIndexOf(" ");return r>0?o.slice(0,r):n}function oe(e){let t=I(e);if(!t)return"";let n=t.split(/[?#]/)[0],o=Math.max(n.lastIndexOf("/"),n.lastIndexOf("\\")),r=o>=0?n.slice(o+1):n,i=r.lastIndexOf(".");return i>0?r.slice(0,i):r}function ie(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o=e.ownerDocument||document,r="";for(let i of n)try{let s=o.getElementById(i);if(!s)continue;let l=I(s.textContent);l&&(r=r?`${r} ${l}`:l)}catch(s){}return r}function V(e){let t=_(e),n=E;for(let i=0;i<n.length;i++){let s=n[i];if(!Object.prototype.hasOwnProperty.call(t,s))continue;let l=s==="aria-labelledby"?ie(e):s==="src"?oe(t[s]):t[s],a=I(l);if(a)return{attributeName:s,identifiableText:a}}let o=q($(e));if(o)return{attributeName:"text",identifiableText:o};let r=q(e.textContent);return r?{attributeName:"text",identifiableText:r}:null}function se(e){if(!e||!e.ownerDocument)return null;try{let t=T(window);for(let n=0;n<t.length;n++)if(t[n].document===e.ownerDocument)return t[n].document}catch(t){}return e.ownerDocument}function le(e,t){let n=se(e);if(!n)return{index:1};let o=y(n),r=1,i=0;for(let s=0;s<o.length;s++){let l=o[s];if(l!==e&&(l===n.documentElement||l.tagName==="BODY"))continue;let a=V(l);!a||a.identifiableText!==t||(i++,l===e&&(r=i))}return{index:r}}function ae(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return null;let t=Object.keys(g);for(let n=0;n<t.length;n++){let o=t[n];if(o!=="element"&&p(e,o))return o}return"element"}function fe(e){if(e==null||e.nodeType!==Node.ELEMENT_NODE)return{identifiableText:null,attributeName:null,index:1,type:null,tagName:null};let t=ae(e),n=V(e);if(!n)return{identifiableText:null,attributeName:null,index:1,type:t,tagName:e.tagName.toLowerCase()};let o=le(e,n.identifiableText);return{identifiableText:n.identifiableText,attributeName:n.attributeName,index:o.index,type:t,tagName:e.tagName.toLowerCase()}}function w(e,t,n=0){if(e==null||t==null)return!1;if(n>te)throw new Error("XPath expression exceeds maximum recursion depth");if(e=e.trim(),e==="true()")return!0;if(e[0]==="("&&e[e.length-1]===")"){let i=1,s=!0;for(let l=1;l<e.length-1;l++)if(e[l]==="("?i++:e[l]===")"&&i--,i===0){s=!1;break}if(s)return w(e.slice(1,-1),t,n+1)}let o=B(e,"or");if(o.length>1){for(let i of o)if(w(i,t,n+1))return!0;return!1}let r=B(e,"and");if(r.length>1){for(let i of r)if(!w(i,t,n+1))return!1;return!0}return F(e,t,n)}function B(e,t){let n=[],o=0,r="",i=!1,s="",l=t==="or"?b.operatorOr:b.operatorAnd;for(let a=0;a<e.length;a++){let f=e[a];if((f==="'"||f==='"')&&(a===0||e[a-1]!=="\\")&&(i?f===s&&(i=!1):(i=!0,s=f)),!i&&(f==="("?o++:f===")"&&o--,o===0)){let c=e.slice(a).match(l);if(c){n.push(r.trim()),a+=c[0].length-1,r="";continue}}r+=f}return r.trim()&&n.push(r.trim()),n}function F(e,t,n=0){if(e==null||t==null)return!1;e=e.trim();let o=e.match(b.selfWithTag);if(o){let f=o[1].toUpperCase();return t.tagName!==f?!1:o[2]?w(o[2],t,n+1):!0}let r=e.match(b.contains);if(r)return(t.getAttribute(r[1])||"").toLowerCase().includes(r[2].toLowerCase());let i=e.match(b.attrEquals);if(i)return t.getAttribute(i[1])===i[2];let s=e.match(b.attrExists);if(s)return t.hasAttribute(s[1]);let l=e.match(b.descendant);if(l)return t.querySelector(l[1])!==null;let a=e.match(b.ancestor);if(a){let f=t.parentElement;for(;f;){if(w(a[1],f,n+1))return!0;f=f.parentElement}return!1}return!1}var g=Object.freeze(P);function $(e){let t="";for(let n=0;n<e.childNodes.length;n++){let o=e.childNodes[n];o.nodeType===Node.TEXT_NODE&&(t+=o.textContent)}return t.trim()}function ce(e){if(e.tagName==="STYLE"||e.tagName==="SCRIPT"||e.querySelector("STYLE, SCRIPT"))return!0;let t=e.parentElement;for(;t;){if(t.tagName==="STYLE"||t.tagName==="SCRIPT")return!0;t=t.parentElement}return!1}function z(e){let t=e.getAttribute("aria-labelledby");if(!t)return"";let n=t.split(/\s+/),o="";for(let r of n)try{let i=document.getElementById(r);i&&(o+=i.textContent)}catch(i){}return o}function N(e,t,n=!1){if(e==null)return!1;if(t==null||t==="")return!0;if(ce(e))return!1;let o=E;for(let s=0;s<o.length;s++){let l=o[s],a;try{a=e.getAttribute(l)}catch(f){continue}if(a){if(l==="aria-labelledby"){if(n?a===t:a.includes(t))return!0;let f=z(e);if(f&&(n?f===t:f.includes(t)))return!0}else if(n?a===t:a.includes(t))return!0}}let r=$(e);if(n?r===t:r.includes(t))return!0;let i=e.textContent;return!!(n?i.trim()===t:i.includes(t))}function p(e,t){if(e==null)return!1;let n=C.get(t);return n?n(e):!1}function y(e=document){let t=[];if(e==null)return t;let n=e.nodeType===Node.DOCUMENT_NODE?e.documentElement:e;if(!n)return t;let o=[n];for(;o.length>0;){let r=o.pop();if(r.nodeType!==Node.ELEMENT_NODE||r.tagName==="SCRIPT"||r.tagName==="STYLE")continue;t.push(r);let i=r.children;for(let s=i.length-1;s>=0;s--)o.push(i[s]);try{if(r.shadowRoot){let s=r.shadowRoot.children;for(let l=s.length-1;l>=0;l--)o.push(s[l])}}catch(s){}}return t}function T(e=window){let t=[];try{t.push({window:e,document:e.document,isMainFrame:!0,frameIndex:-1});let n=e.document.querySelectorAll("iframe");for(let o=0;o<n.length;o++){let r=n[o];try{r.contentWindow&&r.contentDocument&&t.push({window:r.contentWindow,document:r.contentDocument,isMainFrame:!1,frameElement:r,frameIndex:o})}catch(i){i.name==="SecurityError"?console.warn("Skipping cross-origin iframe:",i.message):console.warn("Error accessing iframe:",i.message)}}}catch(n){console.warn("Error getting frames:",n.message)}return t}function S(e){let t=e.getBoundingClientRect();return{x:t.x,y:t.y,width:t.width,height:t.height,top:t.top,bottom:t.bottom,left:t.left,right:t.right,midx:t.x+t.width/2,midy:t.y+t.height/2,tagName:e.tagName.toLowerCase()}}function A(e){if(e==null)return!0;let t=e;for(;t;){if(ue(t))return!0;t=t.parentElement}return!1}function ue(e){if(e.hasAttribute("hidden")||e.getAttribute("aria-hidden")==="true"||e.inert||e.offsetWidth===0&&e.offsetHeight===0)return!0;if(typeof e.checkVisibility=="function")return!e.checkVisibility({checkOpacity:!0,checkVisibilityCSS:!0,contentVisibilityAuto:!0});try{let t=window.getComputedStyle(e);if(t.visibility==="hidden"||t.visibility==="collapse"||t.display==="none"||t.opacity==="0")return!0}catch(t){}return!1}function de(e="element",t=null,n=null){if(e==null&&(e="element"),typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);let o=n&&n.failOnUnknownType===!0;if(e&&!g[e]){let a=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(o)throw new TypeError(`Unknown element type: ${e}`);return console.warn(a),{elements:[]}}let r=[],i=T(window);for(let a of i){let f=y(t||a.document);for(let u=0;u<f.length;u++){let c=f[u];e&&!p(c,e)||r.push({element:c,frame:a})}}let s=[];if(r.length>0){let a=new Set(r.map(u=>u.element)),f=new Set;for(let u=r.length-1;u>=0;u--){let c=r[u],d=c.element;if(!f.has(d)){s.unshift(c);let m=d.parentElement;for(;m;)a.has(m)&&f.add(m),m=m.parentElement}}}return{elements:s.map(a=>{let f=S(a.element),u=a.element.tagName.toLowerCase(),c=A(a.element);return a.frame.isMainFrame?{element:a.element,boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}:{boundingBox:f,tagName:u,frameIndex:a.frame.frameIndex,isHidden:c}})}}function W(e,t=!1,n=null){if(e==null&&(e=""),typeof e!="string")throw new TypeError(`value must be a string, got ${typeof e}`);let o=[],r=T(window);for(let l of r){let a=y(n||l.document);for(let f=0;f<a.length;f++){let u=a[f];N(u,e,t)&&o.push({element:u,frame:l})}}return{elements:o.filter(l=>{let a=l.element;if(k(a,e,t))return!0;for(let u of o)if(u.element!==a&&a.contains(u.element))return!1;return!0}).map(l=>{let a=S(l.element),f=l.element.tagName.toLowerCase(),u=A(l.element);return l.frame.isMainFrame?{element:l.element,boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}:{boundingBox:a,tagName:f,frameIndex:l.frame.frameIndex,isHidden:u}})}}function k(e,t,n=!1){if(t==null||t==="")return!0;let o=E;for(let i=0;i<o.length;i++){let s=o[i],l;try{l=e.getAttribute(s)}catch(a){continue}if(l){if(s==="aria-labelledby"){if(n?l===t:l.includes(t))return!0;let a=z(e);if(a&&(n?a===t:a.includes(t)))return!0}else if(n?l===t:l.includes(t))return!0}}let r=$(e);return!!(n?r===t:r.includes(t))}function me(e=null,t=null,n=null){let o=e!=null,r=o?[e]:Object.keys(g);if(o){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let s=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(n&&n.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(s),{[e]:{visible:0,hidden:0,total:0}}}}let i={};for(let s=0;s<r.length;s++)i[r[s]]={visible:0,hidden:0,total:0};for(let s=0;s<r.length;s++){let l=r[s],a=R(l,null,!1,t,n),f=i[l];for(let u=0;u<a.elements.length;u++){let d=a.elements[u].isHidden?"hidden":"visible";f[d]+=1,f.total+=1}}return i}function R(e=null,t=null,n=!1,o=null,r=null){if(t==null&&(t=""),e!=null){if(typeof e!="string")throw new TypeError(`type must be a string, got ${typeof e}`);if(!g[e]){let f=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(f),{elements:[]}}}if(t!==""&&typeof t!="string")throw new TypeError(`text must be a string, got ${typeof t}`);let i=[],s=T(window);for(let f of s){let u=y(o||f.document);for(let c=0;c<u.length;c++){let d=u[c];e!=null&&!p(d,e)||t!==""&&!N(d,t,n)||i.push({element:d,frame:f})}}return{elements:(t!==""?i.filter(f=>{let u=f.element;if(k(u,t,n))return!0;for(let d of i)if(d.element!==u&&u.contains(d.element))return!1;return!0}):i).map(f=>{let u=S(f.element),c=f.element.tagName.toLowerCase(),d=A(f.element);return f.frame.isMainFrame?{element:f.element,boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}:{boundingBox:u,tagName:c,frameIndex:f.frame.frameIndex,isHidden:d}})}}function L(e){if(e.parentElement)return e.parentElement;try{let t=e.getRootNode();if(t&&t.host)return t.host}catch(t){}return null}function H(e){let t=L(e);if(!t)return[];if(t.shadowRoot)try{return Array.from(t.shadowRoot.children)}catch(n){return[]}return Array.from(t.children)}function he(e,t){let n=L(e);for(;n;){if(p(n,t))return n;n=L(n)}let o=e.children||[];for(let s of o)if(p(s,t))return s;let r=H(e);for(let s of r)if(s!==e&&p(s,t))return s;for(let s of r){if(s===e)continue;let l=y(s);for(let a=0;a<l.length;a++)if(p(l[a],t))return l[a]}let i=e.parentElement;for(;i;){let s=H(i);for(let l of s)if(l!==i){if(p(l,t))return l;let a=y(l);for(let f=0;f<a.length;f++)if(p(a[f],t))return a[f]}i=i.parentElement}return null}function ge(e,t,n=!1,o=null,r=null){let i=e!=null&&e!=="",s=t!=null&&t!=="";if(i&&!s)return R(e,null,!1,o,r);if(!i&&s)return W(t,n,o);if(i){if(typeof e!="string")throw new TypeError(`elementType must be a string, got ${typeof e}`);if(!g[e]){let c=`Unknown element type: ${e}. Valid types: ${Object.keys(g).join(", ")}`;if(r&&r.failOnUnknownType===!0)throw new TypeError(`Unknown element type: ${e}`);return console.warn(c),{elements:[]}}}if(s&&typeof t!="string")throw new TypeError(`attributeText must be a string, got ${typeof t}`);let l=[],a=T(window);for(let c of a){let d=y(o||c.document);for(let m=0;m<d.length;m++){let h=d[m];i&&!p(h,e)||s&&!N(h,t,n)||l.push({element:h,frame:c})}}if(l.length===0&&i&&s){let c=[];for(let m of a){let h=y(o||m.document);for(let O=0;O<h.length;O++){let M=h[O];N(M,t,n)&&k(M,t,n)&&c.push({element:M,frame:m})}}let d=new Set;for(let m of c){let h=he(m.element,e);h&&!d.has(h)&&(d.add(h),l.push({element:h,frame:m.frame}))}}return{elements:(s?l.filter(c=>{let d=c.element;if(k(d,t,n))return!0;for(let h of l)if(h.element!==d&&d.contains(h.element))return!1;return!0}):l).map(c=>{let d=S(c.element),m=c.element.tagName.toLowerCase(),h=A(c.element);return c.frame.isMainFrame?{element:c.element,boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}:{boundingBox:d,tagName:m,frameIndex:c.frame.frameIndex,isHidden:h}})}}function X(e){return e?e&&e.elements&&Array.isArray(e.elements)?e.elements:Array.isArray(e)?e:[e]:[]}function pe(e,t="red",n=3){let o=X(e);for(let r=0;r<o.length;r++){let i=o[r],s=i.element?i.element:i;s&&s.style&&(s.style.outline=`${n}px solid ${t}`,s.style.outlineOffset="2px",s.style.boxShadow="0 0 0 2px rgba(255, 255, 255, 0.8)",s.classList.add("elementfinder-highlighted"))}}function ye(e){let t=X(e);for(let n=0;n<t.length;n++){let o=t[n],r=o.element?o.element:o;r&&r.style&&(r.style.outline="",r.style.outlineOffset="",r.style.boxShadow="",r.classList.remove("elementfinder-highlighted"))}}var x=[];function be(){let e=new Map,t=y();for(let r of t)r&&r.style&&r.style.animationPlayState!=="paused"&&(e.set(r,{animationPlayState:r.style.animationPlayState,transitionProperty:r.style.transitionProperty,webkitAnimationPlayState:r.style.webkitAnimationPlayState,webkitTransitionProperty:r.style.webkitTransitionProperty}),r.style.animationPlayState="paused",r.style.transitionProperty="none",r.style.webkitAnimationPlayState="paused",r.style.webkitTransitionProperty="none");let n=document.getElementById("elementfinder-animation-pause");n||(n=document.createElement("style"),n.id="elementfinder-animation-pause",n.textContent=`
|
|
2
2
|
*, *::before, *::after {
|
|
3
3
|
animation-play-state: paused !important;
|
|
4
4
|
transition-property: none !important;
|
|
@@ -12,4 +12,4 @@ var ElementFinder=(()=>{var D=Object.defineProperty;var Z=Object.getOwnPropertyD
|
|
|
12
12
|
transition-duration: 0s !important;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
`,document.head.appendChild(n));let o={originalStyles:e,pausedCount:e.size};return x.push(o),o}function we(e){if(e){let n=x.indexOf(e);if(n===-1)return;x.splice(n,1)}else{if(x.length===0)return;e=x.pop()}let t=e.originalStyles;if(t)for(let[n,o]of t)n&&n.style&&(n.style.animationPlayState=o.animationPlayState||"",n.style.transitionProperty=o.transitionProperty||"",n.style.webkitAnimationPlayState=o.webkitAnimationPlayState||"",n.style.webkitTransitionProperty=o.webkitTransitionProperty||"");if(x.length===0){let n=document.getElementById("elementfinder-animation-pause");n&&n.remove()}}function Ee(){return Object.keys(g)}function xe(){return[...E]}return
|
|
15
|
+
`,document.head.appendChild(n));let o={originalStyles:e,pausedCount:e.size};return x.push(o),o}function we(e){if(e){let n=x.indexOf(e);if(n===-1)return;x.splice(n,1)}else{if(x.length===0)return;e=x.pop()}let t=e.originalStyles;if(t)for(let[n,o]of t)n&&n.style&&(n.style.animationPlayState=o.animationPlayState||"",n.style.transitionProperty=o.transitionProperty||"",n.style.webkitAnimationPlayState=o.webkitAnimationPlayState||"",n.style.webkitTransitionProperty=o.webkitTransitionProperty||"");if(x.length===0){let n=document.getElementById("elementfinder-animation-pause");n&&n.remove()}}function Ee(){return Object.keys(g)}function xe(){return[...E]}return K(Te);})();
|
package/package.json
CHANGED
package/src/element-finder.js
CHANGED
|
@@ -1310,9 +1310,10 @@ export function findProbableElements(elementType, attributeText, exact = false,
|
|
|
1310
1310
|
const hasType = elementType !== null && elementType !== undefined && elementType !== '';
|
|
1311
1311
|
const hasText = attributeText !== null && attributeText !== undefined && attributeText !== '';
|
|
1312
1312
|
|
|
1313
|
-
// If only type is provided, delegate to
|
|
1313
|
+
// If only type is provided, delegate to the same type-only search used by
|
|
1314
|
+
// findElements(type, '') so counts and result sets match exactly.
|
|
1314
1315
|
if (hasType && !hasText) {
|
|
1315
|
-
return
|
|
1316
|
+
return findElements(elementType, null, false, parent, options);
|
|
1316
1317
|
}
|
|
1317
1318
|
|
|
1318
1319
|
// If only text is provided, delegate to findElementsByAttribute
|