Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: viewport interactive elements retrieval #601

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lavague-core/lavague/core/base_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def js_wrap_function_call(fn: str):
const windowHeight = (window.innerHeight || document.documentElement.clientHeight);
const windowWidth = (window.innerWidth || document.documentElement.clientWidth);

return (function() {
function getInteractions(e, in_viewport, foreground_only) {
return (function(inViewport, foregroundOnly) {
function getInteractions(e) {
const tag = e.tagName.toLowerCase();
if (!e.checkVisibility() || e.hasAttribute('disabled') || e.hasAttribute('readonly')
|| (tag === 'input' && e.getAttribute('type') === 'hidden') || tag === 'body') {
Expand Down Expand Up @@ -524,7 +524,7 @@ def js_wrap_function_call(fn: str):
//evts.push('SCROLL');
}

if (in_viewport == true) {
if (inViewport) {
const rect = e.getBoundingClientRect();
let iframe = e.ownerDocument.defaultView.frameElement;
while (iframe) {
Expand All @@ -543,10 +543,10 @@ def js_wrap_function_call(fn: str):
if (elemCenter.x > windowWidth) return [];
if (elemCenter.y < 0) return [];
if (elemCenter.y > windowHeight) return [];
if (foreground_only !== true) return evts; // whenever to check for elements above
if (!foregroundOnly) return evts; // whenever to check for elements above
let pointContainer = document.elementFromPoint(elemCenter.x, elemCenter.y);
do {
if (pointContainer === element) return evts;
if (pointContainer === e) return evts;
if (pointContainer == null) return evts;
} while (pointContainer = pointContainer.parentNode);
return [];
Expand All @@ -558,7 +558,7 @@ def js_wrap_function_call(fn: str):
const results = {};
function traverse(node, xpath) {
if (node.nodeType === Node.ELEMENT_NODE) {
const interactions = getInteractions(node, arguments?.[0], arguments?.[1]);
const interactions = getInteractions(node);
if (interactions.length > 0) {
results[xpath] = interactions;
}
Expand Down Expand Up @@ -589,7 +589,7 @@ def js_wrap_function_call(fn: str):
}
traverse(document.body, '/html/body');
return results;
})();
})(arguments?.[0], arguments?.[1]);
"""

JS_WAIT_DOM_IDLE = """
Expand Down
Loading