Fix cached click actions succeeding when element doesn't exist (#SKY-7577) (#4485)
This commit is contained in:
@@ -182,20 +182,26 @@ class RealSkyvernPageAi(SkyvernPageAi):
|
|||||||
organization_id=context.organization_id,
|
organization_id=context.organization_id,
|
||||||
)
|
)
|
||||||
actions_json = json_response.get("actions", [])
|
actions_json = json_response.get("actions", [])
|
||||||
if actions_json:
|
if not actions_json:
|
||||||
task_id = context.task_id if context else None
|
# LLM returned no actions - the element likely doesn't exist on the page.
|
||||||
task = await app.DATABASE.get_task(task_id, organization_id) if task_id and organization_id else None
|
# Raise an exception so the caller knows the action failed.
|
||||||
if organization_id and task and step:
|
raise Exception(
|
||||||
actions = parse_actions(
|
f"AI could not find an element to click for intention: {intention}. "
|
||||||
task, step.step_id, step.order, self.scraped_page, json_response.get("actions", [])
|
"The element may not exist on the current page."
|
||||||
)
|
)
|
||||||
action = cast(ClickAction, actions[0])
|
task_id = context.task_id if context else None
|
||||||
result = await handle_click_action(action, self.page, self.scraped_page, task, step)
|
task = await app.DATABASE.get_task(task_id, organization_id) if task_id and organization_id else None
|
||||||
if result and result[-1].success is False:
|
if organization_id and task and step:
|
||||||
raise Exception(result[-1].exception_message)
|
actions = parse_actions(
|
||||||
xpath = action.get_xpath()
|
task, step.step_id, step.order, self.scraped_page, json_response.get("actions", [])
|
||||||
selector = f"xpath={xpath}" if xpath else selector
|
)
|
||||||
return selector
|
action = cast(ClickAction, actions[0])
|
||||||
|
result = await handle_click_action(action, self.page, self.scraped_page, task, step)
|
||||||
|
if result and result[-1].success is False:
|
||||||
|
raise Exception(result[-1].exception_message)
|
||||||
|
xpath = action.get_xpath()
|
||||||
|
selector = f"xpath={xpath}" if xpath else selector
|
||||||
|
return selector
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception(
|
LOG.exception(
|
||||||
f"Failed to do ai click. Falling back to original selector={selector}, intention={intention}, data={data}"
|
f"Failed to do ai click. Falling back to original selector={selector}, intention={intention}, data={data}"
|
||||||
@@ -204,7 +210,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
|
|||||||
if selector:
|
if selector:
|
||||||
locator = self.page.locator(selector)
|
locator = self.page.locator(selector)
|
||||||
await locator.click(timeout=timeout)
|
await locator.click(timeout=timeout)
|
||||||
return selector
|
return selector
|
||||||
|
|
||||||
|
# If we reach here with no selector, the AI failed and there's no fallback - raise an error
|
||||||
|
raise Exception(f"AI click failed and no fallback selector available for intention: {intention}")
|
||||||
|
|
||||||
async def ai_input_text(
|
async def ai_input_text(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user