refresh options before doing select (#2537)

This commit is contained in:
Shuchang Zheng
2025-05-29 20:41:36 -07:00
committed by GitHub
parent 47709dc0d8
commit f0b0a22d25
3 changed files with 17 additions and 0 deletions

View File

@@ -3193,6 +3193,7 @@ async def normal_select(
step_id=step.step_id,
)
await skyvern_element.refresh_select_options()
options_html = skyvern_element.build_HTML()
field_information = (
input_or_select_context.field if not input_or_select_context.intention else input_or_select_context.intention

View File

@@ -795,6 +795,18 @@ class SkyvernElement:
LOG.warning("Failed to navigate to the <a> href link", exc_info=True, href=href, current_url=page.url)
raise
async def refresh_select_options(self) -> tuple[list, str] | None:
if self.get_tag_name() != InteractiveElement.SELECT:
return None
frame = await SkyvernFrame.create_instance(self.get_frame())
options, selected_value = await frame.get_select_options(await self.get_element_handler())
self.__static_element["options"] = options
if "attributes" in self.__static_element:
self.__static_element["attributes"]["selected"] = selected_value
self._attributes = self.__static_element["attributes"]
return options, selected_value
class DomUtil:
"""

View File

@@ -291,3 +291,7 @@ class SkyvernFrame:
async def remove_target_attr(self, element: ElementHandle) -> None:
js_script = "(element) => element.removeAttribute('target')"
return await self.evaluate(frame=self.frame, expression=js_script, arg=element)
async def get_select_options(self, element: ElementHandle) -> tuple[list, str]:
js_script = "([element]) => getSelectOptions(element)"
return await self.evaluate(frame=self.frame, expression=js_script, arg=[element])