From ca24d2a64956899571e6cfcdc1a4959261f45432 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Sun, 25 Feb 2024 23:15:47 +0800 Subject: [PATCH] fix selector bug and determine the path according to arch --- desktop_env/evaluators/getters/chrome.py | 27 +++++++++++-------- .../1704f00f-79e6-43a7-961b-cedd3724d5fd.json | 6 ----- .../2888b4e6-5b47-4b57-8bf5-c73827890774.json | 3 --- .../368d9ba4-203c-40c1-9fa3-da2f1430ce63.json | 6 ----- .../47543840-672a-467d-80df-8f7c3b9788c9.json | 9 ------- .../6c4c23a1-42a4-43cc-9db1-2f86ff3738cc.json | 3 --- .../7f52cab9-535c-4835-ac8c-391ee64dc930.json | 3 --- .../82279c77-8fc6-46f6-9622-3ba96f61b477.json | 3 --- .../82bc8d6a-36eb-4d2d-8801-ef714fb1e55a.json | 3 --- .../9f3f70fc-5afc-4958-a7b7-3bb4fcb01805.json | 8 +----- .../9f935cce-0a9f-435f-8007-817732bfc0a5.json | 3 --- .../a96b564e-dbe9-42c3-9ccf-b4498073438a.json | 3 --- .../b070486d-e161-459b-aa2b-ef442d973b92.json | 3 --- .../b4f95342-463e-4179-8c3f-193cd7241fb2.json | 3 --- .../b7895e80-f4d1-4648-bee0-4eb45a6f1fa8.json | 3 --- .../c1fa57f3-c3db-4596-8f09-020701085416.json | 3 --- .../cabb3bae-cccb-41bd-9f5d-0f3a9fecd825.json | 3 --- .../da46d875-6b82-4681-9284-653b0c7ae241.json | 11 +------- .../f3b19d1e-2d48-44e9-b4e1-defcae1a0197.json | 3 --- .../f79439ad-3ee8-4f99-a518-0eb60e5652b0.json | 3 --- .../fc6d8143-9452-4171-9459-7f515143419a.json | 3 --- 21 files changed, 18 insertions(+), 94 deletions(-) diff --git a/desktop_env/evaluators/getters/chrome.py b/desktop_env/evaluators/getters/chrome.py index d8e44c3..18153a7 100644 --- a/desktop_env/evaluators/getters/chrome.py +++ b/desktop_env/evaluators/getters/chrome.py @@ -1,6 +1,7 @@ import json import logging import os +import platform import time import sqlite3 from typing import Dict, Any, List @@ -363,10 +364,11 @@ def get_active_url_from_accessTree(env, config): This function is used to get the active tab url from the accessibility tree. config: Dict[str, str]{ - 'xpath': - the same as in metrics.general.accessibility_tree. - 'selectors': - the same as in metrics.general.accessibility_tree. + # we no longer need to specify the xpath or selectors, since we will use defalut value + # 'xpath': + # the same as in metrics.general.accessibility_tree. + # 'selectors': + # the same as in metrics.general.accessibility_tree. 'goto_prefix': the prefix you want to add to the beginning of the url to be opened, default is "https://", (the url we get from accTree does not have prefix) @@ -380,14 +382,17 @@ def get_active_url_from_accessTree(env, config): logger.debug("AT@eval: %s", accessibility_tree) # first, use accessibility API to get the active tab URL at: _Element = lxml.etree.fromstring(accessibility_tree) - if "xpath" in config: - elements: List[_Element] = at.xpath(config["xpath"], namespaces=_accessibility_ns_map) - elif "selectors" in config: - selector = CSSSelector(", ".join(config["selectors"]), namespaces=_accessibility_ns_map) - elements: List[_Element] = selector(at) + arch = platform.machine() + if "arm" in arch: + selector = CSSSelector(", application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]", namespaces=_accessibility_ns_map) else: - raise ValueError("At least one of xpath and selectors is required") - + selector = CSSSelector(", application[name=Google\\ Chrome] entry[name=Address\\ and\\ search\\ bar]", namespaces=_accessibility_ns_map) + elements: List[_Element] = selector(at) + # if "xpath" in config: + # elements: List[_Element] = at.xpath(config["xpath"], namespaces=_accessibility_ns_map) + # elif "selectors" in config: + # selector = CSSSelector(", ".join(config["selectors"]), namespaces=_accessibility_ns_map) + # elements: List[_Element] = selector(at) if len(elements) == 0: print("no elements found") return 0. diff --git a/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json b/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json index 109249f..566d666 100644 --- a/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json +++ b/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json @@ -46,17 +46,11 @@ "func":["check_direct_json_object", "check_direct_json_object"], "result": [{ "type": "active_tab_url_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "parse_keys": ["locationName", "dropLocationName", "filterCriteria_carCategory", "filterCriteria_sortBy"] }, { "type": "active_tab_html_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "xpath", "xpathObject":{ diff --git a/evaluation_examples/examples/chrome/2888b4e6-5b47-4b57-8bf5-c73827890774.json b/evaluation_examples/examples/chrome/2888b4e6-5b47-4b57-8bf5-c73827890774.json index a3e046c..ae2ced5 100644 --- a/evaluation_examples/examples/chrome/2888b4e6-5b47-4b57-8bf5-c73827890774.json +++ b/evaluation_examples/examples/chrome/2888b4e6-5b47-4b57-8bf5-c73827890774.json @@ -47,9 +47,6 @@ "func":"exact_match", "result": { "type": "url_dashPart", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "partIndex": -1, "needDeleteId": true, diff --git a/evaluation_examples/examples/chrome/368d9ba4-203c-40c1-9fa3-da2f1430ce63.json b/evaluation_examples/examples/chrome/368d9ba4-203c-40c1-9fa3-da2f1430ce63.json index 75295df..987c122 100644 --- a/evaluation_examples/examples/chrome/368d9ba4-203c-40c1-9fa3-da2f1430ce63.json +++ b/evaluation_examples/examples/chrome/368d9ba4-203c-40c1-9fa3-da2f1430ce63.json @@ -46,9 +46,6 @@ "func":["check_direct_json_object", "is_expected_url_pattern_match"], "result": [{ "type": "url_dashPart", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "partIndex": -2, "needDeleteId": false, @@ -57,9 +54,6 @@ }, { "type": "active_tab_info", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }], "expected":[ diff --git a/evaluation_examples/examples/chrome/47543840-672a-467d-80df-8f7c3b9788c9.json b/evaluation_examples/examples/chrome/47543840-672a-467d-80df-8f7c3b9788c9.json index 8ff1ca1..e7f58c4 100644 --- a/evaluation_examples/examples/chrome/47543840-672a-467d-80df-8f7c3b9788c9.json +++ b/evaluation_examples/examples/chrome/47543840-672a-467d-80df-8f7c3b9788c9.json @@ -48,16 +48,10 @@ "result": [ { "type": "active_url_from_accessTree", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, { "type": "active_tab_html_parse", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "class", "class_singleObject":{}, @@ -74,9 +68,6 @@ }, { "type": "active_tab_html_parse", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "xpath", "xpathObject":{ diff --git a/evaluation_examples/examples/chrome/6c4c23a1-42a4-43cc-9db1-2f86ff3738cc.json b/evaluation_examples/examples/chrome/6c4c23a1-42a4-43cc-9db1-2f86ff3738cc.json index 582aaca..e74a071 100644 --- a/evaluation_examples/examples/chrome/6c4c23a1-42a4-43cc-9db1-2f86ff3738cc.json +++ b/evaluation_examples/examples/chrome/6c4c23a1-42a4-43cc-9db1-2f86ff3738cc.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_html_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "class", "class_singleObject":{ diff --git a/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json b/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json index d08381b..6f37745 100644 --- a/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json +++ b/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_url_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "parse_keys": ["q", "tbs"] }, diff --git a/evaluation_examples/examples/chrome/82279c77-8fc6-46f6-9622-3ba96f61b477.json b/evaluation_examples/examples/chrome/82279c77-8fc6-46f6-9622-3ba96f61b477.json index c3d1051..3b22aa1 100644 --- a/evaluation_examples/examples/chrome/82279c77-8fc6-46f6-9622-3ba96f61b477.json +++ b/evaluation_examples/examples/chrome/82279c77-8fc6-46f6-9622-3ba96f61b477.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_url_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "parse_keys": ["list_price_max", "maximum_distance", "zip","fuel_slugs[]"] }, diff --git a/evaluation_examples/examples/chrome/82bc8d6a-36eb-4d2d-8801-ef714fb1e55a.json b/evaluation_examples/examples/chrome/82bc8d6a-36eb-4d2d-8801-ef714fb1e55a.json index 76cb2cb..f6c7a68 100644 --- a/evaluation_examples/examples/chrome/82bc8d6a-36eb-4d2d-8801-ef714fb1e55a.json +++ b/evaluation_examples/examples/chrome/82bc8d6a-36eb-4d2d-8801-ef714fb1e55a.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_url_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "parse_keys": ["fromStation", "toStation", "departing"], "replace":{ diff --git a/evaluation_examples/examples/chrome/9f3f70fc-5afc-4958-a7b7-3bb4fcb01805.json b/evaluation_examples/examples/chrome/9f3f70fc-5afc-4958-a7b7-3bb4fcb01805.json index 0e65934..951f521 100644 --- a/evaluation_examples/examples/chrome/9f3f70fc-5afc-4958-a7b7-3bb4fcb01805.json +++ b/evaluation_examples/examples/chrome/9f3f70fc-5afc-4958-a7b7-3bb4fcb01805.json @@ -47,16 +47,10 @@ "conj": "and", "result": [ { - "type": "active_tab_info", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ] + "type": "active_tab_info" }, { "type": "active_tab_html_parse", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "category": "xpath", "xpathObject":{ "/html/body/div[2]/div/div[6]/div[2]/div[2]/div/div[1]/div[4]/ul/li[2]": "money" diff --git a/evaluation_examples/examples/chrome/9f935cce-0a9f-435f-8007-817732bfc0a5.json b/evaluation_examples/examples/chrome/9f935cce-0a9f-435f-8007-817732bfc0a5.json index d24b29a..c360d62 100644 --- a/evaluation_examples/examples/chrome/9f935cce-0a9f-435f-8007-817732bfc0a5.json +++ b/evaluation_examples/examples/chrome/9f935cce-0a9f-435f-8007-817732bfc0a5.json @@ -46,9 +46,6 @@ "func":"is_expected_url_pattern_match", "result": { "type": "active_tab_info", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, "expected":{ diff --git a/evaluation_examples/examples/chrome/a96b564e-dbe9-42c3-9ccf-b4498073438a.json b/evaluation_examples/examples/chrome/a96b564e-dbe9-42c3-9ccf-b4498073438a.json index cfb0401..9566d00 100644 --- a/evaluation_examples/examples/chrome/a96b564e-dbe9-42c3-9ccf-b4498073438a.json +++ b/evaluation_examples/examples/chrome/a96b564e-dbe9-42c3-9ccf-b4498073438a.json @@ -56,9 +56,6 @@ "func":"is_expected_active_tab", "result": { "type": "active_tab_info", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, "expected":{ diff --git a/evaluation_examples/examples/chrome/b070486d-e161-459b-aa2b-ef442d973b92.json b/evaluation_examples/examples/chrome/b070486d-e161-459b-aa2b-ef442d973b92.json index 935126a..8c68f9d 100644 --- a/evaluation_examples/examples/chrome/b070486d-e161-459b-aa2b-ef442d973b92.json +++ b/evaluation_examples/examples/chrome/b070486d-e161-459b-aa2b-ef442d973b92.json @@ -46,9 +46,6 @@ "func":"exact_match", "result": { "type": "url_dashPart", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "partIndex": -1, "needDeleteId": false, diff --git a/evaluation_examples/examples/chrome/b4f95342-463e-4179-8c3f-193cd7241fb2.json b/evaluation_examples/examples/chrome/b4f95342-463e-4179-8c3f-193cd7241fb2.json index 39457ba..677cead 100644 --- a/evaluation_examples/examples/chrome/b4f95342-463e-4179-8c3f-193cd7241fb2.json +++ b/evaluation_examples/examples/chrome/b4f95342-463e-4179-8c3f-193cd7241fb2.json @@ -47,9 +47,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_html_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category":"class", "class_singleObject":{}, diff --git a/evaluation_examples/examples/chrome/b7895e80-f4d1-4648-bee0-4eb45a6f1fa8.json b/evaluation_examples/examples/chrome/b7895e80-f4d1-4648-bee0-4eb45a6f1fa8.json index 97a7534..8ffa341 100644 --- a/evaluation_examples/examples/chrome/b7895e80-f4d1-4648-bee0-4eb45a6f1fa8.json +++ b/evaluation_examples/examples/chrome/b7895e80-f4d1-4648-bee0-4eb45a6f1fa8.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_html_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "xpath", "xpathObject":{ diff --git a/evaluation_examples/examples/chrome/c1fa57f3-c3db-4596-8f09-020701085416.json b/evaluation_examples/examples/chrome/c1fa57f3-c3db-4596-8f09-020701085416.json index f98ab7e..d03e439 100644 --- a/evaluation_examples/examples/chrome/c1fa57f3-c3db-4596-8f09-020701085416.json +++ b/evaluation_examples/examples/chrome/c1fa57f3-c3db-4596-8f09-020701085416.json @@ -56,9 +56,6 @@ "func":"is_expected_url_pattern_match", "result": { "type": "active_tab_info", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, "expected":{ diff --git a/evaluation_examples/examples/chrome/cabb3bae-cccb-41bd-9f5d-0f3a9fecd825.json b/evaluation_examples/examples/chrome/cabb3bae-cccb-41bd-9f5d-0f3a9fecd825.json index 0c6fd04..43e6836 100644 --- a/evaluation_examples/examples/chrome/cabb3bae-cccb-41bd-9f5d-0f3a9fecd825.json +++ b/evaluation_examples/examples/chrome/cabb3bae-cccb-41bd-9f5d-0f3a9fecd825.json @@ -46,9 +46,6 @@ "func":"is_expected_url_pattern_match", "result": { "type": "active_url_from_accessTree", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, "expected":{ diff --git a/evaluation_examples/examples/chrome/da46d875-6b82-4681-9284-653b0c7ae241.json b/evaluation_examples/examples/chrome/da46d875-6b82-4681-9284-653b0c7ae241.json index 448d581..a458935 100644 --- a/evaluation_examples/examples/chrome/da46d875-6b82-4681-9284-653b0c7ae241.json +++ b/evaluation_examples/examples/chrome/da46d875-6b82-4681-9284-653b0c7ae241.json @@ -47,16 +47,10 @@ "conj": "and", "result": [ { - "type": "active_tab_info", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ] + "type": "active_tab_info" }, { "type": "active_tab_html_parse", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "category": "class", "class_singleObject":{}, "class_multiObject":{ @@ -68,9 +62,6 @@ }, { "type": "active_tab_html_parse", - "selectors": [ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "category": "input", "inputObject":{ "/html/body/div/div/form/div[7]/div/div/div[1]/input[1]": "name", diff --git a/evaluation_examples/examples/chrome/f3b19d1e-2d48-44e9-b4e1-defcae1a0197.json b/evaluation_examples/examples/chrome/f3b19d1e-2d48-44e9-b4e1-defcae1a0197.json index d781e67..74bc333 100644 --- a/evaluation_examples/examples/chrome/f3b19d1e-2d48-44e9-b4e1-defcae1a0197.json +++ b/evaluation_examples/examples/chrome/f3b19d1e-2d48-44e9-b4e1-defcae1a0197.json @@ -32,9 +32,6 @@ "func":"is_expected_url_pattern_match", "result": { "type": "active_tab_info", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www." }, "expected":{ diff --git a/evaluation_examples/examples/chrome/f79439ad-3ee8-4f99-a518-0eb60e5652b0.json b/evaluation_examples/examples/chrome/f79439ad-3ee8-4f99-a518-0eb60e5652b0.json index 015452e..74c78a3 100644 --- a/evaluation_examples/examples/chrome/f79439ad-3ee8-4f99-a518-0eb60e5652b0.json +++ b/evaluation_examples/examples/chrome/f79439ad-3ee8-4f99-a518-0eb60e5652b0.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_url_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "parse_keys":["originIata", "destinationIata", "tpAdults", "tpTeens", "tpChildren", "tpStartDate", "isReturn"], "replace":{ diff --git a/evaluation_examples/examples/chrome/fc6d8143-9452-4171-9459-7f515143419a.json b/evaluation_examples/examples/chrome/fc6d8143-9452-4171-9459-7f515143419a.json index 9b11e2f..336719e 100644 --- a/evaluation_examples/examples/chrome/fc6d8143-9452-4171-9459-7f515143419a.json +++ b/evaluation_examples/examples/chrome/fc6d8143-9452-4171-9459-7f515143419a.json @@ -46,9 +46,6 @@ "func":"check_direct_json_object", "result": { "type": "active_tab_html_parse", - "selectors":[ - "application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]" - ], "goto_prefix": "https://www.", "category": "class", "class_singleObject":{