mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 21:26:04 +00:00
Update chrome.js
This commit is contained in:
parent
c9c5c83c8c
commit
3ae03c70a5
|
@ -346,7 +346,7 @@ var ChromeObject = function() {
|
|||
return JSON.parse(responseText).result.result.value;
|
||||
} catch (e) {
|
||||
console.error("ChromeObject.getEvaluatedValue() ->", e.message);
|
||||
return "";
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -354,11 +354,11 @@ var ChromeObject = 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 + ')');
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user