Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove unused exceptions #613

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -24,11 +24,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 @@ -297,10 +293,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}")
Loading