Web element intelligent positioning and operation method based on barrier-free tree
By using a deterministic algorithm based on barrier-free trees for web element location and manipulation, this method solves the problems of unreliable location, high cost, large latency, and insufficient self-healing ability in existing technologies. It achieves deterministic, low-cost, and fast web element manipulation, which is suitable for web automated testing and intelligent webpage operation.
Patent Information
- Application Number
- CN202611346169.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-01
- Publication Date
- 2026-11-20
AI Technical Summary
Existing web automation testing technologies suffer from unreliable element location, poor reproducibility, high cost, large latency, and a lack of automatic rewriting and self-healing capabilities for locators/operation code and verification mechanisms for operation results.
A deterministic algorithm based on accessibility trees is used for web element location and manipulation. By receiving operation requests, a semantic accessibility tree snapshot is obtained, a node tree is constructed, multiple semantic location strategies are applied, multiple candidate locators are generated, confidence is quantitatively evaluated and dynamically adjusted, an operation plan is generated, and anomaly self-healing and result verification are performed.
It achieves deterministic and reproducible positioning, reduces costs and latency, has self-healing code rewriting capabilities and a result verification mechanism based on state comparison, and is suitable for web automation testing and intelligent webpage operation.
Smart Images

Figure CN123138529A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated testing technology for web applications, and specifically to a method for intelligent location and manipulation of web elements based on an accessibility tree. Background Technology
[0002] In the field of web automation testing and intelligent webpage interaction, the mainstream element location and manipulation technologies currently fall into three main categories: Option 1: Hard-coded element location based on DOM selectors. Automated testing frameworks like Selenium involve testers manually inspecting the page's DOM using browser developer tools, then writing XPath paths or CSS selectors as element locators. Alternatively, a program can obtain the complete DOM tree and match target elements based on combinations of tag names, ids, classes, and attributes to generate locators, which are then executed in scripts for clicks, inputs, etc. This approach relies on DOM implementation details for location, resulting in fragile locators and high maintenance costs. It's important to note that while some modern testing frameworks (such as Playwright) provide semantic query primitives like `get_by_role` and `get_by_text` (which use an underlying accessibility tree), these primitives only provide the basic query methods. The role, accessible name, and query strategy must be manually specified and hard-coded by the developer. These primitives themselves do not provide automatic generation of multiple strategies, quantitative evaluation of locator confidence, or dynamic ranking. Furthermore, they lack automatic syntax rewriting and self-healing for locator / operation code after operation failures, and result verification based on snapshot comparisons before and after the operation. In other words, existing semantic query primitives only solve the problem of "how to query", while decision-making processes such as "what strategy to use to query, how to evaluate query quality, how to self-heal after failure, and how to verify whether the operation is effective" still rely entirely on manual intervention.
[0003] Option 2 is standardized positioning based on DOM semantic mapping. This approach preprocesses the front-end source code of the web application to build a "basic operation object table," pre-mapping page elements into objects with semantic character descriptions. When writing test cases, test objects are matched from the object table, and the basic operations are translated into program primitives to drive the browser, achieving layered decoupling between test objects and test logic. This relies on the preprocessing of the source code and the pre-maintenance of the object table, and the mapping still faces DOM objects, not deviating from DOM implementation details. The object table needs to be maintained synchronously with changes to the front-end.
[0004] Option 3: UI interaction and operation generation based on artificial intelligence / large language model (AI / LLM) decision-making. This type of option can be further divided into the following three representative forms: (3a) Multimodal large model exploration type: Collect interface screenshots, XML files describing the interface structure (including accessible trees), text descriptions and historical operation records, generate single-step exploration operation instructions after comprehensive analysis by the multimodal large model, and recursively traverse to build a visual map.
[0005] (3b) Accessibility Tree Snapshot + LLM Decision Type (such as open source projects Playwright MCP, browser-use, etc.): First, the browser accessibility tree snapshot interface is called to obtain the structured text of the page, which is then provided as input to the large language model. The large language model reads the snapshot text, understands its semantics, and decides which element to operate on. The output is then in the form of an element reference identifier (ref) or an action instruction, which is deterministically executed by the browser's underlying layer. Its characteristics are: the decision-making power is in the LLM, and the output is a ref-based tool call (such as browser_click{ref:e5}) or action instruction, rather than independently reusable locator code; the same input may produce different outputs due to the randomness of LLM inference, and it does not provide confidence scoring, multi-strategy generation, code syntax layer self-healing, or snapshot comparison verification before and after operation.
[0006] (3c) Test scripts generated directly from natural language: The large language model directly generates complete test scripts containing XPath / CSS selectors based on the natural language description.
[0007] The common feature of the above three forms is that the final decision-making power for element recognition and operation is given to the large language model, which is a probabilistic decision and requires reasoning based on the large language model.
[0008] The three existing solutions have the following drawbacks: Defect 1: Unreliable localization and poor reproducibility. Solution 3 completely entrusts element identification and operation decision-making to the large model's reasoning. Due to the influence of model illusion, the generated results are unstable and have a high error rate. Multiple executions of the same paragraph and the same keyword may produce different localization results, which are difficult to reproduce and cannot meet the deterministic requirements of automated testing.
[0009] Defect 2: High cost, large latency, and difficulty in verifying whether the operation is actually effective. Solution 3 requires calling a large model for inference every time it is located, which results in high computing power and calling costs, as well as large response latency; and after the model generates the operation, there is no verification mechanism to verify whether the operation is actually effective, which may lead to the misjudgment of "execution successful but not actually effective".
[0010] Defect 3: Fragile positioning; failure occurs with changes in interface structure. Solutions one and two, based on DOM selectors or DOM object mapping, heavily rely on the DOM hierarchy, IDs, classes, and other implementation details. Front-end framework upgrades, component library iterations, and UI redesigns can all cause widespread locator failure, resulting in high maintenance costs for test scripts. Solution two also requires preprocessing the source code and maintaining an object table, making it unsuitable for scenarios without source code.
[0011] Defect 4: Lack of automatic rewriting and self-healing of the locator / operation code itself, and no locator quality measurement. In existing solutions: Solutions 1 and 2 directly throw an error and terminate when locating fails; Solution 3 re-infers new instructions from a large model, which is a runtime-level re-decision, not an automatic syntax-level rewriting of existing locators or operation code (such as inserting a first-element qualifier into the locator, injecting forced operation parameters, or downgrading selection / checkmark operations to clicks); none of the existing solutions have established a quantifiable evaluation mechanism for locator quality (such as multi-strategy confidence). Therefore, existing technologies lack deterministic, automatic code rewriting and downgrade execution capabilities when facing specific anomalies such as multi-element conflicts, pointer occlusion, element read-only, and operation type mismatches.
[0012] To address this, we invented a method for intelligent positioning and manipulation of Web elements based on an accessibility tree, which solves the above-mentioned technical problems. Summary of the Invention
[0013] This invention provides a method for intelligent location and manipulation of Web elements based on an accessibility tree. The location is accurate, reproducible, and free of illusions. It is also low-cost and has low latency. It has deterministic code rewriting self-healing capabilities and a result verification mechanism based on state comparison.
[0014] Therefore, the present invention provides the following technical solution: A method for intelligent location and manipulation of web elements based on an accessibility tree, the method comprising: Step 1: Receive the operation request from the caller and call the browser's accessibility tree snapshot interface to obtain a semantic accessibility tree snapshot; Step 2: Parse the semantically accessible tree snapshot and construct a node tree with parent-child relationships; Step 3: Apply multiple semantic localization strategies to the target node to generate multiple candidate locators; Step 4: Quantitatively evaluate and dynamically adjust the generated candidate locators to obtain a candidate locator sequence; Step 5: For the candidate locator sequence, generate multiple operation plans and complete the execution of the operation plans and anomaly self-healing; Step 6: Use different verification methods based on the operation type to determine whether the operation plan is truly effective.
[0015] Optionally, in step 1, the operation request includes natural language keywords and operation verbs for the target element; the natural language keywords are the accessible name of the target element or words contained in the associated form tags of the target element; the operation verbs include click, input, select, check, decheck, clear, and upload; the semantic accessibility tree snapshot is represented by indented text and contains only semantic information; each node in the semantic accessibility tree snapshot contains: ARIA role, accessible name, and multiple state attributes.
[0016] Optionally, step 2 includes: First, lexical parsing is performed, the semantic accessibility tree snapshot is read line by line, and each line is parsed into a node object according to the preset grammar rules. The ARIA role, accessible name and status attributes of the node object are extracted. Secondly, a stack-based hierarchical matching is performed. Based on the indentation depth, a stack-based hierarchical matching algorithm is used to construct the parent-child relationship between nodes and form a complete node tree. Finally, name propagation and completion are performed. For list items or option nodes with missing accessible names but text in their child nodes, the text of the child nodes is propagated upwards to complete the accessible names, resulting in a structured semantic node tree with parent-child relationships.
[0017] Optionally, in step 3, for the target node to be located, based on the semantic features of the target node in the node tree, two or more semantic feature dimensions are selected from multiple semantic feature dimensions for combination, and a semantic positioning strategy is applied to generate at least two different candidate locators. The semantic feature dimensions include: ARIA roles and accessible names, semantic ancestor chains, state attributes, form tag associations, anchor nodes, and text. The code of the candidate locator is composed of semantic query primitives such as role query, name query, state query, ancestor chain query, text query, and tag association query.
[0018] Optionally, in step 4, when performing confidence quantification evaluation and dynamic adjustment on the generated candidate locators, firstly, an initial confidence level is assigned to each candidate locator generated by a strategy; then, the initial confidence level is dynamically adjusted based on two types of contextual information: the first type is whether the element is unique in the snapshot, and the second type is whether the element has associated labels. The specific adjustment rules are as follows: when there are associated labels and the element is not unique, the confidence level of the strategy that depends on the label is increased and the confidence level of the strategy that directly locates the target is a read-only input box that requires clicking the parent container, the confidence level of the candidate locator that clicks the parent container is increased; finally, all candidate locators are sorted from high to low according to the adjusted confidence level to obtain the candidate locator sequence.
[0019] Optionally, in step 5, the received operation verb is normalized by combining it with the ARIA role of the target node, and a corresponding operation code is generated for each candidate locator in the candidate locator sequence to form multiple operation schemes; when executing multiple operation schemes, they are tried in order of confidence from high to low.
[0020] Optionally, in step 5, upon completion of the execution of the operation plan and the anomaly self-healing, the specific steps include: First, before executing the operation plan, a pre-check is performed to verify whether the candidate locator can match the element. If the number of matches is zero, the operation plan is skipped. Secondly, execute the operation code in the operation plan; Finally, when a preset type of exception is captured, the operation code is automatically rewritten at the syntax level according to the repair strategy and then retried. The repair strategy includes: when a multi-element conflict exception is detected, a syntax parsing algorithm that supports nested parentheses and string escaping is used to insert the first element qualifier in the candidate locator; when a pointer occlusion or element read-only exception is detected, a forced operation parameter is injected into the operation; when a selection or checkbox operation fails, the selection or checkbox operation is downgraded to a click operation; for read-only input boxes, a clear operation is triggered first and then a forced click is performed.
[0021] Optionally, in step 6, the operation type is determined according to the operation verb and ARIA role. For input and clear operations, the current value of the input box is verified; for check and uncheck operations, the selected state is verified; for navigation click operations, it is considered successful by default; for button click and drop-down selection operations, it is determined by comparing whether the semantic accessibility tree snapshot before and after the operation has changed; if the verification is successful, the operation scheme is confirmed to be successful and the operation code of the operation scheme is output; if the verification fails or fails after self-healing, the next operation scheme is taken and retried until all operation schemes are exhausted and the failure and reason are returned.
[0022] A web element intelligent positioning and operating system based on an accessibility tree, the system comprising: The accessibility tree snapshot acquisition unit receives operation requests from the caller and calls the browser's accessibility tree snapshot interface to obtain a semantic accessibility tree snapshot; The node tree building unit parses the semantically accessible tree snapshot and constructs a node tree with parent-child relationships; The locator generation unit applies multiple semantic localization strategies to the target node to generate multiple candidate locators; The locator evaluation and adjustment unit performs confidence-quantitative evaluation and dynamic adjustment on the generated candidate locators to obtain a candidate locator sequence. The operation plan execution unit generates multiple operation plans for the candidate locator sequence and completes the execution of the operation plans and anomaly self-healing. The operation plan verification unit uses different verification methods based on the operation type to determine whether the operation plan is truly effective.
[0023] A computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to perform the steps of the method for intelligent location and manipulation of Web elements based on an accessibility tree.
[0024] This invention provides a method for intelligent location and manipulation of web elements based on an accessibility tree. It involves a method that automatically completes web page element location, operation execution, and automated test code generation using a deterministic algorithm (rather than large language model inference) based on browser accessibility tree (ARIA) snapshots. The deterministic algorithm makes all decisions, outputting independently reusable locator code that is reproducible and requires no large language model intervention. It includes confidence weighting, syntax-level self-healing, and snapshot comparison verification. The overall method comprises nine steps: request reception, snapshot acquisition, node tree construction, multi-strategy location, confidence ranking, execution and self-healing, result verification, and code output / failure return, forming a closed loop. The locator of this invention is based on page semantic information rather than DOM implementation details, making it resistant to front-end structural changes and highly stable. By replacing large model inference with a deterministic algorithm (multi-strategy + confidence quantification), location is definite, reproducible, and free of illusions, with low cost and low latency. It has automatic recovery and degraded execution capabilities after location failure; it provides an operation result verification mechanism based on state comparison; and it can complete location and operation using only natural language keywords, without the need for source code preprocessing. This invention can be applied to web application scenarios such as web automated testing, intelligent webpage operation assistants, and browser automation via semantic interface calls by artificial intelligence agents. Compared with existing technologies, this invention has the following technical advantages: Firstly, the location is definite, reproducible, and free of illusions, with low cost and low latency. Solution 3 (including Playwright MCP / browser-use and other 3b forms) completely entrusts element recognition and operation decision-making to large language model reasoning. This is susceptible to model illusions, resulting in unstable results, inconsistent executions, and each location requires calling a large model, leading to high computational and call costs and long response latency. Its output is a ref-based tool call or action command, which becomes invalid after page changes and cannot be reused independently of the MCP service. This invention uses a deterministic multi-strategy generation and confidence quantification algorithm to complete element recognition. The same input will inevitably produce the same result, ensuring definite, reproducible, and illusion-free location, meeting the deterministic requirements of automated testing. Furthermore, the output is independently reusable semantic locator code (such as get_by_role), which can run directly in any Playwright environment without needing to be used by the system itself. Simultaneously, all operations are completed by a local deterministic algorithm, eliminating the need to call a large model, resulting in low cost and low latency, making it suitable for large-scale batch execution.
[0025] Secondly, it possesses deterministic code rewriting self-healing capabilities and a result verification mechanism based on state comparison. Solution 3 can only rely on the large model to re-infer when the operation fails. It lacks both automatic rewriting of the syntax layer of the locator / operation code itself (such as inserting the first element qualifier in the locator, injecting forced operation parameters, downgrading the selection / checking operation to a click, etc.) and verification of whether the operation is actually effective. The anomaly self-healing mechanism of this invention can automatically rewrite the code and retry under common anomalies such as multi-element conflict, occlusion, read-only, and operation type mismatch. It also uses differentiated verification based on the operation type (verifying the input value / selection state, or comparing the barrier-free tree snapshot before and after the operation) to determine whether the operation is effective, avoiding the misjudgment of "execution successful but not actually effective". Attached Figure Description
[0026] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly described below. Obviously, the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without creative effort.
[0027] Figure 1 This is a flowchart of a specific embodiment of the intelligent positioning and manipulation method for Web elements based on an accessibility tree according to the present invention; Figure 2 This is a schematic diagram of the multi-strategy locator generation in a specific embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a web element intelligent positioning and operating system based on an accessibility tree in a specific embodiment of the present invention. Detailed Implementation
[0028] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0029] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. 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 skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0030] like Figure 1 As shown, Figure 1 This is a flowchart of a method for intelligent location and manipulation of web elements based on an accessibility tree according to a specific embodiment of the present invention. The method includes: S101, Operation request received.
[0031] The system receives an operation request from a caller (AI agent or automated script). This request contains at least natural language keywords for the target element and operation verbs. The keywords are the accessible name of the target element or words contained in its associated form tags. The operation verbs include, but are not limited to, clicking, inputting, selecting, checking, dechecking, clearing, and uploading. This step allows subsequent location services to be driven solely by natural language, eliminating the need for the caller to provide any selectors.
[0032] S102, Semantic Accessibility Tree Snapshot Acquisition.
[0033] Instead of parsing the complete DOM, the browser's accessibility tree snapshot API is invoked to obtain an accessibility tree snapshot represented as indented text, containing only semantic information. Each node in the snapshot contains at least: an ARIA role, an accessible name, and several state attributes (such as disabled, checked, expanded, and cursor). Compared to the complete DOM, the snapshot data is smaller, less noisy, and strips away the implementation details of the front-end framework, retaining only semantic information meaningful for element identification.
[0034] S103, Snapshot Text Parsing and Node Tree Construction.
[0035] Lexical and syntactic analysis is performed on the indented text snapshot, specifically including: (3.1) Lexical analysis: Read line by line, and parse each line into a node object according to the preset grammar rules (indentation + list mark + role + name + attribute block + colon text), and extract its role, name and status attributes; (3.2) Stack-based hierarchical matching: Based on the indentation depth, a stack-based hierarchical matching algorithm is used (elements with indentation greater than or equal to the current node are popped from the stack before the current node is pushed onto the stack) to construct the parent-child relationship between nodes and form a complete node tree; (3.3) Name propagation completion: For list item / option type nodes where the accessible name is missing but the child nodes have text, perform "child node text propagation upwards" to complete the accessible name with the text of the child nodes. This results in a structured semantic node tree with parent-child relationships.
[0036] S104, Multi-strategy semantic locator generation.
[0037] For the target node to be located, based on its semantic features in the node tree, two or more semantic feature dimensions are automatically selected and combined to generate at least two different semantic locator codes. These semantic feature dimensions include, but are not limited to: role and accessible name, semantic ancestor chain, state attribute, form tag association, anchor node, and text. The locator code is composed of semantic query primitives such as role query, name query, state query, ancestor chain query, text query, and tag association query, rather than hard-coded DOM paths. Figure 2 As shown, six specific strategies are used as examples (this does not constitute a closed constraint on the set of feature dimensions): Strategy A: Direct Locator by Role Name: When a node has an accessible name, generate a locator by "role + name"; Strategy B Semantic Ancestor Hierarchical Location: Extract semantically related ancestor nodes (such as navigation areas, form areas, and dialog boxes) along the path from node to root, and generate a hierarchical locator "via semantic ancestor → target element"; Strategy C: State-aware localization: When a node has state attributes such as checked / expanded / disabled, the state is added as a query condition to the locator. Strategy D: Form Label Association Positioning: When a node is a form input element and its neighboring area (sibling, uncle-nephew, and deeply nested structures) contains form label text, an association locator is generated that "traverses up through the label text → input element"; when the target is a read-only input box, an association locator is generated that clicking its clickable parent container is enabled. Strategy E Parent / Sibling Anchor Point Location: When the target node itself has no name but its ancestor or sibling node has an accessible name, the target element is located using the named node as the anchor point. Strategy F: Text-based fallback positioning. For links, unlabeled input boxes, etc., text query or label query is used as a fallback.
[0038] S105, Confidence Quantification Assessment and Dynamic Adjustment.
[0039] Each locator generated by a strategy is assigned an initial confidence level (example initial values for each strategy: Strategy A: Direct locating by role name 0.95, Strategy B: Semantic ancestor layering 0.90, Strategy C: State awareness 0.92, Strategy D: Form tag association 0.85, Strategy E: Anchor point locating 0.88~0.82, Strategy F: Text fallback 0.70). The initial confidence level is then dynamically adjusted based on two types of contextual information: the first is whether the element is unique in the snapshot, and the second is whether the element has associated tags. Specifically, the adjustment rules are as follows: when associated tags exist and the element is not unique, the confidence level of the strategy dependent on tags (Strategy D) is increased, and the confidence level of the direct locating strategy (Strategy A) is decreased; when the target is a read-only input box that requires clicking the parent container, the confidence level of the locator that clicks the parent container is increased accordingly. Finally, all candidate locators are sorted from high to low according to the adjusted confidence level to obtain an ordered candidate locator sequence. The confidence level is a quantifiable locator quality metric used to guide subsequent selection and degradation.
[0040] S106, Operation plan generation, execution, and anomaly self-healing.
[0041] Combining the received operation verbs with the role of the target node, the operation verbs are normalized (if no verb is specified, the default action is taken based on the role, such as input for a text box, click for a button, and checkbox for a checkbox), and corresponding operation codes are generated for each locator in the candidate locator sequence, forming multiple operation schemes. During execution, the schemes are tried sequentially from highest to lowest confidence, specifically including: (6.1) Pre-check before execution: First check whether the locator can match the element. If the number of matches is zero, skip the scheme. (6.2) Execute the operation code; (6.3) Exception Self-Healing: When a preset type of exception is captured, the system queries the correspondence between preset exception characteristics and repair strategies, automatically rewrites the operation code at the syntax level, and then retryes. The repair strategies include at least three types: when a multi-element conflict (strict mode violation) exception is detected, a syntax parsing algorithm supporting nested parentheses and string escaping is used to insert the first element qualifier (.first) in the locator; when a pointer occlusion or element read-only exception is detected, a forced operation parameter (force) is injected into the operation; when a selection / checkbox operation fails, it is downgraded to a click operation; for read-only input boxes, the clear operation is triggered first, and then a forced click is performed. After successful rewriting, the system retryes and writes the rewritten steps back to the solution step sequence to ensure the integrity of the final output code. After successful rewriting and retry, the process proceeds to step S107; if the rewriting and retry fails, the next operation solution is executed.
[0042] S107, Verification of operational result differences.
[0043] Different verification methods are used depending on the type of operation to determine whether the operation has actually taken effect: For input / clear operations, verify the current value of the input box; for check / uncheck operations, verify the selected state; for navigation click operations (menu items, tabs, links, tree items), due to potential delays caused by changes, they are considered successful by default; for button clicks, drop-down selections, etc., the determination is made by comparing whether the accessibility tree snapshots before and after the operation have changed. If the verification passes, proceed to step S108; if the verification fails, proceed to step S109.
[0044] S108, when the verification is successful, the candidate solution is confirmed to be successful, and all operation codes corresponding to the solution (including pre-execution checks, operation execution, exception self-healing rewriting, option clicking, etc.) are output, and the process ends normally.
[0045] If verification fails or self-healing fails after step S109, the next candidate solution is selected for retry, and the process returns to step S104. This continues until all solutions are exhausted, at which point a failure and its reason are returned. When all candidate solutions fail verification or self-healing fails, a failure result and its reason (such as the number of matched elements and the reason for failure of each solution) are returned for the caller to process.
[0046] The present invention provides a method for intelligent location and manipulation of Web elements based on an accessibility tree. It adopts an open definition of "feature dimension + at least two combinations", which makes the set of location strategies scalable and avoids the circumvention of closed enumeration. It also adopts a dynamic confidence adjustment mechanism: based on the context such as element uniqueness and tag relevance, the confidence of each strategy is dynamically adjusted and sorted accordingly, thereby providing a quantifiable quality assessment and selection basis for Web element locators. The self-healing mechanism for automatic code rewriting based on the pre-defined correspondence between "abnormal features → repair strategies" in this invention is not innovative in its specific repair techniques (such as inserting .first, injecting force, or operation degradation, which are common practices of existing APIs in query frameworks), but rather in its pre-defined correspondence between abnormal features and repair strategies (e.g., detecting a multi-element conflict exception → inserting a first element qualifier in the locator; detecting a pointer occlusion or element read-only exception → injecting a forced operation parameter; detecting a selection / checkmark operation failure → downgrading to a click operation). The rewriting method is an "in-place rewriting" of existing locators / operation code after syntax tree parsing (e.g., inserting a qualifier in the method chain corresponding to the first balanced bracket), requiring no manual intervention, no regeneration of the locator, and no re-triggering of model inference. This is fundamentally different from existing technologies that "retry by calling an API after catching an exception" or "regenerate new instructions from a large model." This mechanism helps improve the robustness of automated processes on dynamic web pages. The differential result verification mechanism of this invention, based on the comparison of barrier-free tree snapshots before and after the operation, can determine whether the operation is truly effective based on state comparison, avoiding the misjudgment of "execution successful but not actually effective"; it can complete the entire process of positioning, execution, verification and code generation end-to-end with only natural language keywords as input, without the need for source code preprocessing, thus lowering the threshold for use.
[0047] In a specific embodiment of the present invention, taking "entering text in the brand input box and clicking the query button" as an example, the specific steps include: Step S101: Receive request {keyword = "brand owner", verb = "input", value = "test brand"}; Step S102, obtain a snapshot containing the generic node " Brand: "and its adjacent textbox node" Please enter the brand; Step S103: Construct a node tree based on indentation and propagate the completed names; Step S104: Generate multiple locators such as strategy A and strategy D for the textbox node; In step S105, since the element is not unique and has a label, the confidence of strategy D is increased from 0.85 to 0.93 (constrained by the upper limit of 0.93) and ranked first. Step S106: Execute sequentially, locate successfully and execute input; Step S107: Verify that the input box value equals "Test Brand" and output the code. Similarly, the query button is clicked by directly locating the role name (Strategy A), and the change in the snapshot before and after is used for verification.
[0048] In one embodiment, the exception self-healing implementation includes: when a click operation throws a multi-element conflict exception, the present invention parses the locator code syntax tree, inserts the .first qualifier in the method chain corresponding to the first balanced bracket, and then retryes; when the select_option operation fails, it is automatically rewritten to .click() for retry.
[0049] Examples of the rewritten code for the three types of repair strategies are as follows: Repair ① (Multi-element conflict): The original code `page.get_by_role(“menuitem”, name="Resource Management”).click(timeout=3000)` throws a `strictmode violation` exception. It is rewritten as `page.get_by_role(“menuitem”, name="Resource Management”).first.click(timeout=3000)`, which then retryes. Repair ② (Pointer occlusion / read-only): The original code `page.get_by_role(“button”, name="Query”).click(timeout=3000)` throws an `intercepts pointer events` exception. It is rewritten as `page.get_by_role(“button”, name="Query”).click(timeout=3000,force=True)`. Retry; if the element is a read-only input box, first perform a hover and trigger its clear button (click .el-icon-circle-close after hover), then click with force=True; Fix ③ (selection / checking failure): After the original code page.get_by_role(“combobox”).select_option(“video”) fails to execute, it is rewritten as page.get_by_role(“combobox”).click() to trigger the native click behavior and then retry.
[0050] The algorithm steps for parsing balanced bracket syntax include (corresponding to the fix in ① "inserting qualifiers in the method chain corresponding to the first balanced bracket"): Step 1, locate the first occurrence of "page." in the operation code string; Step 2, scan character by character starting from the first left bracket "(" after it; Step 3, maintain two states during the scan: one is whether it is within a string literal (entering the string state when encountering a single quote or double quote, and exiting when encountering the same type of quote and the preceding character is not an escape character), and the other is the bracket depth count (counting only outside the string: incrementing by one when encountering a left bracket and decrementing by one when encountering a right bracket); Step 4, when the depth count reaches zero, the current right bracket ")" is the closing bracket paired with the first left bracket, and the part before this closing bracket is the complete target method call; Step 5, check if the closing bracket is immediately followed by a dot method chain (such as .click()), and the method chain does not contain the qualifier .first or .nth, then insert ".first" after the closing bracket and before the subsequent method chain to generate the rewritten code. If the balanced parentheses cannot be located or the qualifier is already present, abandon the rewrite and treat it as a failure.
[0051] In one embodiment, the confidence level dynamic adjustment lookup table is as follows: For elements that are unique, have labels, and are not read-only: Strategy A (direct positioning) maintains a confidence level of 0.95; Strategy D (label association) has a confidence level of 0.85. Since the elements are unique, no weighting is required, and the ranking is A>D.
[0052] For elements that are not unique, have labels, and are not read-only: Strategy D increases the weight to 0.93 (+0.08, subject to the upper limit of 0.93), while strategy A decreases the weight to 0.65 (-0.30), resulting in a sorting order of D > A.
[0053] For elements that are not unique, have labels, and are read-only input boxes: the click variant of the read-only parent container in strategy D is weighted up to 0.99 (+0.50, capped at 0.99), making it the highest priority.
[0054] Elements without labels and not unique: Each strategy maintains its initial confidence level. Strategy A is reduced to 0.65 due to its non-uniqueness, while ancestor chain / anchor strategies (0.88~0.90) lead the pack.
[0055] Keyword matches tag (user search term is tag keyword): At this point, a variant of strategy D is dynamically injected (denoted as fuzzy_label, the difference being that the search keyword is used instead of the complete tag text, and the generated locator is shorter), with a confidence of 0.99 at the top.
[0056] Accordingly, embodiments of the present invention also provide a web element intelligent positioning and operating system based on an accessibility tree, such as... Figure 3The image shown is a structural diagram of the system. This intelligent web element location and manipulation system based on an accessibility tree includes the following modules: Accessibility tree snapshot acquisition unit 301 receives an operation request from the caller and calls the browser's accessibility tree snapshot interface to obtain a semantic accessibility tree snapshot; Node tree building unit 302 parses the semantically accessible tree snapshot and constructs a node tree with parent-child relationships; The locator generation unit 303 applies multiple semantic localization strategies to the target node to generate multiple candidate locators. The locator evaluation and adjustment unit 304 performs confidence-quantitative evaluation and dynamic adjustment on the generated candidate locators to obtain a candidate locator sequence. The operation plan execution unit 305 generates multiple operation plans for the candidate locator sequence and completes the execution of the operation plans and anomaly self-healing. The operation plan verification unit 306 uses different verification methods based on the operation type to determine whether the operation plan is truly effective.
[0057] A typical application of this invention is the MCP (Model Context Protocol) service, which encapsulates the method into several semantic tool interfaces (such as click, input, selection, checkmark, clear, upload, etc.), and a large language model proxy drives the browser to complete web operations through these interfaces. This form embodies the design goal of this invention: "AI-friendly and keyword-driven".
[0058] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.
[0059] The present invention also provides a storage medium, which is a computer-readable storage medium storing a computer program thereon, the computer program being executable when it runs. Figure 1 The method shown may include some or all of the steps. The storage medium may include read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc. The storage medium may also include non-volatile memory or non-transitory memory, etc.
[0060] The above embodiments can be implemented, in whole or in part, by software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer program are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data provider to another website, computer, server, or data provider via wired or wireless means.
[0061] The embodiments of the present invention have been described in detail above. Specific implementation methods have been used to illustrate the present invention. The descriptions of the embodiments above are only for the purpose of helping to understand the methods and systems of the present invention, and are merely some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention, and the content of this specification should not be construed as a limitation of the present invention. Therefore, any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for intelligent positioning and manipulation of Web elements based on an accessibility tree, characterized in that, The method includes: Step 1: Receive the operation request from the caller and call the browser's accessibility tree snapshot interface to obtain a semantic accessibility tree snapshot; Step 2: Parse the semantically accessible tree snapshot and construct a node tree with parent-child relationships; Step 3: Apply multiple semantic localization strategies to the target node to generate multiple candidate locators; Step 4: Quantitatively evaluate and dynamically adjust the generated candidate locators to obtain a candidate locator sequence; Step 5: For the candidate locator sequence, generate multiple operation plans and complete the execution of the operation plans and anomaly self-healing; Step 6: Use different verification methods based on the operation type to determine whether the operation plan is truly effective.
2. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 1, characterized in that, In step 1, the operation request includes natural language keywords and operation verbs for the target element; the natural language keywords are the accessible name of the target element or words contained in the associated form tags of the target element; the operation verbs include click, input, select, check, decheck, clear, and upload; the semantic accessibility tree snapshot is represented by indented text and contains only semantic information; each node in the semantic accessibility tree snapshot contains: ARIA role, accessible name, and multiple state attributes.
3. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 2, characterized in that, Step 2 includes: First, lexical parsing is performed, the semantic accessibility tree snapshot is read line by line, and each line is parsed into a node object according to the preset grammar rules. The ARIA role, accessible name and status attributes of the node object are extracted. Secondly, a stack-based hierarchical matching is performed. Based on the indentation depth, a stack-based hierarchical matching algorithm is used to construct the parent-child relationship between nodes and form a complete node tree. Finally, name propagation and completion are performed. For list items or option nodes with missing accessible names but text in their child nodes, the text of the child nodes is propagated upwards to complete the accessible names, resulting in a structured semantic node tree with parent-child relationships.
4. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 2, characterized in that, In step 3, for the target node to be located, based on the semantic features of the target node in the node tree, two or more semantic feature dimensions are selected from multiple semantic feature dimensions and combined to generate at least two different candidate locators by applying a semantic positioning strategy. The semantic feature dimensions include: ARIA roles and accessible names, semantic ancestor chains, state attributes, form tag associations, anchor nodes, and text. The code of the candidate locator is composed of semantic query primitives such as role query, name query, state query, ancestor chain query, text query, and tag association query.
5. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 4, characterized in that, In step 4, when evaluating and dynamically adjusting the confidence of the generated candidate locators, firstly, an initial confidence level is assigned to each candidate locator generated by each strategy; then, the initial confidence level is dynamically adjusted based on two types of contextual information: the first type is whether the element is unique in the snapshot, and the second type is whether the element has associated tags. The specific adjustment rules are as follows: when there are associated tags and the element is not unique, the confidence level of the strategy that depends on the tags is increased and the confidence level of the strategy that directly locates the target is a read-only input box that requires clicking the parent container, the confidence level of the candidate locator that clicks the parent container is increased; finally, all candidate locators are sorted from high to low according to the adjusted confidence level to obtain the candidate locator sequence.
6. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 5, characterized in that, In step 5, the received operation verbs are combined with the ARIA role of the target node, the operation verbs are normalized, and corresponding operation codes are generated for each candidate locator in the candidate locator sequence, thus forming multiple operation schemes. When executing multiple operation plans, try them in order of confidence from highest to lowest.
7. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 6, characterized in that, Step 5, upon completion of the operation plan execution and anomaly self-healing, specifically includes: First, before executing the operation plan, a pre-check is performed to verify whether the candidate locator can match the element. If the number of matches is zero, the operation plan is skipped. Secondly, execute the operation code in the operation plan; Finally, when a preset type of exception is captured, the operation code is automatically rewritten at the syntax level according to the repair strategy and then retried. The repair strategy includes: when a multi-element conflict exception is detected, a syntax parsing algorithm that supports nested parentheses and string escaping is used to insert the first element qualifier in the candidate locator; when a pointer occlusion or element read-only exception is detected, a forced operation parameter is injected into the operation; when a selection or checkbox operation fails, the selection or checkbox operation is downgraded to a click operation; for read-only input boxes, a clear operation is triggered first and then a forced click is performed.
8. The method for intelligent positioning and manipulation of Web elements based on an accessibility tree according to claim 7, characterized in that, In step 6, the operation type is determined according to the operation verb and ARIA role. For input and clear operations, the current value of the input box is verified; for check and uncheck operations, the selected state is verified. For navigation clicks, the operation is considered successful by default; For button clicks and dropdown selections, the determination is made by comparing whether the semantic accessibility tree snapshots before and after the operation have changed; If the verification passes, the operation plan is confirmed as successful and the operation code of the operation plan is output; if the verification fails or the self-healing process fails, the next operation plan is used for retrying until all operation plans are exhausted, and then the failure and reason are returned.
9. A web element intelligent positioning and operating system based on an accessibility tree, characterized in that, The system includes: The accessibility tree snapshot acquisition unit receives operation requests from the caller and calls the browser's accessibility tree snapshot interface to obtain a semantic accessibility tree snapshot; The node tree building unit parses the semantically accessible tree snapshot and constructs a node tree with parent-child relationships; The locator generation unit applies multiple semantic localization strategies to the target node to generate multiple candidate locators; The locator evaluation and adjustment unit performs confidence-quantitative evaluation and dynamic adjustment on the generated candidate locators to obtain a candidate locator sequence. The operation plan execution unit generates multiple operation plans for the candidate locator sequence and completes the execution of the operation plans and anomaly self-healing. The operation plan verification unit uses different verification methods based on the operation type to determine whether the operation plan is truly effective.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is run by the processor, it executes the steps of the method for intelligent positioning and operation of Web elements based on an accessibility tree, as described in any one of claims 1 to 8.
