Skip to content

Commit

Permalink
Fix select action bug (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
LawyZheng committed Apr 17, 2024
1 parent 551af04 commit c162ad3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
9 changes: 8 additions & 1 deletion skyvern/webeye/actions/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,16 @@ async def handle_select_option_action(
)
return [ActionFailure(Exception(f"Cannot handle SelectOptionAction on a non-listbox element"))]

# TODO: double click will uncheck the checkbox
if tag_name == "input" and await locator.get_attribute(
"type", timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS
) in ["radio", "checkbox"]:
click_action = ClickAction(element_id=action.element_id)
return await chain_click(task, page, click_action, xpath)

current_text = await locator.input_value()
if current_text == action.option.label:
return ActionSuccess()
return [ActionSuccess()]
try:
# First click by label (if it matches)
await page.click(f"xpath={xpath}", timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)
Expand Down
33 changes: 23 additions & 10 deletions skyvern/webeye/scraper/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,27 @@ function buildTreeFromBody() {
var resultArray = [];

const checkSelect2 = () => {
const showInvisible = (element) => {
if (element.style.display === "none") {
element.style.removeProperty("display");
return true;
}

const removedClass = [];
for (let i = 0; i < element.classList.length; i++) {
const className = element.classList[i];
if (className.includes("hidden")) {
removedClass.push(className);
}
}
if (removedClass.length !== 0) {
removedClass.forEach((className) => {
element.classList.remove(className);
});
return true;
}
return false;
};
// 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.
Expand All @@ -511,11 +532,7 @@ function buildTreeFromBody() {
// search select in previous
let _pre = element.previousElementSibling;
while (_pre) {
if (
_pre.tagName.toLowerCase() === "select" &&
_pre.style.display === "none"
) {
_pre.style.removeProperty("display");
if (_pre.tagName.toLowerCase() === "select" && showInvisible(_pre)) {
// only hide the select2 container when an alternative select found
element.style.display = "none";
return;
Expand All @@ -526,11 +543,7 @@ function buildTreeFromBody() {
// search select in next
let _next = element.nextElementSibling;
while (_next) {
if (
_next.tagName.toLowerCase() === "select" &&
_next.style.display === "none"
) {
_next.style.removeProperty("display");
if (_next.tagName.toLowerCase() === "select" && showInvisible(_next)) {
// only hide the select2 container when an alternative select found
element.style.display = "none";
return;
Expand Down

0 comments on commit c162ad3

Please sign in to comment.