custom select optimize (#985)

This commit is contained in:
LawyZheng
2024-10-16 19:23:12 +08:00
committed by GitHub
parent e45c9e1288
commit ba6ef89b35
2 changed files with 22 additions and 1 deletions

View File

@@ -451,7 +451,18 @@ async def handle_input_text_action(
# press arrowdown to watch if there's any options popping up
await incremental_scraped.start_listen_dom_increment()
await skyvern_element.press_key("ArrowDown")
try:
await skyvern_element.press_key("ArrowDown")
except TimeoutError:
# sometimes we notice `press_key()` raise a timeout but actually the dropdown is opened.
LOG.info(
"Timeout to press ArrowDown to open dropdown, ignore the timeout and continue to execute the action",
task_id=task.task_id,
step_id=step.step_id,
element_id=skyvern_element.get_id(),
action=action,
)
await asyncio.sleep(5)
incremental_element = await incremental_scraped.get_incremental_element_tree(
@@ -677,6 +688,13 @@ async def handle_select_option_action(
element_dict=element_dict,
)
# Handle the edge case:
# Sometimes our custom select logic could fail, and leaving the dropdown being opened.
# Confirm if the select action is on the custom option element
if await skyvern_element.is_custom_option():
click_action = ClickAction(element_id=action.element_id)
return await chain_click(task, scraped_page, page, click_action, skyvern_element)
if not await skyvern_element.is_selectable():
# 1. find from children
# TODO: 2. find from siblings and their chidren

View File

@@ -148,6 +148,9 @@ class SkyvernElement:
return False
async def is_custom_option(self) -> bool:
return self.get_tag_name() == "li" or await self.get_attr("role") == "option"
async def is_checkbox(self) -> bool:
tag_name = self.get_tag_name()
if tag_name != "input":