Skip to content
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
11 changes: 4 additions & 7 deletions src/askui/locators/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"""The type of match to use.

- `"similar"` uses a similarity threshold to determine if the text is a match.
- `"exact"` requires the text to be exactly the same (this is not the same as `"similar"`
with a `similarity_threshold` of `100` as a `similarity_threshold` of `100` can still
- `"exact"` requires the text to be exactly the same (this is not the same as `"similar"`
with a `similarity_threshold` of `100` as a `similarity_threshold` of `100` can still
allow for small differences in very long texts).
- `"contains"` requires the text to contain (exactly) the specified text.
- `"regex"` uses a regular expression to match the text.
Expand Down Expand Up @@ -70,7 +70,7 @@ class Element(Locator):
"""Locator for finding ui elements by their class.

Args:
class_name (Literal["text", "textfield"] | None, optional): The class of the ui element, e.g., `'text'` or `'textfield'`. Defaults to `None`.
class_name (Literal["switch","text", "textfield"] | None, optional): The class of the ui element, e.g., `'text'` or `'textfield'`. Defaults to `None`.

Examples:
```python
Expand All @@ -87,10 +87,7 @@ class Element(Locator):
@validate_call
def __init__(
self,
class_name: Annotated[
Literal["text", "textfield"] | None,
Field(),
] = None,
class_name: Literal["switch", "text", "textfield"] | None = None,
) -> None:
super().__init__()
self._class_name = class_name
Expand Down
21 changes: 15 additions & 6 deletions tests/e2e/agent/test_locate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

from askui.agent import VisionAgent
from askui.exceptions import ElementNotFoundError
from askui.locators import (
AiElement,
Element,
Prompt,
Text,
)
from askui.locators import AiElement, Element, Prompt, Text
from askui.locators.locators import Image
from askui.models import ModelName

Expand All @@ -39,6 +34,20 @@ def test_locate_with_string_locator(
assert 450 <= x <= 570
assert 190 <= y <= 260

def test_locate_with_switch_class_locator(
self,
vision_agent: VisionAgent,
path_fixtures: pathlib.Path,
model: str,
) -> None:
"""Test locating elements using a class locator."""
locator = Element("switch")
x, y = vision_agent.locate(
locator, path_fixtures / "images" / "switch.png", model=model
)
assert 340 <= x <= 360
assert 420 <= y <= 460

def test_locate_with_textfield_class_locator(
self,
vision_agent: VisionAgent,
Expand Down
Binary file added tests/fixtures/images/switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.