From abab126dec34012339f5326891cef605066a6cab Mon Sep 17 00:00:00 2001 From: dhuynh95 Date: Tue, 24 Sep 2024 16:24:52 +0200 Subject: [PATCH] Added minor change --- lavague-core/lavague/exporter/base.py | 2 ++ lavague-core/lavague/exporter/python.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lavague-core/lavague/exporter/base.py b/lavague-core/lavague/exporter/base.py index 569a398b..ea9efaf5 100644 --- a/lavague-core/lavague/exporter/base.py +++ b/lavague-core/lavague/exporter/base.py @@ -22,6 +22,7 @@ def on_missing_action(self, action: Action) -> None: def translate_action(self, action: Action) -> Optional[str]: """Translate a single action to target framework code""" + instruction = action.instruction match action.action_type: case ActionType.NAVIGATION: @@ -47,6 +48,7 @@ def translate_action(self, action: Action) -> Optional[str]: case _: self.on_missing_action(action) + output = f"# {instruction}\n{output}\n" return output def translate_click(self, action_output: NavigationOutput) -> Optional[str]: diff --git a/lavague-core/lavague/exporter/python.py b/lavague-core/lavague/exporter/python.py index f1cd9d49..5be98640 100644 --- a/lavague-core/lavague/exporter/python.py +++ b/lavague-core/lavague/exporter/python.py @@ -1,7 +1,5 @@ -from contextlib import contextmanager import inspect import re -from functools import wraps from typing import Callable, Optional, List from lavague.exporter.base import TrajectoryExporter from lavague.action.base import ActionType @@ -36,7 +34,7 @@ class PythonExporter(TrajectoryExporter): """ @classmethod - def translate(cls, method: Callable, output: NavigationOutput, string_only: bool = True) -> Optional[str]: + def translate(cls, method: Callable, output: NavigationOutput | ExtractionOutput, string_only: bool = True) -> Optional[str]: """Takes the code of method, replace each use of the 'action' parameter with the actual action attributes. Replacement is done only on attributes of the action used in the method. """ @@ -169,6 +167,10 @@ def hover(self, action: NavigationOutput) -> Optional[str]: driver = self.get_driver() driver.find_element(By.XPATH, action.xpath).hover() + def set_value(self, action: NavigationOutput) -> Optional[str]: + driver = self.get_driver() + driver.find_element(By.XPATH, action.xpath).send_keys(action.value) + def extract(self, action: ExtractionOutput) -> Optional[str]: driver = self.get_driver()