Skip to content

Commit

Permalink
support dropdown on combobox (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawyZheng committed Apr 18, 2024
1 parent 0b7378f commit 8dacbeb
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions skyvern/webeye/scraper/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,23 @@ function isInteractable(element) {
return false;
}

const isComboboxDropdown = (element) => {
if (element.tagName.toLowerCase() !== "input") {
return false;
}
const role = element.getAttribute("role")
? element.getAttribute("role").toLowerCase()
: "";
const haspopup = element.getAttribute("aria-haspopup")
? element.getAttribute("aria-haspopup").toLowerCase()
: "";
const readonly =
element.getAttribute("readonly") &&
element.getAttribute("readonly").toLowerCase() !== "false";
const controls = element.hasAttribute("aria-controls");
return role && haspopup && controls && readonly;
};

function removeMultipleSpaces(str) {
if (!str) {
return str;
Expand Down Expand Up @@ -601,6 +618,23 @@ function buildTreeFromBody() {
} else if (attrs["role"] && attrs["role"].toLowerCase() === "listbox") {
// if "role" key is inside attrs, then get all the elements with role "option" and get their text
selectOptions = getListboxOptions(element);
} else if (isComboboxDropdown(element)) {
// open combobox dropdown to get options
element.click();
const listBox = document.getElementById(
element.getAttribute("aria-controls"),
);
if (listBox) {
selectOptions = getListboxOptions(listBox);
}
// HACK: press Tab to close the dropdown
element.dispatchEvent(
new KeyboardEvent("keydown", {
keyCode: 9,
bubbles: true,
key: "Tab",
}),
);
}
if (selectOptions) {
elementObj.options = selectOptions;
Expand Down

0 comments on commit 8dacbeb

Please sign in to comment.