Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
close select2 when failed to select (#498)
LawyZheng49d7e77b3a17
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.pyindex ba782503a..4d3bcd59e 100644--- a/skyvern/webeye/actions/handler.py+++ b/skyvern/webeye/actions/handler.py@@ -522,31 +522,37 @@ async def handle_select_option_action(if action.option.index is not None:if action.option.index >= len(options):result.append(ActionFailure(Exception("Select index out of bound")))- return result+ else:+ try:+ option_content = options[action.option.index].get("text")+ if option_content != action.option.label:+ LOG.warning(+ "Select option label is not consistant to the action value. Might select wrong option.",+ option_content=option_content,+ action=action,+ )- try:- option_content = options[action.option.index].get("text")- if option_content != action.option.label:- LOG.warning(- "Select option label is not consistant to the action value. Might select wrong option.",- option_content=option_content,+ await select2_element.select_by_index(index=action.option.index, timeout=timeout)+ result.append(ActionSuccess())+ return result+ except Exception as e:+ result.append(ActionFailure(e))+ LOG.info(+ "failed to select by index in select2, try to select by label",+ exc_info=True,action=action,)- await select2_element.select_by_index(index=action.option.index, timeout=timeout)- result.append(ActionSuccess())- return result- except Exception as e:- result.append(ActionFailure(e))- LOG.info(- "failed to select by index in select2, try to select by label",- exc_info=True,- action=action,- )-if len(result) == 0:result.append(ActionFailure(Exception("nothing is selected, try to select again.")))+ if isinstance(result[-1], ActionFailure):+ LOG.info(+ "Failed to select a select2 option, close the dropdown",+ action=action,+ )+ await select2_element.close()+return resultelif tag_name == "ul" or tag_name == "div" or tag_name == "li":# if the role is listbox, find the option with the "label" or "value" and click that option elementdiff --git a/skyvern/webeye/utils/dom.py b/skyvern/webeye/utils/dom.pyindex 834399fb3..0deec3a90 100644--- a/skyvern/webeye/utils/dom.py+++ b/skyvern/webeye/utils/dom.py@@ -167,6 +167,9 @@ class Select2Dropdown:# wait for the options to loadawait asyncio.sleep(3)+ async def close(self, timeout: float = SettingsManager.get_settings().BROWSER_ACTION_TIMEOUT_MS) -> None:+ await self.page.locator("#select2-drop").press("Escape", timeout=timeout)+async def get_options(self) -> typing.List[SkyvernOptionType]:options = await get_select2_options(self.page)return typing.cast(typing.List[SkyvernOptionType], options)