Method, device and medium for path positioning based on dictionary tree structure and weight learning
The path localization method based on trie structure and weight learning solves the problem of difficult locator maintenance in traditional web automation testing, achieving higher localization accuracy and lower maintenance costs, and is suitable for element localization in dynamic web pages.
Patent Information
- Application Number
- CN202511232799.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2045-08-29
AI Technical Summary
Traditional web automation testing tools rely on XPath or CSS selectors when locating dynamic web page elements, resulting in high technical coupling. Dynamically generated class names introduce characteristic noise interference, affecting the accuracy of location. Furthermore, the maintenance workload of automated test scripts is large, and the maintenance cost is high.
A path localization method based on trie structure and weight learning is adopted. By acquiring document object model elements, evaluating node weight scores, extracting feature information of target nodes to generate comprehensive feature codes, and matching similar features with a pre-set trie, a recommended target path is generated.
It improves positioning accuracy, reduces technical coupling, reduces maintenance costs, improves test case development efficiency, makes the locator more stable in dynamic web pages, and can incrementally learn based on user feedback.
Smart Images

Figure CN120743791B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer science, and more particularly to a path localization method, device, and medium based on a trie structure and weight learning. Background Technology
[0002] In the field of web automation testing, element location is a crucial step in ensuring that test scripts can accurately identify and manipulate web page elements, directly impacting the accuracy and reliability of the test. Current mainstream web automation testing tools, such as Selenium, primarily rely on XPath (XML Path Language) or CSS (Cascading Style Sheets) selectors to locate page elements.
[0003] However, dynamic web pages are highly flexible and interactive, and their DOM (Document Object Model) structure changes frequently based on user operations, data loading, and other factors. This makes element locators based on traditional positioning methods prone to failure, posing a huge challenge to web automation testing. Summary of the Invention
[0004] This invention provides a path localization method, device, and medium based on trie structure and weight learning, which at least solves the problems of traditional element localization relying on array indexes and other paths, high technical coupling, feature noise interference from dynamically generated class names in dynamic web pages affecting localization accuracy, and large workload and high maintenance cost of locator in automated test scripts.
[0005] This invention provides a path localization method based on a trie structure and weight learning, comprising the following steps: obtaining document object model elements; evaluating the weight scores of the nodes of the document object model elements, determining target nodes that meet preset importance conditions based on the weight scores of the nodes of the document object model elements; extracting feature information of the target nodes to generate a comprehensive feature code, performing similarity feature matching based on the comprehensive feature code of the target nodes and a preset trie, and generating a recommended target path based on the structure tree of the successfully matched similar features when the comprehensive feature code of the target nodes matches the preset trie.
[0006] This invention also provides a path localization system based on a trie structure and weight learning, comprising: an acquisition module for acquiring document object model elements; an evaluation module for evaluating the weight scores of nodes of the document object model elements, and determining target nodes that meet preset importance conditions based on the weight scores of nodes of the document object model elements; and a localization module for extracting feature information of the target nodes to generate a comprehensive feature code, performing similarity feature matching based on the comprehensive feature code of the target nodes and a preset trie, and generating a recommended target path based on the structure tree of the successfully matched similar features when the comprehensive feature code of the target nodes matches the preset trie.
[0007] The present invention also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of the path localization method based on the trie structure and weight learning described above when executing the computer program.
[0008] The present invention also provides a non-volatile computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the path localization method based on the trie structure and weight learning described above.
[0009] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described path localization method based on a trie structure and weight learning.
[0010] This invention obtains Document Object Model (DOM) elements, evaluates the weight scores of the nodes of DOM elements, determines target nodes that meet preset importance conditions based on the weight scores of the nodes of DOM elements, extracts feature information of the target nodes to generate comprehensive feature codes, performs similarity feature matching based on the comprehensive feature codes of the target nodes and a preset trie, and generates recommended target paths based on the structure tree of the successfully matched similar features when the comprehensive feature codes of the target nodes match the preset trie. This solves the problems of traditional element location relying on array indices and other paths, high technical coupling, feature noise interference from dynamically generated class names in dynamic web pages affecting location accuracy, and high maintenance workload and cost of locators in automated test scripts. It improves location accuracy, reduces technical coupling, and can recommend XPath structures based on the user-selected DOM elements in test case development, saving development time. Attached Figure Description
[0011] To more clearly illustrate the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 A flowchart illustrating a path localization method based on a trie structure and weight learning according to an embodiment of the present invention;
[0013] Figure 2 This is a flowchart illustrating a path localization method based on trie structure and weight learning according to an embodiment of the present invention.
[0014] Figure 3 This is a schematic diagram of a DOM structure node according to an embodiment of the present invention;
[0015] Figure 4 This is a schematic diagram of a path localization system based on a trie structure and weight learning according to an embodiment of the present invention;
[0016] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of the present invention.
[0018] It should be noted that, in the description of this invention, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., used in this invention are used to distinguish similar objects and are not used to describe a specific order or sequence.
[0019] In the field of web automation testing, element locator failure has long been a technical pain point. Current mainstream tools (such as Selenium) rely on XPath or CSS selectors to locate page elements, but changes in the DOM structure of dynamic web pages (such as class name changes and node hierarchy adjustments) can cause locators to fail on a large scale.
[0020] Traditional solutions have three limitations:
[0021] High technical coupling: The positioning path includes global XPath paths using array indices such as div[3] / button[2], which will fail when the front end is fine-tuned.
[0022] Characteristic noise interference: Dynamically generated class names (such as class="c7b3f") cannot be used as stable identifiers.
[0023] Out-of-control maintenance costs: In automated test scripts, location maintenance accounts for 67% of the overall workload. To solve the above problem, this invention provides a path localization method based on trie structure and weight learning.
[0024] XPath is a query language used to locate and select specific nodes in XML or HTML documents. Based on path expressions, it allows developers to precisely match target nodes using conditions such as element name, attributes, hierarchical relationships, and text content. XPath is widely used in web automation testing (such as Selenium), data scraping (such as web crawling), and XML data processing, providing both absolute path and relative path locating methods to improve the flexibility and accuracy of element location.
[0025] like Figure 1 As shown, this path localization method based on trie structure and weight learning includes the following steps:
[0026] Step S101: Obtain the document object model element.
[0027] Specifically, such as Figure 2 As shown, by installing a specific browser plugin, the user selects the document object model element information they need to locate on the page. The plugin traces the DOM tree down to the body structure and then passes the document object model element to the program core.
[0028] It should be noted that there are many similar open-source plugins on the market. Therefore, the following text will not describe information related to plugins and DOM collection.
[0029] Step S102: Evaluate the weight scores of nodes of document object model elements, and determine the target nodes that meet the preset importance conditions based on the weight scores of nodes of document object model elements.
[0030] Optionally, in some embodiments, evaluating the weight scores of nodes of a Document Object Model (DOM) element includes: determining the attribute weight score, semantic value weight score, and structural value of the nodes of the DOM element; calculating the sum of the attribute weight score and the semantic value weight score of the nodes of the DOM element, and obtaining the weight score of the nodes of the DOM element based on the product of the sum and the structural value.
[0031] After obtaining Document Object Model (DOM) elements, the program evaluates the weight score of each HTML DOM node sequentially from three dimensions: node attributes, semantic value, and structural value. Based on the weight score, it selects target nodes according to preset importance criteria. The formula for calculating the weight score of DOM element nodes is as follows:
[0032] (Node attribute weight score + semantic value weight score) * structural value.
[0033] For example, if a node of a Document Object Model element has a node attribute weight score of 40, a semantic value weight score of 20, and a structural value of 1.5, then the weight score of a node of that Document Object Model element is 90.
[0034] By employing the above technical solutions, the weight scores of nodes are evaluated at a fine-grained level based on multi-dimensional value, thereby improving the accuracy of selecting important nodes and enhancing the accuracy of path recommendations.
[0035] Optionally, in some embodiments, determining the target node that satisfies the preset importance condition based on the weight score of the nodes of the document object model element includes: determining whether there is a first node in the document object model element with a weight score greater than a first threshold; if there is a first node, determining whether the number of the first node is greater than or equal to a first preset value; if the number of the first node is greater than or equal to the first preset value, determining that the first node is a target node that satisfies the preset importance condition.
[0036] The first threshold and the first preset value can be thresholds preset by the user, thresholds obtained through a limited number of experiments, or thresholds obtained through a limited number of computer simulations.
[0037] In this embodiment of the invention, taking a first threshold of 80 points as an example and a first preset value of 5 as an example:
[0038] If there is a first node with a weight score greater than 80 in the document object model element, then it is further determined whether the number of first nodes is greater than or equal to 5. If the number of first nodes is greater than or equal to 5, then the first node is taken as the target node that meets the preset importance condition.
[0039] By employing the above technical solution and using the dual constraints of "weight score threshold + quantity threshold", misjudgments caused by abnormal weights of individual nodes or overly strict / loose threshold settings are avoided, thereby improving the stability of screening important nodes.
[0040] Optionally, in some embodiments, after determining whether the number of first nodes is greater than or equal to a first preset value, the method includes: if the number of first nodes is less than the first preset value and the number of first nodes is greater than or equal to a second preset value, then the second node among the first nodes that meets the preset quantity condition is taken as the target node.
[0041] The second preset value can be a threshold set by the user, a threshold obtained through a limited number of experiments, or a threshold obtained through a limited number of computer simulations.
[0042] In this embodiment of the invention, taking a second preset value of 3 as an example:
[0043] Understandably, if the number of first nodes is less than 5, then it is determined whether the number of first nodes is greater than or equal to 3. If the number of first nodes is greater than or equal to 3, then the first nodes are sorted from high to low according to their weight scores, and at least the top three nodes in the weight score ranking are taken as target nodes.
[0044] If multiple nodes have the same weight score (i.e., "duplicate score"), the node that is later in the sort (i.e., "later node") is selected first.
[0045] For example, if nodes A (weight score = 90), B (weight score = 90), and C (weight score = 80) are sorted into [A, B, C], and if we prioritize taking the last node, then the first 3 nodes in [B, A, C] are selected as the target nodes.
[0046] By using the above technical solution, and by setting two threshold values, the processing strategy can be dynamically adjusted according to the actual number of nodes. When there are enough nodes, all nodes are processed directly to avoid information loss due to over-filtering. When there are not enough nodes, a secondary filter is started to ensure that at least a certain number of key nodes (such as 3) are retained to avoid the inability to support core functions due to too few nodes.
[0047] Optionally, in some embodiments, determining the attribute weight score of a node of a Document Object Model (DOM) element includes: identifying the current attribute of the node of the DOM element; if the current attribute is a unique identifier attribute, assigning a first score as the attribute weight score of the node of the DOM element; if the current attribute is a business attribute, assigning a second score as the attribute weight score of the node of the DOM element; if the current attribute is a role attribute, assigning a third score as the attribute weight score of the node of the DOM element; if the current attribute is a class name attribute, assigning a fourth score as the attribute weight score of the node of the DOM element, wherein the first score is greater than the second score, and the second score is greater than the third score.
[0048] The first score, second score, third score, and fourth score can be thresholds preset by the user, thresholds obtained through a limited number of experiments, or thresholds obtained through a limited number of computer simulations.
[0049] Specifically, the program extracts the built-in attributes of each Document Object Model element's node, including but not limited to: unique identifier attribute id, class name attribute class, business attribute data-*, role attribute role, value attribute value, title attribute title, etc. It then calculates the attribute weight score for the corresponding node for different attribute pairs.
[0050] In this embodiment of the invention, the unique identifier ID attribute has the highest weight score, which can be 40 points, meaning the first score is 40 points. Because IDs are typically unique identifiers in HTML, the ID attribute is automatically assigned the maximum score of 40 points, regardless of whether its value is randomly generated or semantically explicit.
[0051] For example, if a node has id="submit-btn" or id="a8b3c2", then the corresponding attribute weight score is 40 points.
[0052] Business data-* attributes (such as data-type / data-role): The weight score can be 30 points, meaning the second score is 30 points. These custom attributes are often used in business logic; their existence automatically earns them 30 points, prioritizing their potential value, but the weight score may be adjusted later based on semantic evaluation.
[0053] The role attribute has a weight score of 20 points, meaning the third-highest score is 20 points. Role is an ARIA role attribute used for accessibility; its presence automatically awards 20 points, such as role="button".
[0054] The class name attribute: The weight score can be 20 points. The existence of a class name will get a base score of 20 points, but it should be noted that this score is based on the evaluation of "existence". Additional points will be added or deducted based on the business semantic value of the class name (for example, style classes such as class="clearfix" may be reduced in weight). Therefore, the fourth score may be less than or equal to 20 points, or it may be greater than or equal to 20 points.
[0055] By employing the aforementioned technical solution, the importance of nodes is accurately quantified through weighted scoring of the attributes of Document Object Model (DOM) elements, thereby providing a reliable basis for subsequent path recommendations.
[0056] Optionally, in some embodiments, determining the semantic value weight score of a node of a document object model element includes: determining whether the node of the document object model element has a target business keyword; if the node of the document object model element has a target business keyword, then assigning a fifth score as the semantic value weight score of the node of the document object model element; otherwise, determining whether the node of the document object model element satisfies a preset random generation feature; if the node of the document object model element satisfies the preset random generation feature, then assigning a sixth score as the semantic value weight score of the node of the document object model element; otherwise, assigning a seventh score as the semantic value weight score of the node of the document object model element, wherein the fifth score is greater than the sixth and seventh scores, and the sixth score is less than the seventh score.
[0057] The fifth, sixth, and seventh scores can be user-preset thresholds, thresholds obtained through a limited number of experiments, or thresholds obtained through a limited number of computer simulations.
[0058] Understandably, if a node's attribute is simply "existence," then semantics involves a secondary check on the "existence" information and the values of related attributes. This embodiment of the invention categorizes the semantic value of nodes in the Document Object Model (DOM) into three cases based on the built-in language model:
[0059] If a node of a Document Object Model element contains meaningful business keywords, the semantic value weight score is 20 points, that is, the fifth score is 20 points, such as id="btn-submit" and class="add-panel".
[0060] If a node of a document object model element contains a target business keyword, then it is determined whether the node of the document object model element satisfies the preset random generation feature. If a node of a document object model element contains a randomly generated string, then the semantic value weight score of the node of the document object model element is -20 points, that is, the sixth score is -20 points, for example, id="a8b3c2".
[0061] If a node of a Document Object Model element is a string or number without a business keyword, the semantic value weight score is 0, that is, the seventh score is 0, for example, data-index="0" and data-type="a".
[0062] The above technical solution assigns the highest semantic weight to business keywords to accurately identify core business nodes, assigns neutral weight when there are no business keywords, filters out irrelevant noise nodes, and assigns negative weight to random strings to reduce priority and security risks.
[0063] Optionally, in some embodiments, determining the structural value of a node of a Document Object Model (DOM) element includes: determining whether the node of the DOM element is a main content area node; if the node of the DOM element is a main content area node, then assigning a first preset value to the structural value of the node of the DOM element; otherwise, determining whether the node of the DOM element is a footer node or a sidebar node, or determining whether the node of the DOM element is a transition container node, or determining whether the node of the DOM element is a business-carrying node; if the node of the DOM element is a footer node or a sidebar node, then assigning a second preset value to the structural value of the node of the DOM element; if the node of the DOM element is a transition container node, then assigning a third preset value to the structural value of the node of the DOM element; if the node of the DOM element is a business-carrying node, then assigning a fourth preset value to the structural value of the node of the DOM element, wherein the first preset value is greater than the fourth preset value, the fourth preset value is greater than the second preset value, and the second preset value is greater than the third preset value.
[0064] The first preset value, the second preset value, the third preset value, and the fourth preset value can be thresholds preset by the user, thresholds obtained through a limited number of experiments, or thresholds obtained through a limited number of computer simulations.
[0065] It is understandable that the structural value of a node in a Document Object Model (DOM) element is obtained by determining the position coefficient or container role of the node. The position coefficient includes the main content area, footer or sidebar, transition container, etc., while the container role includes business-carrying nodes such as form container or list container.
[0066] In this embodiment of the invention, if the position coefficient of a node of a document object model element is a node of the main content area, then the structural value of a node of a document object model element is 1.5, that is, the first preset value is 1.5.
[0067] If the node of a Document Object Model (DOM) element is a footer node or a sidebar node, then the structural value of the node of the DOM element is 0.8, which is the second preset value of 0.8.
[0068] If a node of a Document Object Model (DOM) element is a transition container node, then the structural value of the node of the DOM element is, i.e., the third preset value is 0.5.
[0069] If the container role of a node of a Document Object Model element is a business-carrying node, such as a form container or list container, then the structural value of the node of the Document Object Model element is 1.3, which is the fourth preset value of 1.3.
[0070] For example, the descriptions of the attributes, semantic value, and structural value of nodes in a Document Object Model element are as follows: Figure 3 As shown, the weight scores of nodes A, B, C, and D of the document object model element are evaluated.
[0071] Evaluation of node A: Weight score of node A = Unique identifier ID exists (i.e., the first score is 40 points) + Class name contains business terms (i.e., the fourth score is 15 points) × Main content area node (i.e., the first preset value is 1.5) = 82.5 points.
[0072] Evaluation of node B: The weight score of node B = class name exists (i.e., the attribute weight score is 20 points) × sidebar position (i.e., the structural value is 0.8) = 16 points (not belonging to the target node: filter).
[0073] Evaluation of node C: The weight score of node C = existence of data-role (i.e., the attribute weight score is 25 points) × content area coefficient (i.e., the structural value is 1.5) = 37.5 points.
[0074] Node D evaluation: Node D's weight score = Class name exists (i.e., attribute weight score is 20 points) × Overloaded container (i.e., structural value is 0.5 points) = 10 points (not belonging to the target node: filter).
[0075] Node E evaluation: ID exists (i.e., attribute weight score is 40 points) + contains business text (i.e., semantic value weight score is 10 points) = 50 points.
[0076] Based on the weight scores of nodes A, B, C, and D, the target node sequence is output as: [A, C, E] → Target path XPath is generated: / / *[@id='app'] / main[@data-role='content-area'] / button[@id='submit-btn'].
[0077] Through the above technical solution, the main content area node is given the highest structural value, which can accurately locate the core area of the page; the business carrying node is given the second highest structural value, which can be used to monitor the business nodes; the footer / sidebar node is given the second lowest structural value, which can distinguish the auxiliary function area; and the transition container node is given the lowest structural value, which can clean up redundant structures.
[0078] Step S103: Extract the feature information of the target node to generate a comprehensive feature code. Perform similar feature matching between the comprehensive feature code of the target node and the preset trie. If the comprehensive feature code of the target node matches the preset trie successfully, generate a recommended target path based on the structure tree of the successfully matched similar features.
[0079] It should be understood that the present invention utilizes the data structure of the trie itself to sequentially put the feature information of each node of an XPath into the node to form the corresponding trie. When it is confirmed that a certain node needs to be located, it is only necessary to read all the node information on the corresponding path sequentially from the root node and then concatenate them to form the complete XPath.
[0080] Taking the example above as an example, assuming that the XPath has been added to the preset trie, its internal structure is as follows:
[0081] body→[type=div:2, id=*app*]→[type=main:2, data-role=content-*]→[type=button:leaf, id=*btn, text=A3F9].
[0082] There is a new DOM structure. After DOM weight evaluation and feature extraction, its XPath information is as follows: body→ / *[@id='app-v2']→ / main[@data-role='content-area']→ / div[@id='submit-parent']→ / button[@id='submit-btn']. Comparing it with the information already in the trie, there is an extra parent div wrapped around the button. After matching, the information already existing in the trie will be recommended first, followed by the current XPath information.
[0083] Optionally, in some embodiments, extracting feature information of the target node to generate a comprehensive feature code includes: extracting structural features, attribute features, and semantic features of the target node; and concatenating the structural features, attribute features, and semantic features of the target node to generate a comprehensive feature code of the target node.
[0084] Specifically, after the DOM weighting algorithm selects the target node, the feature extractor reads the feature information of the target node and performs feature distillation. It's important to note that the feature extractor reads the original DOM node, not the XPath structure. It still extracts features from the target node from three dimensions: structural features, attribute features, and semantic features. The specific extraction process is as follows:
[0085] 1. Structural fingerprint features: Determine the element's location and environment from the target node structure within the context, for example:
[0086] A combination of node tag and direct child element type (e.g., div>h3+ul).
[0087] The position ratio within the parent container (e.g., first child node / 5 child nodes in total → "0.2").
[0088] 2. Stable attribute characteristics: Determining element characteristics from some common attribute information, for example:
[0089] Extract common prefixes of class names (e.g., btn-primary / btn-danger → feature "btn-*").
[0090] Data attribute pattern abstraction (e.g., data-type="user-123" → feature "data-type=user-*").
[0091] 3. Semantic features, similar to weights, extract keywords from a semantic perspective, for example:
[0092] Business text keyword fingerprint ("Submit" → code A3F9, "Cancel" → B2E4).
[0093] Role type tag (role="dialog" → encoded NAV).
[0094] For the previous node E (<buttonid="submit-btn"> Submission), extraction process example:
[0095] Structural features: button tag + no child elements → "button:leaf";
[0096] Attribute characteristics: ID containing "submit" → pattern "id=*btn";
[0097] Semantic features: text "submit" → fingerprint "A3F9";
[0098] Finally, the structural features, attribute features, and semantic features of the target node are concatenated to generate the comprehensive feature code of the target node: [type=button:leaf, id=*btn, text=A3F9].
[0099] By using the above technical solutions, comprehensive feature encoding is used to replace single attribute matching, thereby reducing false matching and significantly improving the robustness of feature matching.
[0100] Optionally, in some embodiments, similarity feature matching is performed between the comprehensive feature code of the target node and a preset trie. If the comprehensive feature code of the target node matches the preset trie successfully, a recommended target path is generated based on the structure tree of the successfully matched similar features. This includes: sequentially passing the comprehensive feature code of the target node from the root node of the preset trie for matching; if there is a matching node in the target node whose comprehensive feature code matches the preset trie with a similarity feature matching degree greater than a second threshold, then it is determined that the comprehensive feature code of the target node matches the preset trie successfully; and the recommended target path is returned according to the weight value of the matching node.
[0101] The second threshold can be a threshold preset by the user, a threshold obtained through a limited number of experiments, or a threshold obtained through a limited number of computer simulations.
[0102] Specifically, the comprehensive feature code of the target node is cyclically input and matched with the preset trie. (Note that a maximum of 3 levels of the preset trie are matched with the comprehensive feature code of the target node.) If there is a matching node in the target node whose comprehensive feature code matches the preset trie with a similarity feature matching degree greater than the second threshold, then the comprehensive feature code of the target node is determined to be a successful match with the preset trie. The nodes with successful matches are sorted from highest to lowest weight value and a maximum of 3 nodes are selected as matching nodes. The recommended target path is returned based on the structure of the matching nodes.
[0103] It should be noted that if a node in the preset trie has a matching direct child node, the weight value of the child node is increased.
[0104] The above technical solution reduces false matches by replacing single-attribute matching with comprehensive feature encoding, and limits the matching range by using hierarchical matching rules (root node → up to 3 child nodes), thus balancing retrieval efficiency and accuracy.
[0105] Optionally, in some embodiments, after generating the target path, the process includes: obtaining user feedback information based on the target path; if the feedback information indicates that the path is available, then adding a weight value of the target path to a preset trie; if the feedback information indicates that the path is unavailable, then adding a new node to the preset trie.
[0106] As described above, this program's XPath localization method is based on an initial XPath derived from DOM weight evaluation, supplemented by feature extraction and comparison with a trie. In fact, the results from the trie are more accurate than those from DOM weight evaluation due to user feedback. After the program provides a recommended target XPath, users can provide feedback on its usability. If usable, the target path's feature information is added to the dictionary, and its weight is increased in the pre-defined trie. The more times a path is used, the higher its weight becomes, achieving a "the more you use it, the more accurate it becomes" effect.
[0107] If the user reports that the target path is unavailable, a new node is added to the preset trie, and the new node is recorded as the default weight value.
[0108] When a user's actual target path is used and a new path is given on the original route, a new path will be given in the trie according to the node characteristics. At this time, the button has two links in the trie. Subsequently, according to the user's choice, the weight value of one link will become higher and higher. When similar paths are passed in, the path with the higher weight value will always be recommended to the user first.
[0109] The above technical solution enhances the dynamic adaptability of the trie by driving the dynamic update of the trie through user feedback information (path availability / unavailability).
[0110] Optionally, in some embodiments, if the comprehensive feature encoding of the target node fails to match the preset trie, the method includes: returning the target path generated based on the target node.
[0111] Understandably, when the comprehensive feature encoding of the target node cannot match the preset trie, a target path is dynamically generated based on the attribute or structural information of the target node, and the generated target path is returned to the user. A new node is added to the preset trie and recorded as the default weight value.
[0112] By using the above technical solution, when the trie matching fails, the target path (such as XPath) is directly generated based on the original features of the target node, avoiding recommendation interruption due to matching failure and ensuring system availability.
[0113] Optionally, in some embodiments, the path localization method based on trie structure and weight learning described above further includes: obtaining the usage count of at least one path in a preset trie; and adjusting the weight value of at least one path according to the usage count of at least one path.
[0114] Specifically, the trie is traversed periodically (e.g., hourly / daily), and the weights are updated based on the number of times a path is used.
[0115] For example, for high-frequency paths that are used more often than the first time, the weight value of the corresponding path will be increased, and it will be matched with priority when the user uses it again; for low-frequency paths that are used less often than the second time, the weight value of the corresponding path will be decreased, and it will be matched less often when the user uses it.
[0116] The above technical solution dynamically adjusts the weight of the trie nodes based on the number of times the path is used, thereby enabling priority recommendation of high-frequency paths.
[0117] Optionally, in some embodiments, the path localization method based on trie structure and weight learning described above further includes: cleaning up nodes in a preset trie that have not been used for more than a preset time and whose corresponding weight values are less than a third threshold, based on a preset period.
[0118] Among them, the preset period, preset time, and third threshold can be thresholds preset by the user, thresholds obtained through a limited number of experiments, or thresholds obtained through a limited number of computer simulations.
[0119] It should be understood that a node in the preset trie can be cleaned up weekly if the unused time of a certain node exceeds a preset time and the weight value of that node is less than the third threshold.
[0120] For example, taking a preset time of 30 days and a third threshold of 50, if it is detected that a certain node A has not been used for 40 days and the current weight of a certain node A is 40, then a certain node A will be cleaned up.
[0121] By using the above technical solutions, long-term unused and low-weight nodes are cleaned up regularly, preventing the trie from expanding indefinitely due to sparse user behavior or dynamic page changes, thereby reducing storage costs and query latency.
[0122] To enable those skilled in the art to further understand the path localization based on trie structure and weight learning in the embodiments of this application, the following detailed description is provided in conjunction with specific embodiments, such as... Figure 2 As shown.
[0123] Step 1: Users install a specific browser plugin and select the element information they need to locate on the page.
[0124] Step 2: The plugin traces the DOM tree down to the body structure and then sends the information to the program core.
[0125] Step 3: The DOM weight evaluation program parses the input HTML structure according to a preset algorithm and selects important nodes.
[0126] Step 4: The feature extractor traverses the nodes to extract feature information for each important node. Then, it attempts to find if a similar dictionary structure tree exists within the trie. If no similar structure tree exists, it directly returns the important node. If a similar structure tree exists, it extracts all similar structure trees from the dictionary and returns them one by one according to their weight values as the recommended XPath.
[0127] Step 5: Users use the XPath provided by the system to perform actual verification and provide feedback. The feedback mechanism optimizes the trie based on the user's feedback.
[0128] In summary, the technical effects brought about by the embodiments of the present invention are as follows.
[0129] (1) Improve positioning stability by establishing a dictionary tree to filter noise and calculate node weights, making the locator more stable in the front-end iteration.
[0130] (2) Reduce the technical coupling and elevate the positioning to the business logic layer to reduce large-scale modifications to the locator due to changes in the front end.
[0131] (3) Achieve optimization closed loop, drive incremental learning with the help of user feedback, and make the locator "more and more accurate the more it is used".
[0132] (4) Improve development efficiency. In test case development, the XPath structure can be recommended based on the DOM element selected by the user, saving development time.
[0133] Next, referring to the accompanying drawings, the path localization method based on trie structure and weight learning proposed according to an embodiment of the present invention is described.
[0134] Figure 4 This is a schematic diagram of a path localization system based on a trie structure and weight learning according to an embodiment of the present invention.
[0135] like Figure 4 As shown, the path localization system 10 based on trie structure and weight learning includes: acquisition module 100, evaluation module 200 and localization module 300.
[0136] The document object model (DOM) includes: an acquisition module 100 for acquiring document object model elements; an evaluation module 200 for evaluating the weight scores of nodes in the DOM elements and determining target nodes that meet preset importance conditions based on the weight scores of the nodes in the DOM elements; and a localization module 300 for extracting feature information of target nodes to generate comprehensive feature codes, performing similarity feature matching between the comprehensive feature codes of target nodes and preset trie trees, and generating recommended target paths based on the structure tree of the successfully matched similar features when the comprehensive feature codes of target nodes are successfully matched with the preset trie trees.
[0137] Optionally, in some embodiments, after generating the target path, the positioning module 300 is further configured to: obtain user feedback information based on the target path; if the feedback information indicates that the path is available, then add the weight value of the target path to a preset trie; if the feedback information indicates that the path is unavailable, then add a new node to the preset trie.
[0138] Optionally, in some embodiments, the evaluation module 200 is further configured to: determine the attribute weight score, semantic value weight score, and structural value of the nodes of the document object model element; calculate the sum of the attribute weight score and the semantic value weight score of the nodes of the document object model element, and obtain the weight score of the nodes of the document object model element based on the product of the sum and the structural value.
[0139] Optionally, in some embodiments, the evaluation module 200 is further configured to: determine whether there is a first node in the document object model elements with a weight score greater than a first threshold; if there is a first node, determine whether the number of the first nodes is greater than or equal to a first preset value; if the number of the first nodes is greater than or equal to the first preset value, determine that the first node is a target node that meets the preset importance condition.
[0140] Optionally, in some embodiments, after determining whether the number of first nodes is greater than or equal to a first preset value, the evaluation module 200 is further configured to: if the number of first nodes is less than the first preset value and the number of first nodes is greater than or equal to a second preset value, then the second node among the first nodes that meets the preset quantity condition is taken as the target node.
[0141] Optionally, in some embodiments, the evaluation module 200 is further configured to: identify the current attribute of a node of a document object model element; if the current attribute is a unique identifier attribute, assign a first score as the attribute weight score of the node of the document object model element; if the current attribute is a business attribute, assign a second score as the attribute weight score of the node of the document object model element; if the current attribute is a role attribute, assign a third score as the attribute weight score of the node of the document object model element; if the current attribute is a class name attribute, assign a fourth score as the attribute weight score of the node of the document object model element, wherein the first score is greater than the second score, and the second score is greater than the third score.
[0142] Optionally, in some embodiments, the evaluation module 200 is further configured to: determine whether a node of a document object model element contains a target business keyword; if a node of a document object model element contains a target business keyword, then assign a fifth score as the semantic value weight score of the node of the document object model element; otherwise, determine whether a node of a document object model element satisfies a preset random generation feature; if a node of a document object model element satisfies a preset random generation feature, then assign a sixth score as the semantic value weight score of the node of the document object model element; otherwise, assign a seventh score as the semantic value weight score of the node of the document object model element, wherein the fifth score is greater than the sixth and seventh scores, and the sixth score is less than the seventh score.
[0143] Optionally, in some embodiments, the evaluation module 200 is further configured to: determine whether a node of a document object model element is a main content area node; if a node of a document object model element is a main content area node, then assign a first preset value to the structural value of the node of the document object model element; otherwise, determine whether a node of a document object model element is a footer node or a sidebar node, or determine whether a node of a document object model element is a transition container node, or determine whether a node of a document object model element is a business-carrying node; if a node of a document object model element is a footer node or a sidebar node, then assign a second preset value to the structural value of the node of the document object model element; if a node of a document object model element is a transition container node, then assign a third preset value to the structural value of the node of the document object model element; if a node of a document object model element is a business-carrying node, then assign a fourth preset value to the structural value of the node of the document object model element, wherein the first preset value is greater than the fourth preset value, the fourth preset value is greater than the second preset value, and the second preset value is greater than the third preset value.
[0144] Optionally, in some embodiments, the positioning module 300 is further configured to: extract the structural features, attribute features, and semantic features of the target node; and concatenate the structural features, attribute features, and semantic features of the target node to generate a comprehensive feature code of the target node.
[0145] Optionally, in some embodiments, the positioning module 300 is further configured to: sequentially pass the comprehensive feature code of the target node from the root node of the preset trie for matching; if there is a matching node in the target node whose comprehensive feature code matches the similarity feature of the preset trie with a degree greater than a second threshold, then determine that the comprehensive feature code of the target node matches the preset trie successfully; and return the recommended target path according to the weight value of the matching node.
[0146] Optionally, in some embodiments, if the comprehensive feature encoding of the target node fails to match the preset trie, the positioning module 300 is further configured to: return the target path generated based on the target node.
[0147] Optionally, in some embodiments, the path localization system 10 based on trie structure and weight learning described above further includes: an adjustment module, used to obtain the number of times at least one path is used in a preset trie, and adjust the weight value of at least one path according to the number of times at least one path is used.
[0148] Optionally, in some embodiments, the path localization system 10 based on the trie structure and weight learning described above further includes: a cleaning module, used to clean up nodes in a preset trie that have not been used for more than a preset time and whose corresponding weight values are less than a third threshold, based on a preset period.
[0149] It should be noted that the description of the features in the corresponding embodiments of the path localization system based on trie structure and weight learning can be found in the relevant descriptions of the corresponding embodiments of the path localization method based on trie structure and weight learning, which will not be repeated here.
[0150] Figure 5 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. The electronic device may include:
[0151] The memory 501, the processor 502, and the computer program stored on the memory 501 and capable of running on the processor 502.
[0152] When the processor 502 executes the program, it implements the path localization method based on trie structure and weight learning provided in the above embodiments.
[0153] Furthermore, electronic devices also include:
[0154] Communication interface 503 is used for communication between memory 501 and processor 502.
[0155] The memory 501 is used to store computer programs that can run on the processor 502.
[0156] Memory 501 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0157] If the memory 501, processor 502, and communication interface 503 are implemented independently, then the communication interface 503, memory 501, and processor 502 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0158] Optionally, in a specific implementation, if the memory 501, processor 502, and communication interface 503 are integrated on a single chip, then the memory 501, processor 502, and communication interface 503 can communicate with each other through an internal interface.
[0159] Processor 502 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.
[0160] Embodiments of the present invention also provide a non-volatile computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above embodiments of the path localization method based on trie structure and weight learning when it runs.
[0161] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.
[0162] This invention also provides a computer program product, including a computer program that, when executed by a processor, implements the aforementioned path localization method based on a trie structure and weight learning.
[0163] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0164] The foregoing has provided a detailed description of the path localization method, device, and medium based on trie structure and weight learning provided by this invention. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are only intended to help understand the method and core ideas of this invention. It should be noted that those skilled in the art can make various improvements and modifications to this invention without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this invention.
Claims
1. A path localization method based on trie structure and weight learning, characterized in that, Includes the following steps: Retrieve document object model elements; Evaluate the weight scores of the nodes of the document object model element, and determine the target nodes that meet the preset importance conditions based on the weight scores of the nodes of the document object model element. Extract the feature information of the target node to generate a comprehensive feature code, perform similar feature matching based on the comprehensive feature code of the target node and a preset trie, and generate a recommended target path based on the structure tree of the successfully matched similar features when the comprehensive feature code of the target node is successfully matched with the preset trie. The determination of target nodes that satisfy preset importance conditions based on the weight scores of nodes in the document object model includes: Determine whether there is a first node in the document object model elements whose weight score is greater than a first threshold; if the first node exists, determine whether the number of the first nodes is greater than or equal to a first preset value; if the number of the first nodes is greater than or equal to the first preset value, determine that the first node is a target node that meets the preset importance condition. After determining whether the number of the first node is greater than or equal to the first preset value, the process includes: if the number of the first node is less than the first preset value and the number of the first node is greater than or equal to the second preset value, then the second node among the first nodes that meets the preset quantity condition is taken as the target node.
2. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, After generating the target path, the following is included: Obtain user feedback information based on the target path; If the feedback information indicates that the path is available, then the weight value of the target path is added to the preset trie; if the feedback information indicates that the path is unavailable, then a new node is added to the preset trie.
3. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, Evaluating the weight scores of nodes of the document object model elements includes: Determine the attribute weight score, semantic value weight score, and structural value of the nodes of the document object model element; Calculate the sum of the attribute weight score and the semantic value weight score of the nodes of the document object model element, and obtain the weight score of the nodes of the document object model element based on the product of the sum and the structural value.
4. The path localization method based on trie structure and weight learning according to claim 3, characterized in that, Determine the attribute weight scores of nodes for Document Object Model elements, including: Identify the current attributes of the nodes of the document object model element; If the current attribute is a unique identifier attribute, then the first score is assigned as the attribute weight score of the node of the document object model element; if the current attribute is a business attribute, then the second score is assigned as the attribute weight score of the node of the document object model element; if the current attribute is a role attribute, then the third score is assigned as the attribute weight score of the node of the document object model element; if the current attribute is a class name attribute, then the fourth score is assigned as the attribute weight score of the node of the document object model element, wherein the first score is greater than the second score, and the second score is greater than the third score.
5. The path localization method based on trie structure and weight learning according to claim 3, characterized in that, Determine the semantic value weight scores of nodes in the Document Object Model (DOM) element, including: Determine whether the node of the document object model element contains the target business keyword; If the node of the document object model element contains the target business keyword, then the fifth score is assigned as the semantic value weight score of the node of the document object model element; otherwise, it is determined whether the node of the document object model element satisfies the preset random generation feature. If the nodes of the document object model element satisfy the preset random generation features, then the sixth score is assigned as the semantic value weight score of the nodes of the document object model element; otherwise, the seventh score is assigned as the semantic value weight score of the nodes of the document object model element. The fifth score is greater than the sixth score and the seventh score, and the sixth score is less than the seventh score.
6. The path localization method based on trie structure and weight learning according to claim 3, characterized in that, Determine the structural value of nodes in a Document Object Model element, including: Determine whether the node of the document object model element is a main content area node; If the node of the document object model element is a main content area node, then the first preset value is assigned to the structural value of the node of the document object model element; otherwise, it is determined whether the node of the document object model element is a footer node or a sidebar node, or whether the node of the document object model element is a transition container node, or whether the node of the document object model element is a business carrying node. If the node of the document object model element is a footer node or a sidebar node, then the second preset value is assigned to the structural value of the node of the document object model element. If the node of the document object model element is a transition container node, then the third preset value is assigned to the structural value of the node of the document object model element. If the node of the document object model element is a business carrier node, then the fourth preset value is assigned to the structural value of the node of the document object model element. Wherein, the first preset value is greater than the fourth preset value, the fourth preset value is greater than the second preset value, and the second preset value is greater than the third preset value.
7. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, The step of extracting the feature information of the target node to generate a comprehensive feature code includes: Extract the structural features, attribute features, and semantic features of the target node; The structural features, attribute features, and semantic features of the target node are concatenated to generate a comprehensive feature code for the target node.
8. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, The comprehensive feature encoding of the target node is compared with a preset trie for similarity feature matching. If the comprehensive feature encoding of the target node matches the preset trie successfully, a recommended target path is generated based on the structure tree of the successfully matched similar features, including: The comprehensive feature codes of the target nodes are sequentially passed from the root node of the preset trie for matching; If there is a matching node in the target node whose comprehensive feature code matches the preset trie with a similarity feature matching degree greater than the second threshold, then it is determined that the comprehensive feature code of the target node matches the preset trie successfully. The recommended target path is returned based on the weight value of the matched node.
9. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, If the comprehensive feature encoding of the target node fails to match the preset trie, the following applies: Return the target path generated based on the target node.
10. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, Also includes: Obtain the usage count of at least one path in the preset trie; The weight value of the at least one path is adjusted based on the number of times the at least one path is used.
11. The path localization method based on trie structure and weight learning according to claim 1, characterized in that, Also includes: Based on a preset period, clean up nodes in the preset trie that have not been used for a longer than a preset time and whose corresponding weight value is less than a third threshold.
12. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the path localization method based on a trie structure and weight learning as described in any one of claims 1-11.
13. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that, The program is executed by the processor to implement the path localization method based on trie structure and weight learning as described in any one of claims 1-11.
Citation Information
Patent Citations
Dictionary tree construction method, statement search method and device, equipment and storage medium
CN109740165A
RAG reordering method for tree structure document based on pruning optimization
CN119808714A