fix selector bug and determine the path according to arch

This commit is contained in:
Jason Lee
2024-02-25 23:15:47 +08:00
parent 3244098664
commit ca24d2a649
21 changed files with 18 additions and 94 deletions

View File

@@ -1,6 +1,7 @@
import json import json
import logging import logging
import os import os
import platform
import time import time
import sqlite3 import sqlite3
from typing import Dict, Any, List 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. This function is used to get the active tab url from the accessibility tree.
config: config:
Dict[str, str]{ Dict[str, str]{
'xpath': # we no longer need to specify the xpath or selectors, since we will use defalut value
the same as in metrics.general.accessibility_tree. # 'xpath':
'selectors': # the same as in metrics.general.accessibility_tree.
the same as in metrics.general.accessibility_tree. # 'selectors':
# the same as in metrics.general.accessibility_tree.
'goto_prefix': 'goto_prefix':
the prefix you want to add to the beginning of the url to be opened, default is "https://", 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) (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) logger.debug("AT@eval: %s", accessibility_tree)
# first, use accessibility API to get the active tab URL # first, use accessibility API to get the active tab URL
at: _Element = lxml.etree.fromstring(accessibility_tree) at: _Element = lxml.etree.fromstring(accessibility_tree)
if "xpath" in config: arch = platform.machine()
elements: List[_Element] = at.xpath(config["xpath"], namespaces=_accessibility_ns_map) if "arm" in arch:
elif "selectors" in config: selector = CSSSelector(", application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]", namespaces=_accessibility_ns_map)
selector = CSSSelector(", ".join(config["selectors"]), namespaces=_accessibility_ns_map)
elements: List[_Element] = selector(at)
else: 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: if len(elements) == 0:
print("no elements found") print("no elements found")
return 0. return 0.

View File

@@ -46,17 +46,11 @@
"func":["check_direct_json_object", "check_direct_json_object"], "func":["check_direct_json_object", "check_direct_json_object"],
"result": [{ "result": [{
"type": "active_tab_url_parse", "type": "active_tab_url_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"parse_keys": ["locationName", "dropLocationName", "filterCriteria_carCategory", "filterCriteria_sortBy"] "parse_keys": ["locationName", "dropLocationName", "filterCriteria_carCategory", "filterCriteria_sortBy"]
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "xpath", "category": "xpath",
"xpathObject":{ "xpathObject":{

View File

@@ -47,9 +47,6 @@
"func":"exact_match", "func":"exact_match",
"result": { "result": {
"type": "url_dashPart", "type": "url_dashPart",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"partIndex": -1, "partIndex": -1,
"needDeleteId": true, "needDeleteId": true,

View File

@@ -46,9 +46,6 @@
"func":["check_direct_json_object", "is_expected_url_pattern_match"], "func":["check_direct_json_object", "is_expected_url_pattern_match"],
"result": [{ "result": [{
"type": "url_dashPart", "type": "url_dashPart",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"partIndex": -2, "partIndex": -2,
"needDeleteId": false, "needDeleteId": false,
@@ -57,9 +54,6 @@
}, },
{ {
"type": "active_tab_info", "type": "active_tab_info",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}], }],
"expected":[ "expected":[

View File

@@ -48,16 +48,10 @@
"result": [ "result": [
{ {
"type": "active_url_from_accessTree", "type": "active_url_from_accessTree",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "class", "category": "class",
"class_singleObject":{}, "class_singleObject":{},
@@ -74,9 +68,6 @@
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "xpath", "category": "xpath",
"xpathObject":{ "xpathObject":{

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "class", "category": "class",
"class_singleObject":{ "class_singleObject":{

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_url_parse", "type": "active_tab_url_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"parse_keys": ["q", "tbs"] "parse_keys": ["q", "tbs"]
}, },

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_url_parse", "type": "active_tab_url_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"parse_keys": ["list_price_max", "maximum_distance", "zip","fuel_slugs[]"] "parse_keys": ["list_price_max", "maximum_distance", "zip","fuel_slugs[]"]
}, },

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_url_parse", "type": "active_tab_url_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"parse_keys": ["fromStation", "toStation", "departing"], "parse_keys": ["fromStation", "toStation", "departing"],
"replace":{ "replace":{

View File

@@ -47,16 +47,10 @@
"conj": "and", "conj": "and",
"result": [ "result": [
{ {
"type": "active_tab_info", "type": "active_tab_info"
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
]
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"category": "xpath", "category": "xpath",
"xpathObject":{ "xpathObject":{
"/html/body/div[2]/div/div[6]/div[2]/div[2]/div/div[1]/div[4]/ul/li[2]": "money" "/html/body/div[2]/div/div[6]/div[2]/div[2]/div/div[1]/div[4]/ul/li[2]": "money"

View File

@@ -46,9 +46,6 @@
"func":"is_expected_url_pattern_match", "func":"is_expected_url_pattern_match",
"result": { "result": {
"type": "active_tab_info", "type": "active_tab_info",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
"expected":{ "expected":{

View File

@@ -56,9 +56,6 @@
"func":"is_expected_active_tab", "func":"is_expected_active_tab",
"result": { "result": {
"type": "active_tab_info", "type": "active_tab_info",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
"expected":{ "expected":{

View File

@@ -46,9 +46,6 @@
"func":"exact_match", "func":"exact_match",
"result": { "result": {
"type": "url_dashPart", "type": "url_dashPart",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"partIndex": -1, "partIndex": -1,
"needDeleteId": false, "needDeleteId": false,

View File

@@ -47,9 +47,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category":"class", "category":"class",
"class_singleObject":{}, "class_singleObject":{},

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "xpath", "category": "xpath",
"xpathObject":{ "xpathObject":{

View File

@@ -56,9 +56,6 @@
"func":"is_expected_url_pattern_match", "func":"is_expected_url_pattern_match",
"result": { "result": {
"type": "active_tab_info", "type": "active_tab_info",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
"expected":{ "expected":{

View File

@@ -46,9 +46,6 @@
"func":"is_expected_url_pattern_match", "func":"is_expected_url_pattern_match",
"result": { "result": {
"type": "active_url_from_accessTree", "type": "active_url_from_accessTree",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
"expected":{ "expected":{

View File

@@ -47,16 +47,10 @@
"conj": "and", "conj": "and",
"result": [ "result": [
{ {
"type": "active_tab_info", "type": "active_tab_info"
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
]
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"category": "class", "category": "class",
"class_singleObject":{}, "class_singleObject":{},
"class_multiObject":{ "class_multiObject":{
@@ -68,9 +62,6 @@
}, },
{ {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors": [
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"category": "input", "category": "input",
"inputObject":{ "inputObject":{
"/html/body/div/div/form/div[7]/div/div/div[1]/input[1]": "name", "/html/body/div/div/form/div[7]/div/div/div[1]/input[1]": "name",

View File

@@ -32,9 +32,6 @@
"func":"is_expected_url_pattern_match", "func":"is_expected_url_pattern_match",
"result": { "result": {
"type": "active_tab_info", "type": "active_tab_info",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www." "goto_prefix": "https://www."
}, },
"expected":{ "expected":{

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_url_parse", "type": "active_tab_url_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"parse_keys":["originIata", "destinationIata", "tpAdults", "tpTeens", "tpChildren", "tpStartDate", "isReturn"], "parse_keys":["originIata", "destinationIata", "tpAdults", "tpTeens", "tpChildren", "tpStartDate", "isReturn"],
"replace":{ "replace":{

View File

@@ -46,9 +46,6 @@
"func":"check_direct_json_object", "func":"check_direct_json_object",
"result": { "result": {
"type": "active_tab_html_parse", "type": "active_tab_html_parse",
"selectors":[
"application[name=Chromium] entry[name=Address\\ and\\ search\\ bar]"
],
"goto_prefix": "https://www.", "goto_prefix": "https://www.",
"category": "class", "category": "class",
"class_singleObject":{ "class_singleObject":{