Skip to content

Commit

Permalink
feat: remove unused exceptions (#613)
Browse files Browse the repository at this point in the history
* feat: remove unused exceptions

* chore: format
  • Loading branch information
adeprez authored Oct 3, 2024
1 parent 5b194b9 commit f89fe3a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
PossibleInteractionsByXpath,
InteractionType,
)
from lavague.sdk.exceptions import (
NoElementException,
AmbiguousException,
)
import time


Expand Down Expand Up @@ -207,14 +203,6 @@ def exec_code(
)
elif action_name == "wait":
self.perform_wait(item["action"]["args"]["duration"])
elif action_name == "failNoElement":
raise NoElementException(
"No element: " + item["action"]["args"]["value"]
)
elif action_name == "failAmbiguous":
raise AmbiguousException(
"Ambiguous: " + item["action"]["args"]["value"]
)

self.wait_for_idle()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
InteractionType,
DOMNode,
)
from lavague.sdk.exceptions import (
CannotBackException,
NoElementException,
AmbiguousException,
)
from lavague.sdk.exceptions import CannotBackException
from PIL import Image
from io import BytesIO
from selenium.webdriver.chrome.options import Options
Expand Down Expand Up @@ -298,10 +294,6 @@ def exec_code(
xpath,
ScrollDirection.from_string(args.get("value", "DOWN")),
)
case "failNoElement":
raise NoElementException("No element: " + args["value"])
case "failAmbiguous":
raise AmbiguousException("Ambiguous: " + args["value"])
case _:
raise ValueError(f"Unknown action: {action_name}")

Expand Down
5 changes: 2 additions & 3 deletions lavague-sdk/lavague/sdk/base_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class InteractionType(Enum):

r_get_xpaths_from_html = r'xpath=["\'](.*?)["\']'


class ScrollDirection(Enum):
"""Enum for the different scroll directions. Value is (x, y, dimension_index)"""

Expand Down Expand Up @@ -277,7 +278,7 @@ def scroll(
scroll_factor=0.75,
):
pass

# TODO: Remove these methods as they are not used
@abstractmethod
def scroll_up(self):
Expand Down Expand Up @@ -489,8 +490,6 @@ def __exit__(self, exc_type, exc_val, exc_tb):
pass




def js_wrap_function_call(fn: str):
return "(function(){" + fn + "})()"

Expand Down
35 changes: 2 additions & 33 deletions lavague-sdk/lavague/sdk/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,7 @@
from typing import Optional


class NavigationException(Exception):
pass


class ExtractorException(Exception):
class DriverException(Exception):
pass


class CannotBackException(NavigationException):
class CannotBackException(DriverException):
def __init__(self, message="History root reached, cannot go back"):
super().__init__(message)


class RetrievalException(NavigationException):
pass


class NoElementException(RetrievalException):
def __init__(self, message="No element found"):
super().__init__(message)


class AmbiguousException(RetrievalException):
def __init__(self, message="Multiple elements could match"):
super().__init__(message)


class HallucinatedException(RetrievalException):
def __init__(self, xpath: str, message: Optional[str] = None):
super().__init__(message or f"Element was hallucinated: {xpath}")


class ElementOutOfContextException(RetrievalException):
def __init__(self, xpath: str, message: Optional[str] = None):
super().__init__(message or f"Element exists but was not in context: {xpath}")

0 comments on commit f89fe3a

Please sign in to comment.