fix yes/no radio input (#955)

This commit is contained in:
LawyZheng
2024-10-11 10:48:41 +08:00
committed by GitHub
parent 555836ee41
commit 3a935584d0
2 changed files with 11 additions and 1 deletions

View File

@@ -850,6 +850,16 @@ function buildElementObject(frame, element, interactable, purgeable = false) {
attrs["required"] = true;
}
if (
elementTagNameLower === "input" &&
(element.type === "radio" || element.type === "checkbox")
) {
// if checkbox and radio don't have "checked" and "aria-checked", add a checked="false" to help LLM understand
if (!("checked" in attrs) && !("aria-checked" in attrs)) {
attrs["checked"] = false;
}
}
if (elementTagNameLower === "input" || elementTagNameLower === "textarea") {
attrs["value"] = element.value;
}

View File

@@ -573,7 +573,7 @@ def _trimmed_attributes(attributes: dict) -> dict:
for key in attributes:
if key == "role" and attributes[key] in ["listbox", "option"]:
new_attributes[key] = attributes[key]
if key in RESERVED_ATTRIBUTES and attributes[key]:
if key in RESERVED_ATTRIBUTES:
new_attributes[key] = attributes[key]
return new_attributes