store xpath as root level attribute of action (#3654)
This commit is contained in:
@@ -346,6 +346,9 @@ class SkyvernPage:
|
|||||||
# Create action record. TODO: store more action fields
|
# Create action record. TODO: store more action fields
|
||||||
kwargs = kwargs or {}
|
kwargs = kwargs or {}
|
||||||
# we're using "value" instead of "text" for input text actions interface
|
# we're using "value" instead of "text" for input text actions interface
|
||||||
|
xpath = kwargs.get("xpath")
|
||||||
|
if action_type == ActionType.CLICK:
|
||||||
|
xpath = call_result or xpath
|
||||||
text = None
|
text = None
|
||||||
select_option = None
|
select_option = None
|
||||||
response: str | None = kwargs.get("response")
|
response: str | None = kwargs.get("response")
|
||||||
@@ -376,6 +379,7 @@ class SkyvernPage:
|
|||||||
option=select_option,
|
option=select_option,
|
||||||
file_url=file_url,
|
file_url=file_url,
|
||||||
response=response,
|
response=response,
|
||||||
|
xpath=xpath,
|
||||||
created_by="script",
|
created_by="script",
|
||||||
)
|
)
|
||||||
data_extraction_goal = None
|
data_extraction_goal = None
|
||||||
@@ -461,7 +465,7 @@ class SkyvernPage:
|
|||||||
|
|
||||||
######### Public Interfaces #########
|
######### Public Interfaces #########
|
||||||
@action_wrap(ActionType.CLICK)
|
@action_wrap(ActionType.CLICK)
|
||||||
async def click(self, xpath: str, intention: str | None = None, data: str | dict[str, Any] | None = None) -> None:
|
async def click(self, xpath: str, intention: str | None = None, data: str | dict[str, Any] | None = None) -> str:
|
||||||
"""Click an element identified by ``xpath``.
|
"""Click an element identified by ``xpath``.
|
||||||
|
|
||||||
When ``intention`` and ``data`` are provided a new click action is
|
When ``intention`` and ``data`` are provided a new click action is
|
||||||
@@ -504,6 +508,7 @@ class SkyvernPage:
|
|||||||
|
|
||||||
locator = self.page.locator(f"xpath={new_xpath}")
|
locator = self.page.locator(f"xpath={new_xpath}")
|
||||||
await locator.click(timeout=5000)
|
await locator.click(timeout=5000)
|
||||||
|
return new_xpath
|
||||||
|
|
||||||
@action_wrap(ActionType.INPUT_TEXT)
|
@action_wrap(ActionType.INPUT_TEXT)
|
||||||
async def fill(
|
async def fill(
|
||||||
@@ -755,9 +760,7 @@ class SkyvernPage:
|
|||||||
return
|
return
|
||||||
|
|
||||||
@action_wrap(ActionType.SOLVE_CAPTCHA)
|
@action_wrap(ActionType.SOLVE_CAPTCHA)
|
||||||
async def solve_captcha(
|
async def solve_captcha(self, intention: str | None = None, data: str | dict[str, Any] | None = None) -> None:
|
||||||
self, xpath: str, intention: str | None = None, data: str | dict[str, Any] | None = None
|
|
||||||
) -> None:
|
|
||||||
context = skyvern_context.current()
|
context = skyvern_context.current()
|
||||||
if not context or not context.organization_id or not context.task_id or not context.step_id:
|
if not context or not context.organization_id or not context.task_id or not context.step_id:
|
||||||
await asyncio.sleep(30)
|
await asyncio.sleep(30)
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class Action(BaseModel):
|
|||||||
skyvern_element_hash: str | None = None
|
skyvern_element_hash: str | None = None
|
||||||
skyvern_element_data: dict[str, Any] | None = None
|
skyvern_element_data: dict[str, Any] | None = None
|
||||||
tool_call_id: str | None = None
|
tool_call_id: str | None = None
|
||||||
|
xpath: str | None = None
|
||||||
|
|
||||||
# DecisiveAction (CompleteAction, TerminateAction) fields
|
# DecisiveAction (CompleteAction, TerminateAction) fields
|
||||||
errors: list[UserDefinedError] | None = None
|
errors: list[UserDefinedError] | None = None
|
||||||
@@ -130,6 +131,8 @@ class Action(BaseModel):
|
|||||||
raise ValueError("Invalid action data")
|
raise ValueError("Invalid action data")
|
||||||
|
|
||||||
def get_xpath(self) -> str | None:
|
def get_xpath(self) -> str | None:
|
||||||
|
if self.xpath:
|
||||||
|
return self.xpath
|
||||||
if not self.skyvern_element_data:
|
if not self.skyvern_element_data:
|
||||||
return None
|
return None
|
||||||
if "xpath" in self.skyvern_element_data:
|
if "xpath" in self.skyvern_element_data:
|
||||||
|
|||||||
Reference in New Issue
Block a user