Skip to content

Commit

Permalink
chore: ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
JoFrost committed Aug 28, 2024
1 parent 23e1ef0 commit a5a6725
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lavague-core/lavague/core/retrievers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
REMOVE_HIGHLIGHT,
)


class XPathResolved(ABC):
def __init__(self, xpath: str, driver: any, element: WebElement) -> None:
self.xpath = xpath
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -657,14 +665,15 @@ 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()
for k, v in exe.items():
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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a5a6725

Please sign in to comment.