Skip if selected (#604)

This commit is contained in:
LawyZheng
2024-07-16 01:41:56 +08:00
committed by GitHub
parent 33ab70dd8b
commit 9b51df4ffd
2 changed files with 21 additions and 12 deletions

View File

@@ -424,7 +424,6 @@ async def handle_select_option_action(
) -> list[ActionResult]:
dom = DomUtil(scraped_page, page)
skyvern_element = await dom.get_skyvern_element_by_id(action.element_id)
locator = skyvern_element.locator
tag_name = skyvern_element.get_tag_name()
element_dict = scraped_page.id_to_element_dict[action.element_id]
@@ -583,13 +582,6 @@ async def handle_select_option_action(
click_action = ClickAction(element_id=action.element_id)
return await chain_click(task, scraped_page, page, click_action, skyvern_element)
try:
current_text = await locator.input_value()
if current_text == action.option.label or current_text == action.option.value:
return [ActionSuccess()]
except Exception:
LOG.info("failed to confirm if the select option has been done, force to take the action again.")
return await normal_select(action=action, skyvern_element=skyvern_element)
@@ -828,9 +820,16 @@ async def normal_select(
action: actions.SelectOptionAction,
skyvern_element: SkyvernElement,
) -> List[ActionResult]:
try:
current_text = await skyvern_element.get_attr("selected")
if current_text == action.option.label or current_text == action.option.value:
return [ActionSuccess()]
except Exception:
LOG.info("failed to confirm if the select option has been done, force to take the action again.")
action_result: List[ActionResult] = []
is_success = False
locator = skyvern_element.locator
locator = skyvern_element.get_locator()
try:
await locator.click(

View File

@@ -605,7 +605,13 @@ function getSelectOptions(element) {
text: removeMultipleSpaces(option.textContent),
});
}
return selectOptions;
const selectedOption = element.querySelector("option:checked");
if (!selectedOption) {
return [selectOptions, ""];
}
return [selectOptions, removeMultipleSpaces(selectedOption.textContent)];
}
function getListboxOptions(element) {
@@ -776,15 +782,16 @@ async function buildTreeFromBody(frame = "main.frame", open_select = false) {
// assign shadowHostId to the shadowHost element if it doesn't have unique_id
if (!shadowHostId) {
shadowHostId = uniqueId();
shadowHost.setAttribute("unique_id", shadowHostId);
shadowHostEle.setAttribute("unique_id", shadowHostId);
}
elementObj.shadowHost = shadowHostId;
}
// get options for select element or for listbox element
let selectOptions = null;
let selectedValue = "";
if (elementTagNameLower === "select") {
selectOptions = getSelectOptions(element);
[selectOptions, selectedValue] = getSelectOptions(element);
} 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);
@@ -840,6 +847,9 @@ async function buildTreeFromBody(frame = "main.frame", open_select = false) {
if (selectOptions) {
elementObj.options = selectOptions;
}
if (selectedValue) {
elementObj.attributes["selected"] = selectedValue;
}
return elementObj;
}