Skip to content

Commit ba6ef89

Browse files
authored
custom select optimize (#985)
1 parent e45c9e1 commit ba6ef89

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

skyvern/webeye/actions/handler.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,18 @@ async def handle_input_text_action(
451451

452452
# press arrowdown to watch if there's any options popping up
453453
await incremental_scraped.start_listen_dom_increment()
454-
await skyvern_element.press_key("ArrowDown")
454+
try:
455+
await skyvern_element.press_key("ArrowDown")
456+
except TimeoutError:
457+
# sometimes we notice `press_key()` raise a timeout but actually the dropdown is opened.
458+
LOG.info(
459+
"Timeout to press ArrowDown to open dropdown, ignore the timeout and continue to execute the action",
460+
task_id=task.task_id,
461+
step_id=step.step_id,
462+
element_id=skyvern_element.get_id(),
463+
action=action,
464+
)
465+
455466
await asyncio.sleep(5)
456467

457468
incremental_element = await incremental_scraped.get_incremental_element_tree(
@@ -677,6 +688,13 @@ async def handle_select_option_action(
677688
element_dict=element_dict,
678689
)
679690

691+
# Handle the edge case:
692+
# Sometimes our custom select logic could fail, and leaving the dropdown being opened.
693+
# Confirm if the select action is on the custom option element
694+
if await skyvern_element.is_custom_option():
695+
click_action = ClickAction(element_id=action.element_id)
696+
return await chain_click(task, scraped_page, page, click_action, skyvern_element)
697+
680698
if not await skyvern_element.is_selectable():
681699
# 1. find from children
682700
# TODO: 2. find from siblings and their chidren

skyvern/webeye/utils/dom.py

+3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ async def is_auto_completion_input(self) -> bool:
148148

149149
return False
150150

151+
async def is_custom_option(self) -> bool:
152+
return self.get_tag_name() == "li" or await self.get_attr("role") == "option"
153+
151154
async def is_checkbox(self) -> bool:
152155
tag_name = self.get_tag_name()
153156
if tag_name != "input":

0 commit comments

Comments
 (0)