diff --git a/lavague-core/lavague/core/retrievers.py b/lavague-core/lavague/core/retrievers.py index dbe4954e..314c6d32 100644 --- a/lavague-core/lavague/core/retrievers.py +++ b/lavague-core/lavague/core/retrievers.py @@ -182,7 +182,7 @@ def get_html_with_xpath( filter_by_possible_interactions, xpath_prefix + frame_xpath, ) - frame_soup = BeautifulSoup(frame_soup_str, 'html.parser') + frame_soup = BeautifulSoup(frame_soup_str, "html.parser") iframe_tag.replace_with(frame_soup) self.driver.switch_parent_frame() return str(soup) diff --git a/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py b/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py index 5622c322..f288bfb2 100644 --- a/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py +++ b/lavague-integrations/drivers/lavague-drivers-playwright/lavague/drivers/playwright/base.py @@ -312,7 +312,7 @@ def get_possible_interactions( ) -> PossibleInteractionsByXpath: exe: Dict[str, List[str]] = self.execute_script( JS_GET_INTERACTIVES, - in_viewport, + in_viewport, foreground_only, ) res = dict() diff --git a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py index c11af821..0b0e38cd 100644 --- a/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py +++ b/lavague-integrations/drivers/lavague-drivers-selenium/lavague/drivers/selenium/base.py @@ -48,6 +48,7 @@ REMOVE_HIGHLIGHT, ) + class XPathResolved(ABC): def __init__(self, xpath: str, driver: any, element: WebElement) -> None: self.xpath = xpath @@ -61,6 +62,7 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): self._driver.switch_default_frame() + class SeleniumDriver(BaseDriver): driver: WebDriver last_hover_xpath: Optional[str] = None @@ -222,7 +224,9 @@ def check_visibility(self, xpath: str) -> bool: try: # Done manually here to avoid issues element = self.resolve_xpath(xpath).element - res = element is not None and element.is_displayed() and element.is_enabled() + res = ( + element is not None and element.is_displayed() and element.is_enabled() + ) self.switch_default_frame() return res except: @@ -364,13 +368,17 @@ def code_for_execute_script(self, js_code: str, *args) -> str: def hover(self, xpath: str): with self.resolve_xpath(xpath) as element_resolved: self.last_hover_xpath = xpath - ActionChains(self.driver).move_to_element(element_resolved.element).perform() + ActionChains(self.driver).move_to_element( + element_resolved.element + ).perform() def scroll_page(self, direction: ScrollDirection = ScrollDirection.DOWN): self.driver.execute_script(direction.get_page_script()) def get_scroll_anchor(self, xpath_anchor: Optional[str] = None) -> WebElement: - with self.resolve_xpath(xpath_anchor or self.last_hover_xpath) as element_resolved: + with self.resolve_xpath( + xpath_anchor or self.last_hover_xpath + ) as element_resolved: element = element_resolved.element parent = self.driver.execute_script(JS_GET_SCROLLABLE_PARENT, element) scroll_anchor = parent or element @@ -657,7 +665,7 @@ def get_possible_interactions( ) -> PossibleInteractionsByXpath: exe: Dict[str, List[str]] = self.driver.execute_script( JS_GET_INTERACTIVES, - in_viewport, + in_viewport, foreground_only, ) res = dict() @@ -665,6 +673,7 @@ def get_possible_interactions( res[k] = set(InteractionType[i] for i in v) return res + class SeleniumNode(DOMNode): def __init__(self, xpath: str, driver: SeleniumDriver) -> None: self.xpath = xpath @@ -732,6 +741,7 @@ def _create_session(self): ) return response.json()["id"] + SELENIUM_PROMPT_TEMPLATE = """ You are a chrome extension and your goal is to interact with web pages. You have been given a series of HTML snippets and queries. Your goal is to return a list of actions that should be done in order to execute the actions.