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 dropdown bug in select2 #144

Merged
merged 1 commit into from
Apr 4, 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
41 changes: 40 additions & 1 deletion skyvern/webeye/scraper/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,44 @@ function buildTreeFromBody() {
var elements = [];
var resultArray = [];

const checkSelect2 = () => {
// according to select2(https://select2.org/getting-started/basic-usage)
// select2-container seems to be the most common class in select2,
// and the invisible select seems to be the sibling to the "select2-container" element.
const selectContainers = document.querySelectorAll(".select2-container");

selectContainers.forEach((element) => {
// hide the select2 container
element.style.display = "none";

// search select in previous
let _pre = element.previousElementSibling;
while (_pre) {
if (
_pre.tagName.toLowerCase() === "select" &&
_pre.style.display === "none"
) {
_pre.style.removeProperty("display");
return;
}
_pre = _pre.previousElementSibling;
}

// search select in next
let _next = element.nextElementSibling;
while (_next) {
if (
_next.tagName.toLowerCase() === "select" &&
_next.style.display === "none"
) {
_next.style.removeProperty("display");
return;
}
_next = _next.nextElementSibling;
}
});
};

function buildElementObject(element) {
var element_id = elements.length;
var elementTagNameLower = element.tagName.toLowerCase();
Expand Down Expand Up @@ -593,7 +631,8 @@ function buildTreeFromBody() {
}

// TODO: Handle iframes

// setup before parsing the dom
checkSelect2();
// Clear all the unique_id attributes so that there are no conflicts
removeAllUniqueIdAttributes();
processElement(document.body, null);
Expand Down
Loading