Fix select action bug (#202)

This commit is contained in:
LawyZheng 2024-04-17 21:51:16 +08:00 committed by GitHub
parent 551af04888
commit c162ad3d0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 11 deletions

View file

@ -320,9 +320,16 @@ async def handle_select_option_action(
) )
return [ActionFailure(Exception(f"Cannot handle SelectOptionAction on a non-listbox element"))] 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() current_text = await locator.input_value()
if current_text == action.option.label: if current_text == action.option.label:
return ActionSuccess() return [ActionSuccess()]
try: try:
# First click by label (if it matches) # First click by label (if it matches)
await page.click(f"xpath={xpath}", timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) await page.click(f"xpath={xpath}", timeout=SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS)

View file

@ -502,6 +502,27 @@ function buildTreeFromBody() {
var resultArray = []; var resultArray = [];
const checkSelect2 = () => { 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) // according to select2(https://select2.org/getting-started/basic-usage)
// select2-container seems to be the most common class in select2, // 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. // and the invisible select seems to be the sibling to the "select2-container" element.
@ -511,11 +532,7 @@ function buildTreeFromBody() {
// search select in previous // search select in previous
let _pre = element.previousElementSibling; let _pre = element.previousElementSibling;
while (_pre) { while (_pre) {
if ( if (_pre.tagName.toLowerCase() === "select" && showInvisible(_pre)) {
_pre.tagName.toLowerCase() === "select" &&
_pre.style.display === "none"
) {
_pre.style.removeProperty("display");
// only hide the select2 container when an alternative select found // only hide the select2 container when an alternative select found
element.style.display = "none"; element.style.display = "none";
return; return;
@ -526,11 +543,7 @@ function buildTreeFromBody() {
// search select in next // search select in next
let _next = element.nextElementSibling; let _next = element.nextElementSibling;
while (_next) { while (_next) {
if ( if (_next.tagName.toLowerCase() === "select" && showInvisible(_next)) {
_next.tagName.toLowerCase() === "select" &&
_next.style.display === "none"
) {
_next.style.removeProperty("display");
// only hide the select2 container when an alternative select found // only hide the select2 container when an alternative select found
element.style.display = "none"; element.style.display = "none";
return; return;