Update chrome.js

This commit is contained in:
Namhyeon Go 2021-08-11 15:56:24 +09:00 committed by GitHub
parent c9c5c83c8c
commit 3ae03c70a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -346,19 +346,19 @@ var ChromeObject = function() {
return JSON.parse(responseText).result.result.value;
} catch (e) {
console.error("ChromeObject.getEvaluatedValue() ->", e.message);
return "";
return "";
}
};
this.exit = function() {
return this.sendPageRPC("Browser.close", {});
};
this.close = function() {
var response = this.sendPageRPC("Page.close", {});
this.setPageId(null);
return response;
};
this.close = function() {
var response = this.sendPageRPC("Page.close", {});
this.setPageId(null);
return response;
};
this.terminate = function() {
try {
@ -526,40 +526,40 @@ var ChromeObject = function() {
"g": -1,
"d": -1
};
}
}
};
this.getNestedElementPosition = function(selector, subSelector, searchText) {
var s = '';
if (searchText.indexOf(':p(') != 0) {
s += '(function() {'
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
+ ' return (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
+ ' });'
+ ' if (elements.length > 0) {'
+ ' 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(",");'
+ ' } else {'
+ ' return "";'
+ ' }'
+ '})()'
;
} else {
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.indexOf(')')));
s += '(function() {'
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
+ ' return (Math.random() < ' + p + ');'
+ ' });'
+ ' if (elements.length > 0) {'
+ ' 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(",");'
+ ' } else {'
+ ' return "";'
+ ' }'
+ '})()'
;
}
if (searchText.indexOf(':p(') != 0) {
s += '(function() {'
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
+ ' return (x.querySelector("' + subSelector + '").innerText.indexOf(decodeURIComponent("' + encodeURIComponent(searchText) + '")) > -1);'
+ ' });'
+ ' if (elements.length > 0) {'
+ ' 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(",");'
+ ' } else {'
+ ' return "";'
+ ' }'
+ '})()'
;
} else {
var p = parseFloat(searchText.substring(searchText.indexOf('(') + 1, searchText.indexOf(')')));
s += '(function() {'
+ ' var elements = Object.values(document.querySelectorAll("' + selector + '")).filter(function(x) {'
+ ' return (Math.random() < ' + p + ');'
+ ' });'
+ ' if (elements.length > 0) {'
+ ' 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(",");'
+ ' } else {'
+ ' return "";'
+ ' }'
+ '})()'
;
}
var result = this.getEvaluatedValue(s);
var pos = result.split(',');
@ -581,7 +581,7 @@ var ChromeObject = function() {
"g": -1,
"d": -1
};
}
}
};
this.getPageHeight = function() {
@ -647,7 +647,7 @@ var ChromeObject = function() {
}
} else {
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 + ')');
}
};