webdriver-sizzle
Version:
Locate a selenium-webdriver element by sizzle CSS selector
2 lines (1 loc) • 15 kB
JavaScript
!function(){function e(e,t,n,o,i,u){for(var a=0,l=o.length;l>a;a++){var f=o[a];if(f){var c=!1;for(f=f[e];f;){if(f[r]===n){c=o[f.sizset];break}if(1!==f.nodeType||u||(f[r]=n,f.sizset=a),f.nodeName.toLowerCase()===t){c=f;break}f=f[e]}o[a]=c}}}function t(e,t,n,o,i,u){for(var a=0,l=o.length;l>a;a++){var f=o[a];if(f){var c=!1;for(f=f[e];f;){if(f[r]===n){c=o[f.sizset];break}if(1===f.nodeType)if(u||(f[r]=n,f.sizset=a),"string"!=typeof t){if(f===t){c=!0;break}}else if(s.filter(t,[f]).length>0){c=f;break}f=f[e]}o[a]=c}}}var n=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,r="sizcache"+(Math.random()+"").replace(".",""),o=0,i=Object.prototype.toString,u=!1,a=!0,l=/\\/g,f=/\r\n/g,c=/\W/;[0,0].sort(function(){return a=!1,0});var s=function(e,t,r,o){r=r||[],t=t||document;var u=t;if(1!==t.nodeType&&9!==t.nodeType)return[];if(!e||"string"!=typeof e)return r;var a,l,f,c,d,h,g,v,N=!0,b=s.isXML(t),x=[],C=e;do if(n.exec(""),a=n.exec(C),a&&(C=a[3],x.push(a[1]),a[2])){c=a[3];break}while(a);if(x.length>1&&m.exec(e))if(2===x.length&&p.relative[x[0]])l=T(x[0]+x[1],t,o);else for(l=p.relative[x[0]]?[t]:s(x.shift(),t);x.length;)e=x.shift(),p.relative[e]&&(e+=x.shift()),l=T(e,l,o);else if(!o&&x.length>1&&9===t.nodeType&&!b&&p.match.ID.test(x[0])&&!p.match.ID.test(x[x.length-1])&&(d=s.find(x.shift(),t,b),t=d.expr?s.filter(d.expr,d.set)[0]:d.set[0]),t)for(d=o?{expr:x.pop(),set:y(o)}:s.find(x.pop(),1!==x.length||"~"!==x[0]&&"+"!==x[0]||!t.parentNode?t:t.parentNode,b),l=d.expr?s.filter(d.expr,d.set):d.set,x.length>0?f=y(l):N=!1;x.length;)h=x.pop(),g=h,p.relative[h]?g=x.pop():h="",null==g&&(g=t),p.relative[h](f,g,b);else f=x=[];if(f||(f=l),f||s.error(h||e),"[object Array]"===i.call(f))if(N)if(t&&1===t.nodeType)for(v=0;null!=f[v];v++)f[v]&&(f[v]===!0||1===f[v].nodeType&&s.contains(t,f[v]))&&r.push(l[v]);else for(v=0;null!=f[v];v++)f[v]&&1===f[v].nodeType&&r.push(l[v]);else r.push.apply(r,f);else y(f,r);return c&&(s(c,u,r,o),s.uniqueSort(r)),r};s.uniqueSort=function(e){if(N&&(u=a,e.sort(N),u))for(var t=1;t<e.length;t++)e[t]===e[t-1]&&e.splice(t--,1);return e},s.matches=function(e,t){return s(e,null,null,t)},s.matchesSelector=function(e,t){return s(t,null,null,[e]).length>0},s.find=function(e,t,n){var r,o,i,u,a,f;if(!e)return[];for(o=0,i=p.order.length;i>o;o++)if(a=p.order[o],(u=p.leftMatch[a].exec(e))&&(f=u[1],u.splice(1,1),"\\"!==f.substr(f.length-1)&&(u[1]=(u[1]||"").replace(l,""),r=p.find[a](u,t,n),null!=r))){e=e.replace(p.match[a],"");break}return r||(r="undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName("*"):[]),{set:r,expr:e}},s.filter=function(e,t,n,r){for(var o,i,u,a,l,f,c,d,m,h=e,g=[],y=t,v=t&&t[0]&&s.isXML(t[0]);e&&t.length;){for(u in p.filter)if(null!=(o=p.leftMatch[u].exec(e))&&o[2]){if(f=p.filter[u],c=o[1],i=!1,o.splice(1,1),"\\"===c.substr(c.length-1))continue;if(y===g&&(g=[]),p.preFilter[u])if(o=p.preFilter[u](o,y,n,g,r,v)){if(o===!0)continue}else i=a=!0;if(o)for(d=0;null!=(l=y[d]);d++)l&&(a=f(l,o,d,y),m=r^a,n&&null!=a?m?i=!0:y[d]=!1:m&&(g.push(l),i=!0));if(void 0!==a){if(n||(y=g),e=e.replace(p.match[u],""),!i)return[];break}}if(e===h){if(null!=i)break;s.error(e)}h=e}return y},s.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)};var d=s.getText=function(e){var t,n,r=e.nodeType,o="";if(r){if(1===r||9===r||11===r){if("string"==typeof e.textContent)return e.textContent;if("string"==typeof e.innerText)return e.innerText.replace(f,"");for(e=e.firstChild;e;e=e.nextSibling)o+=d(e)}else if(3===r||4===r)return e.nodeValue}else for(t=0;n=e[t];t++)8!==n.nodeType&&(o+=d(n));return o},p=s.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(e){return e.getAttribute("href")},type:function(e){return e.getAttribute("type")}},relative:{"+":function(e,t){var n="string"==typeof t,r=n&&!c.test(t),o=n&&!r;r&&(t=t.toLowerCase());for(var i,u=0,a=e.length;a>u;u++)if(i=e[u]){for(;(i=i.previousSibling)&&1!==i.nodeType;);e[u]=o||i&&i.nodeName.toLowerCase()===t?i||!1:i===t}o&&s.filter(t,e,!0)},">":function(e,t){var n,r="string"==typeof t,o=0,i=e.length;if(r&&!c.test(t)){for(t=t.toLowerCase();i>o;o++)if(n=e[o]){var u=n.parentNode;e[o]=u.nodeName.toLowerCase()===t?u:!1}}else{for(;i>o;o++)n=e[o],n&&(e[o]=r?n.parentNode:n.parentNode===t);r&&s.filter(t,e,!0)}},"":function(n,r,i){var u,a=o++,l=t;"string"!=typeof r||c.test(r)||(r=r.toLowerCase(),u=r,l=e),l("parentNode",r,a,n,u,i)},"~":function(n,r,i){var u,a=o++,l=t;"string"!=typeof r||c.test(r)||(r=r.toLowerCase(),u=r,l=e),l("previousSibling",r,a,n,u,i)}},find:{ID:function(e,t,n){if("undefined"!=typeof t.getElementById&&!n){var r=t.getElementById(e[1]);return r&&r.parentNode?[r]:[]}},NAME:function(e,t){if("undefined"!=typeof t.getElementsByName){for(var n=[],r=t.getElementsByName(e[1]),o=0,i=r.length;i>o;o++)r[o].getAttribute("name")===e[1]&&n.push(r[o]);return 0===n.length?null:n}},TAG:function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e[1]):void 0}},preFilter:{CLASS:function(e,t,n,r,o,i){if(e=" "+e[1].replace(l,"")+" ",i)return e;for(var u,a=0;null!=(u=t[a]);a++)u&&(o^(u.className&&(" "+u.className+" ").replace(/[\t\n\r]/g," ").indexOf(e)>=0)?n||r.push(u):n&&(t[a]=!1));return!1},ID:function(e){return e[1].replace(l,"")},TAG:function(e,t){return e[1].replace(l,"").toLowerCase()},CHILD:function(e){if("nth"===e[1]){e[2]||s.error(e[0]),e[2]=e[2].replace(/^\+|\s*/g,"");var t=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec("even"===e[2]&&"2n"||"odd"===e[2]&&"2n+1"||!/\D/.test(e[2])&&"0n+"+e[2]||e[2]);e[2]=t[1]+(t[2]||1)-0,e[3]=t[3]-0}else e[2]&&s.error(e[0]);return e[0]=o++,e},ATTR:function(e,t,n,r,o,i){var u=e[1]=e[1].replace(l,"");return!i&&p.attrMap[u]&&(e[1]=p.attrMap[u]),e[4]=(e[4]||e[5]||"").replace(l,""),"~="===e[2]&&(e[4]=" "+e[4]+" "),e},PSEUDO:function(e,t,r,o,i){if("not"===e[1]){if(!((n.exec(e[3])||"").length>1||/^\w/.test(e[3]))){var u=s.filter(e[3],t,r,!0^i);return r||o.push.apply(o,u),!1}e[3]=s(e[3],null,null,t)}else if(p.match.POS.test(e[0])||p.match.CHILD.test(e[0]))return!0;return e},POS:function(e){return e.unshift(!0),e}},filters:{enabled:function(e){return e.disabled===!1&&"hidden"!==e.type},disabled:function(e){return e.disabled===!0},checked:function(e){return e.checked===!0},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},parent:function(e){return!!e.firstChild},empty:function(e){return!e.firstChild},has:function(e,t,n){return!!s(n[3],e).length},header:function(e){return/h\d/i.test(e.nodeName)},text:function(e){var t=e.getAttribute("type"),n=e.type;return"input"===e.nodeName.toLowerCase()&&"text"===n&&(t===n||null===t)},radio:function(e){return"input"===e.nodeName.toLowerCase()&&"radio"===e.type},checkbox:function(e){return"input"===e.nodeName.toLowerCase()&&"checkbox"===e.type},file:function(e){return"input"===e.nodeName.toLowerCase()&&"file"===e.type},password:function(e){return"input"===e.nodeName.toLowerCase()&&"password"===e.type},submit:function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&"submit"===e.type},image:function(e){return"input"===e.nodeName.toLowerCase()&&"image"===e.type},reset:function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&"reset"===e.type},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},input:function(e){return/input|select|textarea|button/i.test(e.nodeName)},focus:function(e){return e===e.ownerDocument.activeElement}},setFilters:{first:function(e,t){return 0===t},last:function(e,t,n,r){return t===r.length-1},even:function(e,t){return t%2===0},odd:function(e,t){return t%2===1},lt:function(e,t,n){return t<n[3]-0},gt:function(e,t,n){return t>n[3]-0},nth:function(e,t,n){return n[3]-0===t},eq:function(e,t,n){return n[3]-0===t}},filter:{PSEUDO:function(e,t,n,r){var o=t[1],i=p.filters[o];if(i)return i(e,n,t,r);if("contains"===o)return(e.textContent||e.innerText||d([e])||"").indexOf(t[3])>=0;if("not"===o){for(var u=t[3],a=0,l=u.length;l>a;a++)if(u[a]===e)return!1;return!0}s.error(o)},CHILD:function(e,t){var n,o,i,u,a,l,f=t[1],c=e;switch(f){case"only":case"first":for(;c=c.previousSibling;)if(1===c.nodeType)return!1;if("first"===f)return!0;c=e;case"last":for(;c=c.nextSibling;)if(1===c.nodeType)return!1;return!0;case"nth":if(n=t[2],o=t[3],1===n&&0===o)return!0;if(i=t[0],u=e.parentNode,u&&(u[r]!==i||!e.nodeIndex)){for(a=0,c=u.firstChild;c;c=c.nextSibling)1===c.nodeType&&(c.nodeIndex=++a);u[r]=i}return l=e.nodeIndex-o,0===n?0===l:l%n===0&&l/n>=0}},ID:function(e,t){return 1===e.nodeType&&e.getAttribute("id")===t},TAG:function(e,t){return"*"===t&&1===e.nodeType||!!e.nodeName&&e.nodeName.toLowerCase()===t},CLASS:function(e,t){return(" "+(e.className||e.getAttribute("class"))+" ").indexOf(t)>-1},ATTR:function(e,t){var n=t[1],r=s.attr?s.attr(e,n):p.attrHandle[n]?p.attrHandle[n](e):null!=e[n]?e[n]:e.getAttribute(n),o=r+"",i=t[2],u=t[4];return null==r?"!="===i:!i&&s.attr?null!=r:"="===i?o===u:"*="===i?o.indexOf(u)>=0:"~="===i?(" "+o+" ").indexOf(u)>=0:u?"!="===i?o!==u:"^="===i?0===o.indexOf(u):"$="===i?o.substr(o.length-u.length)===u:"|="===i?o===u||o.substr(0,u.length+1)===u+"-":!1:o&&r!==!1},POS:function(e,t,n,r){var o=t[2],i=p.setFilters[o];return i?i(e,n,t,r):void 0}}},m=p.match.POS,h=function(e,t){return"\\"+(t-0+1)};for(var g in p.match)p.match[g]=new RegExp(p.match[g].source+/(?![^\[]*\])(?![^\(]*\))/.source),p.leftMatch[g]=new RegExp(/(^(?:.|\r|\n)*?)/.source+p.match[g].source.replace(/\\(\d+)/g,h));p.match.globalPOS=m;var y=function(e,t){return e=Array.prototype.slice.call(e,0),t?(t.push.apply(t,e),t):e};try{Array.prototype.slice.call(document.documentElement.childNodes,0)[0].nodeType}catch(v){y=function(e,t){var n=0,r=t||[];if("[object Array]"===i.call(e))Array.prototype.push.apply(r,e);else if("number"==typeof e.length)for(var o=e.length;o>n;n++)r.push(e[n]);else for(;e[n];n++)r.push(e[n]);return r}}var N,b;document.documentElement.compareDocumentPosition?N=function(e,t){return e===t?(u=!0,0):e.compareDocumentPosition&&t.compareDocumentPosition?4&e.compareDocumentPosition(t)?-1:1:e.compareDocumentPosition?-1:1}:(N=function(e,t){if(e===t)return u=!0,0;if(e.sourceIndex&&t.sourceIndex)return e.sourceIndex-t.sourceIndex;var n,r,o=[],i=[],a=e.parentNode,l=t.parentNode,f=a;if(a===l)return b(e,t);if(!a)return-1;if(!l)return 1;for(;f;)o.unshift(f),f=f.parentNode;for(f=l;f;)i.unshift(f),f=f.parentNode;n=o.length,r=i.length;for(var c=0;n>c&&r>c;c++)if(o[c]!==i[c])return b(o[c],i[c]);return c===n?b(e,i[c],-1):b(o[c],t,1)},b=function(e,t,n){if(e===t)return n;for(var r=e.nextSibling;r;){if(r===t)return-1;r=r.nextSibling}return 1}),function(){var e=document.createElement("div"),t="script"+(new Date).getTime(),n=document.documentElement;e.innerHTML="<a name='"+t+"'/>",n.insertBefore(e,n.firstChild),document.getElementById(t)&&(p.find.ID=function(e,t,n){if("undefined"!=typeof t.getElementById&&!n){var r=t.getElementById(e[1]);return r?r.id===e[1]||"undefined"!=typeof r.getAttributeNode&&r.getAttributeNode("id").nodeValue===e[1]?[r]:void 0:[]}},p.filter.ID=function(e,t){var n="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return 1===e.nodeType&&n&&n.nodeValue===t}),n.removeChild(e),n=e=null}(),function(){var e=document.createElement("div");e.appendChild(document.createComment("")),e.getElementsByTagName("*").length>0&&(p.find.TAG=function(e,t){var n=t.getElementsByTagName(e[1]);if("*"===e[1]){for(var r=[],o=0;n[o];o++)1===n[o].nodeType&&r.push(n[o]);n=r}return n}),e.innerHTML="<a href='#'></a>",e.firstChild&&"undefined"!=typeof e.firstChild.getAttribute&&"#"!==e.firstChild.getAttribute("href")&&(p.attrHandle.href=function(e){return e.getAttribute("href",2)}),e=null}(),document.querySelectorAll&&!function(){var e=s,t=document.createElement("div"),n="__sizzle__";if(t.innerHTML="<p class='TEST'></p>",!t.querySelectorAll||0!==t.querySelectorAll(".TEST").length){s=function(t,r,o,i){if(r=r||document,!i&&!s.isXML(r)){var u=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(t);if(u&&(1===r.nodeType||9===r.nodeType)){if(u[1])return y(r.getElementsByTagName(t),o);if(u[2]&&p.find.CLASS&&r.getElementsByClassName)return y(r.getElementsByClassName(u[2]),o)}if(9===r.nodeType){if("body"===t&&r.body)return y([r.body],o);if(u&&u[3]){var a=r.getElementById(u[3]);if(!a||!a.parentNode)return y([],o);if(a.id===u[3])return y([a],o)}try{return y(r.querySelectorAll(t),o)}catch(l){}}else if(1===r.nodeType&&"object"!==r.nodeName.toLowerCase()){var f=r,c=r.getAttribute("id"),d=c||n,m=r.parentNode,h=/^\s*[+~]/.test(t);c?d=d.replace(/'/g,"\\$&"):r.setAttribute("id",d),h&&m&&(r=r.parentNode);try{if(!h||m)return y(r.querySelectorAll("[id='"+d+"'] "+t),o)}catch(g){}finally{c||f.removeAttribute("id")}}}return e(t,r,o,i)};for(var r in e)s[r]=e[r];t=null}}(),function(){var e=document.documentElement,t=e.matchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.msMatchesSelector;if(t){var n=!t.call(document.createElement("div"),"div"),r=!1;try{t.call(document.documentElement,"[test!='']:sizzle")}catch(o){r=!0}s.matchesSelector=function(e,o){if(o=o.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']"),!s.isXML(e))try{if(r||!p.match.PSEUDO.test(o)&&!/!=/.test(o)){var i=t.call(e,o);if(i||!n||e.document&&11!==e.document.nodeType)return i}}catch(u){}return s(o,null,null,[e]).length>0}}}(),function(){var e=document.createElement("div");e.innerHTML="<div class='test e'></div><div class='test'></div>",e.getElementsByClassName&&0!==e.getElementsByClassName("e").length&&(e.lastChild.className="e",1!==e.getElementsByClassName("e").length&&(p.order.splice(1,0,"CLASS"),p.find.CLASS=function(e,t,n){return"undefined"==typeof t.getElementsByClassName||n?void 0:t.getElementsByClassName(e[1])},e=null))}(),document.documentElement.contains?s.contains=function(e,t){return e!==t&&(e.contains?e.contains(t):!0)}:document.documentElement.compareDocumentPosition?s.contains=function(e,t){return!!(16&e.compareDocumentPosition(t))}:s.contains=function(){return!1},s.isXML=function(e){var t=(e?e.ownerDocument||e:0).documentElement;return t?"HTML"!==t.nodeName:!1};var T=function(e,t,n){for(var r,o=[],i="",u=t.nodeType?[t]:t;r=p.match.PSEUDO.exec(e);)i+=r[0],e=e.replace(p.match.PSEUDO,"");e=p.relative[e]?e+"*":e;for(var a=0,l=u.length;l>a;a++)s(e,u[a],o,n);return s.filter(i,o)};"undefined"!=typeof module&&module.exports?module.exports=s:window.Sizzle=s}();