mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 13:16:05 +00:00
Update chrome.js
This commit is contained in:
parent
c9c5c83c8c
commit
3ae03c70a5
|
@ -346,19 +346,19 @@ var ChromeObject = function() {
|
||||||
return JSON.parse(responseText).result.result.value;
|
return JSON.parse(responseText).result.result.value;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("ChromeObject.getEvaluatedValue() ->", e.message);
|
console.error("ChromeObject.getEvaluatedValue() ->", e.message);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.exit = function() {
|
this.exit = function() {
|
||||||
return this.sendPageRPC("Browser.close", {});
|
return this.sendPageRPC("Browser.close", {});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.close = function() {
|
this.close = function() {
|
||||||
var response = this.sendPageRPC("Page.close", {});
|
var response = this.sendPageRPC("Page.close", {});
|
||||||
this.setPageId(null);
|
this.setPageId(null);
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.terminate = function() {
|
this.terminate = function() {
|
||||||
try {
|
try {
|
||||||
|
@ -526,40 +526,40 @@ var ChromeObject = function() {
|
||||||
"g": -1,
|
"g": -1,
|
||||||
"d": -1
|
"d": -1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getNestedElementPosition = function(selector, subSelector, searchText) {
|
this.getNestedElementPosition = function(selector, subSelector, searchText) {
|
||||||
var s = '';
|
var s = '';
|
||||||
|
|
||||||
if (searchText.indexOf(':p(') != 0) {
|
if (searchText.indexOf(':p(') != 0) {
|
||||||
s += '(function() {'
|
s += '(function() {'
|
||||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||||
+ ' return (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
|
+ ' return (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
|
||||||
+ ' });'
|
+ ' });'
|
||||||
+ ' if (elements.length > 0) {'
|
+ ' if (elements.length > 0) {'
|
||||||
+ ' var rect = elements[0].getBoundingClientRect();'
|
+ ' var rect = elements[0].getBoundingClientRect();'
|
||||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(rect.x), parseInt(rect.y), parseInt(rect.right), parseInt(rect.bottom)].join(",");'
|
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(rect.x), parseInt(rect.y), parseInt(rect.right), parseInt(rect.bottom)].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
+ '})()'
|
+ '})()'
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.indexOf(')')));
|
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.indexOf(')')));
|
||||||
s += '(function() {'
|
s += '(function() {'
|
||||||
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
|
||||||
+ ' return (Math.random() < ' + p + ');'
|
+ ' return (Math.random() < ' + p + ');'
|
||||||
+ ' });'
|
+ ' });'
|
||||||
+ ' if (elements.length > 0) {'
|
+ ' if (elements.length > 0) {'
|
||||||
+ ' var rect = elements[0].getBoundingClientRect();'
|
+ ' var rect = elements[0].getBoundingClientRect();'
|
||||||
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(rect.x), parseInt(rect.y), parseInt(rect.right), parseInt(rect.bottom)].join(",");'
|
+ ' return [parseInt(rect.left), parseInt(rect.top), parseInt(rect.x), parseInt(rect.y), parseInt(rect.right), parseInt(rect.bottom)].join(",");'
|
||||||
+ ' } else {'
|
+ ' } else {'
|
||||||
+ ' return "";'
|
+ ' return "";'
|
||||||
+ ' }'
|
+ ' }'
|
||||||
+ '})()'
|
+ '})()'
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = this.getEvaluatedValue(s);
|
var result = this.getEvaluatedValue(s);
|
||||||
var pos = result.split(',');
|
var pos = result.split(',');
|
||||||
|
@ -581,7 +581,7 @@ var ChromeObject = function() {
|
||||||
"g": -1,
|
"g": -1,
|
||||||
"d": -1
|
"d": -1
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getPageHeight = function() {
|
this.getPageHeight = function() {
|
||||||
|
@ -647,7 +647,7 @@ var ChromeObject = function() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
|
var p = parseFloat(selector.substring(selector.indexOf('(') + 1, selector.indexOf(')')));
|
||||||
var _selector = selector.substring(0, selector.indexOf(':'));
|
var _selector = selector.substring(0, selector.indexOf(':'));
|
||||||
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(); })(document.querySelectorAll("' + _selector + '"), ' + p + ')');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user