mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-11 12:11:04 +00:00
Update chrome.js
This commit is contained in:
parent
12bace0218
commit
bea0fb740d
125
lib/chrome.js
125
lib/chrome.js
|
@ -35,6 +35,7 @@ var ChromeObject = function() {
|
|||
this.isAttached = false;
|
||||
this.pageList = [];
|
||||
this.title = "";
|
||||
this.frameIndex = -1;
|
||||
|
||||
this.create = function() {
|
||||
this.oAutoIt = AutoItX.create().getInterface();
|
||||
|
@ -101,7 +102,11 @@ var ChromeObject = function() {
|
|||
console.log("Enabled debugging port:", port);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
this.setFrameIndex = function(idx) {
|
||||
this.frameIndex = idx;
|
||||
};
|
||||
|
||||
this.setPageId = function(s) {
|
||||
if (s == null) {
|
||||
var pageList = this.getPageList();
|
||||
|
@ -377,7 +382,15 @@ var ChromeObject = function() {
|
|||
return this.evaluate('location.href = "' + url + '"');
|
||||
};
|
||||
|
||||
this.evaluate = function(expression) {
|
||||
this.evaluate = function(expression, frameIndex) {
|
||||
var frameIndex = (typeof frameIndex !== "undefined" ? frameIndex : this.frameIndex);
|
||||
|
||||
if (frameIndex > -1) {
|
||||
expression = 'var __getFrame=function(e){return document.getElementsByTagName("frame")[e]},__getDocument=function(){return __getFrame(' + frameIndex + ').contentDocument||__getFrame(' + frameIndex + ').contentWindow.document},__getWindow=function(){return __getFrame(' + frameIndex + ').contentWindow};' + expression;
|
||||
} else {
|
||||
expression = 'var __getDocument=function(){return document},__getWindow=function(){return window};' + expression;
|
||||
}
|
||||
|
||||
try {
|
||||
return this.sendPageRPC("Runtime.evaluate", {
|
||||
"expression": expression
|
||||
|
@ -467,7 +480,7 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getScrollHeight = function(selector) {
|
||||
return parseInt(this.getEvaluatedValue('document.querySelector("' + selector + '").scrollHeight'));
|
||||
return parseInt(this.getEvaluatedValue('__getDocument().querySelector("' + selector + '").scrollHeight'));
|
||||
};
|
||||
|
||||
this.focusWithoutActivate = function() {
|
||||
|
@ -565,7 +578,7 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getScreenPosition = function() {
|
||||
var result = this.getEvaluatedValue('(function() { return [window.screenX, window.screenY].join(","); })();');
|
||||
var result = this.getEvaluatedValue('(function() { return [__getWindow().screenX, __getWindow().screenY].join(","); })();');
|
||||
var pos = result.split(',');
|
||||
return {
|
||||
"x": parseInt(pos[0]),
|
||||
|
@ -579,9 +592,9 @@ var ChromeObject = function() {
|
|||
var pos = -1;
|
||||
|
||||
if (startIndex > 0) {
|
||||
result = this.getEvaluatedValue('(function(k) { var rect = document.querySelectorAll("' + selector + '")[k].getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })(' + startIndex + ');');
|
||||
result = this.getEvaluatedValue('(function(k) { var rect = __getDocument().querySelectorAll("' + selector + '")[k].getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })(' + startIndex + ');');
|
||||
} else {
|
||||
result = this.getEvaluatedValue('(function() { var rect = document.querySelector("' + selector + '").getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();');
|
||||
result = this.getEvaluatedValue('(function() { var rect = __getDocument().querySelector("' + selector + '").getBoundingClientRect(); return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(","); })();');
|
||||
}
|
||||
|
||||
pos = result.split(',');
|
||||
|
@ -607,20 +620,20 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getElementPositionByText = function(selector, searchText) {
|
||||
var result;
|
||||
var result;
|
||||
var pos = -1;
|
||||
var s = '(function() {'
|
||||
+ ' var element = Object.values(document.querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' var element = Object.values(__getDocument().querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' return (x.innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
|
||||
+ ' });'
|
||||
+ ' if (element) {'
|
||||
+ ' var rect = element.getBoundingClientRect();'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(",");'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height)].join(",");'
|
||||
+ ' }'
|
||||
+ '})()'
|
||||
;
|
||||
|
||||
result = this.getEvaluatedValue(s);
|
||||
result = this.getEvaluatedValue(s);
|
||||
pos = result.split(',');
|
||||
if (pos.length == 6) {
|
||||
return {
|
||||
|
@ -650,7 +663,7 @@ var ChromeObject = function() {
|
|||
if (searchText.indexOf(':tokenize(') == 0) {
|
||||
searchText = searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')'));
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||
+ ' var keywords = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim().split(" ");'
|
||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||
|
@ -661,7 +674,7 @@ var ChromeObject = function() {
|
|||
+ ' var rect = element.getBoundingClientRect();'
|
||||
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
|
||||
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' } else {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -673,7 +686,7 @@ var ChromeObject = function() {
|
|||
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')')));
|
||||
if (p > 0) {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' return (Math.random() < ' + p + ');'
|
||||
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
||||
+ ' if (elements.length > 0) {'
|
||||
|
@ -681,7 +694,7 @@ var ChromeObject = function() {
|
|||
+ ' var rect = element.getBoundingClientRect();'
|
||||
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
|
||||
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' } else {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -689,7 +702,7 @@ var ChromeObject = function() {
|
|||
;
|
||||
} else {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '"));'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '"));'
|
||||
+ ' ' + (startIndex > 0 ? 'elements = elements.slice(' + startIndex + ');' : '')
|
||||
+ ' if (elements.length > 0) {'
|
||||
+ ' var k = Math.floor(Math.random() * elements.length);'
|
||||
|
@ -697,7 +710,7 @@ var ChromeObject = function() {
|
|||
+ ' var rect = element.getBoundingClientRect();'
|
||||
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
|
||||
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' } else {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -708,7 +721,7 @@ var ChromeObject = function() {
|
|||
|
||||
else {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||
+ ' var searchText = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim();'
|
||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||
|
@ -719,7 +732,7 @@ var ChromeObject = function() {
|
|||
+ ' var rect = element.getBoundingClientRect();'
|
||||
+ ' var elClassName = "welsonjs_" + parseInt(Math.random() * 1000000000);'
|
||||
+ ' element.setAttribute("class", element.getAttribute("class") + " " + elClassName);'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(window.pageXOffset + rect.left), parseInt(window.pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(__getWindow().pageXOffset + rect.left), parseInt(__getWindow().pageYOffset + rect.top), parseInt(rect.width), parseInt(rect.height), "." + elClassName].join(",");'
|
||||
+ ' } else {'
|
||||
+ ' return "";'
|
||||
+ ' }'
|
||||
|
@ -759,7 +772,7 @@ var ChromeObject = function() {
|
|||
if (searchText.indexOf(':tokenize(') == 0) {
|
||||
searchText = searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')'));
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||
+ ' var keywords = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim().split(" ");'
|
||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||
|
@ -774,7 +787,7 @@ var ChromeObject = function() {
|
|||
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.lastIndexOf(')')));
|
||||
if (p > 0) {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' return (Math.random() < ' + p + ');'
|
||||
+ ' ' + (startIndex > 0 ? '}).slice(' + startIndex + ');' : '});')
|
||||
+ ' if (elements.length > 0) {'
|
||||
|
@ -784,7 +797,7 @@ var ChromeObject = function() {
|
|||
;
|
||||
} else {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '"));'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '"));'
|
||||
+ ' ' + (startIndex > 0 ? 'elements = elements.slice(' + startIndex + ');' : '')
|
||||
+ ' if (elements.length > 0) {'
|
||||
+ ' var k = Math.floor(Math.random() * elements.length);'
|
||||
|
@ -795,7 +808,7 @@ var ChromeObject = function() {
|
|||
}
|
||||
} else {
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||
+ ' var el = x.querySelector("' + subSelector + '");'
|
||||
+ ' var searchText = decodeURIComponent("' + encodeURIComponent(searchText) + '").trim();'
|
||||
+ ' var text = el instanceof HTMLElement ? [el.innerText, el.getAttribute("aria-label"), el.getAttribute("class")].join(" ") : "";'
|
||||
|
@ -815,7 +828,7 @@ var ChromeObject = function() {
|
|||
var s = '';
|
||||
|
||||
s += '(function() {'
|
||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '"));'
|
||||
+ ' var elements = Object.values(__getDocument().querySelectorAll("' + selector + '"));'
|
||||
+ ' var result = -1;'
|
||||
+ ' for (var i = 0; i < elements.length; i++) {'
|
||||
+ ' if (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1) {'
|
||||
|
@ -834,7 +847,7 @@ var ChromeObject = function() {
|
|||
var height = 0;
|
||||
|
||||
if (this.debuggingPort > 0) {
|
||||
var result = this.getEvaluatedValue('(function(obj) { return Math.max(obj.scrollHeight, obj.clientHeight); })(document.querySelector("html"))');
|
||||
var result = this.getEvaluatedValue('(function(obj) { return Math.max(obj.scrollHeight, obj.clientHeight); })(__getDocument().querySelector("html"))');
|
||||
height = parseInt(result);
|
||||
}
|
||||
|
||||
|
@ -881,30 +894,30 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getCurrentDomain = function() {
|
||||
return this.getEvaluatedValue('document.domain') || '';
|
||||
return this.getEvaluatedValue('__getDocument().domain') || '';
|
||||
};
|
||||
|
||||
this.triggerEvent = function(eventName, selector) {
|
||||
if (selector.indexOf(':p(') < 0) {
|
||||
if (eventName == 'click') {
|
||||
return this.evaluate('document.querySelector("' + selector + '").click()');
|
||||
return this.evaluate('__getDocument().querySelector("' + selector + '").click()');
|
||||
} else {
|
||||
return this.evaluate('document.querySelector("' + selector + '").dispatchEvent(new Event("' + eventName + '"))');
|
||||
return this.evaluate('__getDocument().querySelector("' + selector + '").dispatchEvent(new Event("' + eventName + '"))');
|
||||
}
|
||||
} else {
|
||||
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
|
||||
var _selector = selector.substring(0, selector.indexOf(':'));
|
||||
if (p > 0) {
|
||||
return this.evaluate('(function(obj, p) { var element = Object.values(obj).find(function() { return (Math.random() < p); }); if(element) element.click(); })(document.querySelectorAll("' + _selector + '"), ' + p + ')');
|
||||
return this.evaluate('(function(obj, p) { var element = Object.values(obj).find(function() { return (Math.random() < p); }); if(element) element.click(); })(__getDocument().querySelectorAll("' + _selector + '"), ' + p + ')');
|
||||
} else {
|
||||
return this.evaluate('(function(obj) { var elements = Object.values(obj); var element = elements[Math.floor(Math.random() * elements.length)]; if(element) element.click(); })(document.querySelectorAll("' + _selector + '"))');
|
||||
return this.evaluate('(function(obj) { var elements = Object.values(obj); var element = elements[Math.floor(Math.random() * elements.length)]; if(element) element.click(); })(__getDocument().querySelectorAll("' + _selector + '"))');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.triggerEventByFind = function(eventName, selector, searchText) {
|
||||
var s = '(function() {'
|
||||
+ ' var element = Object.values(document.querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' var element = Object.values(__getDocument().querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' return (x.innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
|
||||
+ ' });'
|
||||
+ ' if (element) {'
|
||||
|
@ -917,7 +930,7 @@ var ChromeObject = function() {
|
|||
|
||||
this.triggerEventOnNestedFind = function(eventName, selector, subSelector, searchText) {
|
||||
var s = '(function() {'
|
||||
+ ' var element = Object.values(document.querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' var element = Object.values(__getDocument().querySelectorAll("' + selector + '")).find(function(x) {'
|
||||
+ ' return (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
|
||||
+ ' });'
|
||||
+ ' if (element) {'
|
||||
|
@ -929,25 +942,25 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.scrollTo = function(x, y) {
|
||||
return this.evaluate('window.scrollTo(parseInt(' + x + '), parseInt(' + y + '))');
|
||||
return this.evaluate('__getWindow().scrollTo(parseInt(' + x + '), parseInt(' + y + '))');
|
||||
};
|
||||
|
||||
this.scrollBy = function(dx, dy) {
|
||||
return this.evaluate('window.scrollBy(parseInt(' + dx + '), parseInt(' + dy + '))');
|
||||
return this.evaluate('__getWindow().scrollBy(parseInt(' + dx + '), parseInt(' + dy + '))');
|
||||
};
|
||||
|
||||
this.scrollToElement = function(selector, dx, dy) {
|
||||
return this.evaluate('(function(rect, dx, dy) { window.scrollTo(rect.x + dx, rect.y + dy); })(document.querySelector("' + selector + '").getBoundingClientRect(), parseInt("' + dx + '"), parseInt("' + dy + '"))');
|
||||
return this.evaluate('(function(rect, dx, dy) { __getWindow().scrollTo(rect.x + dx, rect.y + dy); })(__getDocument().querySelector("' + selector + '").getBoundingClientRect(), parseInt("' + dx + '"), parseInt("' + dy + '"))');
|
||||
};
|
||||
|
||||
this.reload = function() {
|
||||
//return this.sendPageRPC("Page.reload", {});
|
||||
return this.evaluate("window.reload()");
|
||||
return this.evaluate("__getWindow().reload()");
|
||||
};
|
||||
|
||||
this.hasClass = function(seletctor, className) {
|
||||
try {
|
||||
var result = this.getEvaluatedValue('document.querySelector("' + seletctor + '").getAttribute("class")');
|
||||
var result = this.getEvaluatedValue('__getDocument().querySelector("' + seletctor + '").getAttribute("class")');
|
||||
if (typeof(result) === "string") {
|
||||
return (result.split(' ').indexOf(className) > -1);
|
||||
} else {
|
||||
|
@ -959,7 +972,7 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.getAttribute = function(selector, attributeName) {
|
||||
return this.getEvaluatedValue('document.querySelector("' + selector + '").getAttribute("' + attributeName + '")');
|
||||
return this.getEvaluatedValue('__getDocument().querySelector("' + selector + '").getAttribute("' + attributeName + '")');
|
||||
};
|
||||
|
||||
this.sendSpaceKey = function() {
|
||||
|
@ -969,33 +982,55 @@ var ChromeObject = function() {
|
|||
this.setValue = function(selector, value, repeat, searchIndex) {
|
||||
var s = encodeURIComponent(value),
|
||||
i = 0,
|
||||
searchIndex = (typeof searchIndex !== "undefined" ? searchIndex : 0)
|
||||
searchIndex = (typeof searchIndex !== "undefined" ? searchIndex : 0),
|
||||
repeat = (typeof repeat !== "undefined" ? repeat : 1)
|
||||
;
|
||||
|
||||
|
||||
while (i < repeat) {
|
||||
if (searchIndex > 0) {
|
||||
this.evaluate('Object.values(document.querySelectorAll("' + selector + '"))[' + searchIndex + '].value = decodeURIComponent("' + s + '");');
|
||||
this.evaluate('Object.values(__getDocument().querySelectorAll("' + selector + '"))[' + searchIndex + '].value = decodeURIComponent("' + s + '");');
|
||||
} else {
|
||||
this.evaluate('document.querySelector("' + selector + '").value = decodeURIComponent("' + s + '")');
|
||||
this.evaluate('__getDocument().querySelector("' + selector + '").value = decodeURIComponent("' + s + '")');
|
||||
}
|
||||
i++;
|
||||
}
|
||||
};
|
||||
|
||||
this.getText = function(selector) {
|
||||
return this.getEvaluatedValue('document.querySelector("' + selector + '").innerText');
|
||||
return this.getEvaluatedValue('__getDocument().querySelector("' + selector + '").innerText');
|
||||
};
|
||||
|
||||
this.setHTML = function(selector, value, repeat, searchIndex) {
|
||||
var s = encodeURIComponent(value),
|
||||
i = 0,
|
||||
searchIndex = (typeof searchIndex !== "undefined" ? searchIndex : 0),
|
||||
repeat = (typeof repeat !== "undefined" ? repeat : 1)
|
||||
;
|
||||
|
||||
while (i < repeat) {
|
||||
if (searchIndex > 0) {
|
||||
this.evaluate('Object.values(__getDocument().querySelectorAll("' + selector + '"))[' + searchIndex + '].value = decodeURIComponent("' + s + '");');
|
||||
} else {
|
||||
this.evaluate('__getDocument().querySelector("' + selector + '").innerHTML = decodeURIComponent("' + s + '")');
|
||||
}
|
||||
i++;
|
||||
}
|
||||
};
|
||||
|
||||
this.getHTML = function(selector) {
|
||||
return this.getEvaluatedValue('__getDocument().querySelector("' + selector + '").innerHTML');
|
||||
};
|
||||
|
||||
this.traceMouseClick = function() {
|
||||
return this.evaluate('window.addEventListener("click",function(e){var t=e.clientX,n=e.clientY,l=document.createElement("div");l.style.position="absolute",l.style.width="20px",l.style.height="20px",l.style.backgroundColor="#00ff00",l.style.zIndex=99999,l.style.top=window.pageYOffset+n-10+"px",l.style.left=window.pageXOffset+t-10+"px",document.body.appendChild(l)});');
|
||||
return this.evaluate('__getWindow().addEventListener("click",function(e){var t=e.clientX,n=e.clientY,l=__getDocument().createElement("div");l.style.position="absolute",l.style.width="20px",l.style.height="20px",l.style.backgroundColor="#00ff00",l.style.zIndex=99999,l.style.top=__getWindow().pageYOffset+n-10+"px",l.style.left=__getWindow().pageXOffset+t-10+"px",__getDocument().body.appendChild(l)});');
|
||||
};
|
||||
|
||||
this.getWindowInnerHeight = function() {
|
||||
return parseInt(this.getEvaluatedValue('window.innerHeight'));
|
||||
return parseInt(this.getEvaluatedValue('__getWindow().innerHeight'));
|
||||
};
|
||||
|
||||
this.getDocumentScrollTop = function() {
|
||||
return parseInt(this.getEvaluatedValue('document.documentElement.scrollTop'));
|
||||
return parseInt(this.getEvaluatedValue('__getDocument().documentElement.scrollTop'));
|
||||
};
|
||||
|
||||
// formula: y > 0 and y + h < ih
|
||||
|
|
Loading…
Reference in New Issue
Block a user