From 2c08a02206dea4908ce54f5d7aa4e1a746bb85c8 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 27 Feb 2024 18:37:32 +0800 Subject: [PATCH] fix the error caused by url encoding --- desktop_env/evaluators/getters/chrome.py | 10 +++++++--- .../chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json | 4 ++-- .../chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/desktop_env/evaluators/getters/chrome.py b/desktop_env/evaluators/getters/chrome.py index d40de23..48060a6 100644 --- a/desktop_env/evaluators/getters/chrome.py +++ b/desktop_env/evaluators/getters/chrome.py @@ -4,6 +4,7 @@ import os import platform import sqlite3 import time +from urllib.parse import unquote from typing import Dict, Any, List from urllib.parse import urlparse, parse_qs @@ -985,6 +986,7 @@ def get_active_tab_html_parse(env, config: Dict[str, Any]): """ active_tab_url = get_active_url_from_accessTree(env, config) if not isinstance(active_tab_url, str): + logger.error("active_tab_url is not a string") return None host = env.vm_ip port = 9222 # fixme: this port is hard-coded, need to be changed from config file @@ -1017,12 +1019,14 @@ def get_active_tab_html_parse(env, config: Dict[str, Any]): for context in browser.contexts: for page in context.pages: page.wait_for_load_state("networkidle") - if page.url == active_tab_url: + # the accTree and playwright can get encoding(percent-encoding) characters, we need to convert them to normal characters + if unquote(page.url) == unquote(active_tab_url): target_page = page - print("tartget page url: ", target_page.url) - print("tartget page title: ", target_page.title()) + print("\33[32mtartget page url: ", target_page.url, "\33[0m") + print("\33[32mtartget page title: ", target_page.title(), "\33[0m") break if target_page is None: + logger.error("Your tab is not the target tab.") return {} return_json = {} if config["category"] == "class": 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 566d666..e545c9b 100644 --- a/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json +++ b/evaluation_examples/examples/chrome/1704f00f-79e6-43a7-961b-cedd3724d5fd.json @@ -62,8 +62,8 @@ "type": "rule", "rules":{ "expected": { - "locationName": "Zurich Airport", - "dropLocationName": "Zurich Airport", + "locationName": "Zürich", + "dropLocationName": "Zürich", "filterCriteria_carCategory": "large", "filterCriteria_sortBy": "PRICE" } 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 6f37745..b2a6b2a 100644 --- a/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json +++ b/evaluation_examples/examples/chrome/7f52cab9-535c-4835-ac8c-391ee64dc930.json @@ -54,7 +54,7 @@ "rules":{ "expected": { "q": "drip coffee maker", - "tbs": "mr:1,price:1,ppr_min:25,ppr_max:60,pdtr0:1825161|1825162" + "tbs": "mr:1,price:1,ppr_min:25,ppr_max:60,sales:1,pdtr0:1825161|1825162" } } }