Skip to content
Open
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
4 changes: 4 additions & 0 deletions browser_env/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
action2create_function,
action2str,
create_check_action,
create_clear_action,
create_click_action,
create_focus_and_click_action,
create_focus_and_type_action,
Expand All @@ -29,6 +30,7 @@
create_select_option_action,
create_stop_action,
create_type_action,
create_upload_action,
is_equivalent,
)
from .async_envs import AsyncScriptBrowserEnv
Expand Down Expand Up @@ -66,9 +68,11 @@
"create_scroll_action",
"create_key_press_action",
"create_check_action",
"create_clear_action",
"create_click_action",
"create_type_action",
"create_hover_action",
"create_upload_action",
"create_select_option_action",
"create_stop_action",
"ActionParsingError",
Expand Down
10 changes: 8 additions & 2 deletions browser_env/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,13 @@ def is_equivalent(a: Action, b: Action) -> bool:
return np.allclose(a["coords"], b["coords"])
case ActionTypes.KEYBOARD_TYPE:
return a["text"] == b["text"]
case ActionTypes.CLICK | ActionTypes.HOVER | ActionTypes.TYPE: # TODO: can be further optimized
case (
ActionTypes.CLICK
| ActionTypes.HOVER
| ActionTypes.TYPE
| ActionTypes.CLEAR
| ActionTypes.UPLOAD
): # TODO: can be further optimized
if a["element_id"] and b["element_id"]:
return a["element_id"] == b["element_id"]
elif a["element_role"] and b["element_role"]:
Expand Down Expand Up @@ -705,7 +711,7 @@ def create_upload_action(
action = create_none_action()
action.update(
{
"action_type": ActionTypes.TYPE,
"action_type": ActionTypes.UPLOAD,
"element_id": element_id,
"element_role": _role2id[element_role],
"element_name": element_name,
Expand Down
10 changes: 8 additions & 2 deletions tests/test_browser_env/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ def test_is_equivalent() -> None:
assert not is_equivalent(action_a, action_b)
action_a["text"] = action_b["text"]
assert is_equivalent(action_a, action_b)
case ActionTypes.CLICK | ActionTypes.HOVER | ActionTypes.TYPE:
case (
ActionTypes.CLICK
| ActionTypes.HOVER
| ActionTypes.TYPE
| ActionTypes.CLEAR
| ActionTypes.UPLOAD
):
if action_a["element_id"] and action_b["element_id"]:
if action_a["element_id"] != action_b["element_id"]:
assert not is_equivalent(action_a, action_b)
action_a["element_id"] = action_b["element_id"]
assert is_equivalent(action_a, action_b)
elif action_a["element_id"] and action_b["element_id"]:
elif action_a["element_role"] and action_b["element_role"]:
if action_a["element_role"] != action_b["element_role"]:
assert not is_equivalent(action_a, action_b)
action_a["element_role"] = action_b["element_role"]
Expand Down