diff --git a/browser_env/__init__.py b/browser_env/__init__.py index 90ecdbe..8a3812c 100644 --- a/browser_env/__init__.py +++ b/browser_env/__init__.py @@ -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, @@ -29,6 +30,7 @@ create_select_option_action, create_stop_action, create_type_action, + create_upload_action, is_equivalent, ) from .async_envs import AsyncScriptBrowserEnv @@ -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", diff --git a/browser_env/actions.py b/browser_env/actions.py index 13aaf1b..b1b1e15 100644 --- a/browser_env/actions.py +++ b/browser_env/actions.py @@ -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"]: @@ -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, diff --git a/tests/test_browser_env/test_actions.py b/tests/test_browser_env/test_actions.py index 332a32b..d0c0d63 100644 --- a/tests/test_browser_env/test_actions.py +++ b/tests/test_browser_env/test_actions.py @@ -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"]