XPath path generation method and device and electronic equipment
By generating multiple optional XPath paths based on the combination of target element attributes, the problems of cumbersome writing of XPath paths and difficulty in maintaining absolute paths are solved, and efficient and accurate XPath path generation and automated testing are achieved.
Patent Information
- Application Number
- CN202411990151.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-06
AI Technical Summary
In web page automation testing, traditional manual XPath writing paths are cumbersome and inefficient, and the absolute paths are too long and difficult to maintain, making it difficult to adapt to the changing UI structure and testing needs.
By obtaining the combination of element attributes at the level where the target element is located in the tree diagram of XML data, multiple optional XPath paths are generated, and the relative paths are locating the target elements uniquely, avoiding the verboseness of the absolute path and maintenance difficulties.
It significantly improves the generation efficiency and accuracy of XPath paths, enhances compatibility and universality, ensures that the paths are still effective when XML data structure changes, and improves the stability and maintainability of automated testing.
Smart Images

Figure CN119940295A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an XPath path generation method, device and electronic device. Background Art
[0002] In the process of web page automation testing, accurately locating the elements in the page is one of the core tasks. As a path language specifically used for XML documents, the Extensible Markup Language (XPath) path can locate the target element by describing the hierarchical structure, attributes or relative position of the element.
[0003] Therefore, in order to improve the efficiency and accuracy of automated testing, it is necessary to provide an XPath path generation solution that can be automatically generated, flexible and has good compatibility. Summary of the invention
[0004] The embodiment of the present application provides an XPath path generation method to improve the efficiency and accuracy of automated testing.
[0005] Correspondingly, the embodiments of the present application also provide an XPath path generation device, an electronic device and a storage medium to ensure the implementation and application of the above method.
[0006] In order to solve the above problems, an embodiment of the present application discloses an XPath path generation method, the method comprising: Obtain the first element attribute combination of the target element at the level in the tree diagram of the extensible markup language XML data; Generate an optional Extensible Markup Language path XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to the second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element having a preset node relationship with the target element in the tree diagram; According to the optional XPath path, a query is performed in the XML data to obtain a query result, and the query result is the XPath path of the target element as the target path.
[0007] The embodiment of the present application also discloses an XPath path generation device, the device comprising: An acquisition module, used for acquiring the first element attribute combination of the target element at the level in the tree diagram of the XML data; A first processing module, configured to generate an optional XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to a second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element having a preset node relationship with the target element in the tree diagram; The second processing module is used to query the XML data according to the optional XPath path to obtain a query result, and use the query result as the XPath path of the target element as the target path.
[0008] An embodiment of the present application also discloses an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, one or more of the methods described in the embodiments of the present application are implemented.
[0009] The embodiments of the present application further disclose a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, one or more methods described in the embodiments of the present application are implemented.
[0010] The embodiments of the present application also disclose a computer program product, including a computer program, which, when executed by a processor, implements one or more of the methods described in the embodiments of the present application.
[0011] The beneficial effects of the technical solution provided by the embodiment of the present application are: In the embodiment of the present application, an optional XPath path is generated by combining the element attributes of the target element, which avoids the tediousness and inefficiency of the traditional manual writing of the XPath path, and also avoids the problem of the absolute path being too long and difficult to maintain. Specifically, multiple optional paths are generated by combining the element attributes of the level of the target element in the tree diagram of the extensible markup language XML data, and / or the element attribute combination of the associated element having a preset node relationship with the target element, and verifying the relative XPath path that can be used to uniquely locate the target element, which significantly improves the generation efficiency and accuracy of the XPath path and enhances compatibility and universality. The XPath path generation method provided in the embodiment of the present application, when the XML data structure changes, the path can still remain valid, because the target path generated by the embodiment of the present application depends on the element attribute combination of the target element, rather than the global structure of the entire XML tree, and the absolute path generated by the prior art usually starts from the root node of the XML document, describing the complete path from the root node to the target element. Since the entire path depends on the global structure of the XML data, any change in a node (such as adding, deleting or reordering nodes) may cause the absolute path to fail. Compared with the prior art, the embodiments of the present application avoid the lengthiness and maintenance difficulty of absolute paths by generating flexible relative XPath paths, improve the generation efficiency, accuracy and compatibility of XPath paths, and significantly enhance the stability and maintainability of automated testing.
[0012] Additional aspects and advantages of the embodiments of the present application will be partially given in the description below, which will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which: Figure 1 A flowchart of the XPath path generation method provided in an embodiment of the present application; Figure 2 A schematic diagram of a first example provided for an embodiment of the present application; Figure 3 A flowchart of a second example provided for an embodiment of the present application; Figure 4 A schematic diagram of the structure of an XPath path generation device provided in an embodiment of the present application; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0014] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0015] Those skilled in the art will appreciate that, unless specifically stated, the singular forms "one", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used here may include wireless connection or wireless coupling. The term "multiple" refers to two or more than two. In view of this, "multiple" may also be understood as "at least two" in the embodiments of the present application. The term "and / or" describes the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / ", unless otherwise specified, generally indicates that the associated objects before and after are in an "or" relationship.
[0016] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0017] The embodiment of the present application provides an XPath path generation method. Optionally, the embodiment of the present application can be applied to various electronic devices, such as mobile terminal devices such as smart phones, tablet computers, car terminals, TV set-top boxes, as well as desktop computers, smart home devices, etc. The embodiment of the present application is introduced with electronic devices as the execution subject. However, this does not constitute a limitation on the embodiment of the present application. Specifically, the present application realizes the precise positioning and automated testing of target elements in the user interface (UI) through XPath technology. Among them, the target element itself may not have a globally unique positioning attribute. Therefore, the embodiment of the present application provides an XPath path generation method, which automatically generates an XPath path for locating a unique target element in an XML document through certain rules, avoiding the tediousness of manually writing an XPath path, and improving the development efficiency and maintainability of the test script. The solution of the embodiment of the present application has strong flexibility and compatibility, and can effectively support the UI testing requirements of multiple devices and different versions.
[0018] like Figure 1 As shown in , the method may include the following steps: Step 101: Obtain the first element attribute combination of the level where the target element is located in the tree diagram of the extensible markup language XML data.
[0019] In the field of web page automation testing, locating elements in a page is one of the core tasks. In order to efficiently and accurately identify and operate different UI elements in a page, XPath technology is usually used. XPath paths can accurately locate specific elements by specifying the structure and hierarchical relationship of XML documents. In web page automation testing, the test script needs to generate an XPath path based on the Hyper Text Markup Language (HTML) or XML structure of the page in order to obtain and operate the target element.
[0020] In the UI test framework of smart mobile operating systems based on the graphical user interface (GUI), the basic elements in the UI interface are usually the interface component types and their subclasses defined by the system. In order to facilitate automated testing, the system organizes the object information of all interface components and outputs them in XML format for identification and calling by test scripts. At this time, the test framework needs to rely on XPath technology to accurately locate specific interface component element nodes in the XML document. Therefore, how to efficiently and accurately generate XPath paths to adapt to the changing UI structure and testing requirements is a technical problem that needs to be solved urgently.
[0021] In the embodiment of the present application, by parsing XML data, the level of the target element to be located is determined, and the attribute combination of the first element of the level is extracted. Wherein, the target element refers to a specific node that needs to be located, identified and operated in the XML document. The target element can be any XML node, and it usually represents an interface component, button, text box, etc. in the UI interface. For example, in an XML document describing the structure of a web page, the target element may be a node of a button, or a node of an input box. The attributes of the target element usually contain various information about the element. Optionally, the attributes of the target element include but are not limited to class name, object name, text, index. Wherein, the XML tree diagram is a hierarchical representation of XML data, which organizes all elements in the XML document in the form of a tree. Each element can be regarded as a node in the tree, and these nodes are connected together through a parent-child relationship to form a tree structure. In this structure, each element has a parent element and possible multiple child elements, and the root node of the tree is usually the top element of the XML document. The hierarchical structure of the XML tree diagram determines the relative position of the elements. Wherein, the level refers to the depth of the target element in the XML tree diagram. Each node in an XML document has a level, and the levels increase downwards layer by layer starting from the root node. For example, the root node has a level of 1, and its direct child element has a level of 2, and the child element levels further down increase in sequence. The purpose of obtaining the level of the target element is to help determine its exact position in the document. Among them, the element attribute combination refers to a combination of multiple attributes of the target element. These attributes may include the class name, object name, text, index, etc. of the element, which are used to identify the characteristics of the element. The element attribute combination in the embodiment of the present application can help locate the target element as the basis for generating the XPath path.
[0022] In the embodiment of the present application, an optional XPath path is generated by combining the element attributes of the target element, which avoids the tediousness and inefficiency of traditional manual XPath path writing, and also avoids the problem of absolute path being too long and difficult to maintain. Specifically, multiple optional paths are generated by combining the element attributes of the level where the target element is located in the tree diagram of the extensible markup language XML data, and / or the element attribute combination of the associated element that has a preset node relationship with the target element, and verifying the relative XPath path that can be used to uniquely locate the target element, which significantly improves the generation efficiency and accuracy of the XPath path and enhances compatibility and universality.
[0023] Step 102: Generate an optional Extensible Markup Language Path XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to the second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element in the tree diagram that has a preset node relationship with the target element.
[0024] In the embodiment of the present application, an XPath path is generated by the first element attribute combination, and the path is used to uniquely identify the position of the target element. Optionally, if the first element attribute combination is not enough to accurately locate the target element, another XPath path can be generated according to the second element attribute combination. The second element attribute combination refers to the attribute combination of the associated elements that have a preset node relationship with the target element in the XML tree diagram, and the attributes of these associated elements can be used to further optimize or confirm the generation of the XPath path. It can be seen that the XPath path generation method provided by the embodiment of the present application, when the XML data structure changes, the path can still remain valid, because the target path generated by the embodiment of the present application depends on the element attribute combination of the target element, rather than the global structure of the entire XML tree, and the absolute path generated by the prior art usually starts from the root node of the XML document, describing the complete path from the root node to the target element. Since the entire path depends on the global structure of the XML data, any change in a node (such as adding, deleting or reordering nodes) may cause the absolute path to fail. Compared with the prior art, the embodiments of the present application avoid the lengthiness and maintenance difficulty of absolute paths by generating flexible relative XPath paths, improve the generation efficiency, accuracy and compatibility of XPath paths, and significantly enhance the stability and maintainability of automated testing.
[0025] Step 103: perform a query in the XML data according to the optional XPath path to obtain a query result, and use the query result as the XPath path of the target element as the target path.
[0026] In the embodiment of the present application, query operations are performed in XML data according to the optional XPath paths to verify the validity of these paths. Specifically, the generated optional XPath paths are used to query the XML data to find nodes that match the target element. If the query result correctly returns the target element node, then the XPath path is confirmed to be valid as the valid path (target path) of the target element. This process ensures that the generated XPath path is not only theoretically feasible, but also can correctly locate the target element in the actual XML data, thereby providing an accurate positioning basis for subsequent test operations.
[0027] Figure 2 is a schematic diagram of a first example of an XPath path generation method according to an embodiment of the present disclosure. Figure 2 As shown, the embodiment of the present disclosure relates to an XPath path generation method, which includes: Step 201: Obtain the first element attribute combination of the level where the target element is located in the tree diagram of the extensible markup language XML data.
[0028] In the embodiment of the present application, by parsing XML data, the level of the target element to be located is determined, and the attribute combination of the first element of the level is extracted. Among them, the attribute combination of the first element includes but is not limited to at least one of the following Object name: The object name refers to the name by which an element is identified in the system. For some elements, it is unique and will not change during the entire software life cycle. When using the object name for positioning, it can ensure high accuracy, but because there may be multiple elements with the same name on some interfaces, the repetition rate is high, so it needs to be used in combination with other attributes to reduce the possibility of conflict.
[0029] Object name and class name; the class name is the type identifier of the element. Usually, each element has a corresponding class name, and the class name will basically not change during the software life cycle. Combining the object name and class name can help further improve the accuracy of positioning. Although the class name has a high repetition rate in elements of the same type, it can effectively reduce repetition and improve the uniqueness of the path after combining with the object name.
[0030] Object name, class name and text; when an element has object name, class name and text attributes at the same time, the combination of these three attributes can significantly improve the accuracy of positioning. The text attribute is usually the content directly displayed to the user on the UI interface, which can help quickly identify elements, especially for elements with clear text such as buttons, labels, and input boxes. When these three are used in combination, the repetition rate is low and it has strong uniqueness, which can accurately locate the target element.
[0031] Text; the text attribute refers to the text information directly displayed to the user in the UI interface. Text can usually directly reflect the function or meaning of an element, so when an element has a text attribute, positioning by text often improves the readability of the script. However, the disadvantage of the text attribute is that it may change during the operation of the software, and if the text is too long (more than 20 characters), it may not be suitable as a positioning basis. Therefore, the text attribute is very effective in specific scenarios, but it is also necessary to consider whether it is applicable in combination with the actual situation.
[0032] Text and class name; when an element has both text and class name attributes, the combination of the two can further reduce the possibility of positioning conflicts, especially when there are many similar elements in the interface, the combination of text and class name can more accurately determine the target element. However, compared with the use of text alone, the introduction of class name can enhance the stability of the path, because the class name usually does not change, while the text may change with different language versions or UI adjustments.
[0033] Class name and index; Class name. As an identifier of the element type, the class name usually does not change. However, in some cases, there may be multiple elements with the same class name at the same level. In this case, the index attribute can be used as a supplementary means to distinguish these elements with the same class name. The index is not an attribute of the element itself, but a serial number automatically assigned when multiple elements have the same class name in the XML structure. The combination of class name and index can solve the problem of locating multiple elements with the same class name and ensure the uniqueness of the XPath path.
[0034] Step 202: Generate the first XPath path in sequence according to the preset priority corresponding to each combination of the first element attributes.
[0035] In the embodiment of the present application, the first XPath path of the target element is generated in sequence according to the preset priority corresponding to each first element attribute combination. In this process, the operation focus is first placed on the target element node to be located, and then the single-layer XPath path is attempted to be generated one by one according to the preset priority order. Among them, the preset priorities corresponding to the first element attribute combination are shown in Table 1 below, which are: object name, object name + class name, object name + class name + text, text, text + class name, class name + index, class name.
[0036] Table 1:
[0037] It should be noted that the object name has the highest priority because it is usually a unique and stable identifier; the second is the combination of the object name and the class name. The use of these two attributes together can further improve accuracy; the text attribute can help quickly locate elements, especially when the text is clearly displayed in the UI interface; when the element has a text attribute, locating directly based on the text usually improves readability, but it may also be affected by changes in the interface during the software operation; combining text and class names helps improve the stability of positioning, especially when there are multiple text-like elements in the UI; the combination of class name and index is used to handle repeated class name elements in the hierarchy, distinguishing them by index, and finally using the class name alone for positioning, which has a high repetition rate, but is still effective in some cases. By prioritizing the attribute combination, it is ensured that the test framework can quickly find the most accurate and stable path among multiple possible XPath paths. By gradually trying high-priority attribute combinations, the probability of positioning failure can be effectively reduced, and the accuracy and efficiency of element positioning in automated testing can be improved.
[0038] Step 203: perform a query in the XML data according to each of the first XPath paths, and determine whether the query result includes the target element.
[0039] In the embodiment of the present application, the XPath path of the level where the target element is located is sequentially obtained according to the priority corresponding to the above attribute combination. Each single-layer XPath path generated will be matched with the current focus element to verify its validity. By verifying whether each generated XPath path can successfully locate the target element, the validity and accuracy of the generated XPath path are ensured, thereby improving the stability and reliability of element positioning in automated testing.
[0040] Step 204: If the query result includes the target element, the XPath path of the target element in the query result is used as the target path.
[0041] In the embodiment of the present application, if a certain XPath path can accurately locate a unique target element in the XML data, the XPath path is returned. By confirming whether the query result contains the target element, it is ensured that only valid and accurate XPath paths are selected as the target path, thereby improving the accuracy and efficiency of automated testing.
[0042] In some embodiments, after obtaining the target path, the method further includes: When the number of levels of the target path is greater than a preset threshold, and the levels corresponding to the first and last nodes in the target path are different and not adjacent, the intermediate nodes except the first and last nodes in the target path are replaced with the first symbol in sequence, and it is verified whether the XPath path after each replacement is valid; If, according to the replaced XPath path, the element determined in the XML data includes the target element, the first symbol is retained and the next intermediate node is replaced; if, according to the replaced XPath path, the element determined in the XML data does not include the target element, the replacement is canceled and the next intermediate node is processed until the intermediate nodes in the target element are traversed to obtain the optimized target path.
[0043] In the embodiment of the present application, after obtaining the target path, the method is further optimized. Specifically, if the number of levels of the target path obtained is greater than the preset threshold, and the levels corresponding to the first and last nodes in the path are different and non-adjacent, then the framework will replace the intermediate nodes in the target path except the first and last nodes with the first symbol (such as the wildcard "*") in sequence, and verify whether the replaced XPath path is still valid. If the target element can be found in the XML data according to the replaced XPath path, then this replacement is retained and the next intermediate node is replaced; if the replaced path is invalid, the replacement is canceled and the next intermediate node is processed until all intermediate nodes are traversed, and finally an optimized target path is obtained. This process can optimize the generated XPath path, reduce the lengthy path part, and use wildcards to replace intermediate nodes to improve the flexibility and maintainability of the path, while ensuring that the path is still valid. Through this method, the complexity of the XPath path can be effectively reduced, and the performance of the automated testing framework can be improved, especially when facing a complex or dynamically changing UI interface, the reliability and adaptability of the test script are enhanced.
[0044] Step 205: If the query result does not include the target element, retain the XPath string corresponding to the element attribute combination with the highest priority in the first element attribute combination.
[0045] In an embodiment of the present application, when the query result fails to include the target element, the XPath string corresponding to the element attribute combination with the highest priority is retained. Specifically, when a certain XPath path cannot effectively locate the target element, the test framework will first save the single-layer XPath string with the highest priority corresponding to the path, and splice the string into a temporary XPath path. Then, the framework will generate a new XPath rule based on the attribute combination of the next priority, and continue to splice it into the temporary XPath path for further validity verification. If the newly generated XPath path is valid, the path is returned; if it is invalid, the framework will continue to generate and verify the XPath path according to the above method until an XPath path that can accurately locate the target element is found. The embodiment of the present application ensures that when positioning fails, the test framework can efficiently try different XPath paths according to different attribute combinations of the target element until a valid target path is finally found, thereby enhancing the flexibility and reliability of positioning.
[0046] Step 206, obtain a second element attribute combination of an associated element that has a preset node relationship with the target element; the associated element includes at least one of the following: a parent node element of the target element in the tree diagram; other elements at the same level as the target element in the tree diagram and belonging to the same parent node element; an upper node element of the target element in the tree diagram.
[0047] In the embodiment of the present application, when the XPath paths corresponding to all attribute combinations of the level where the target element is located are all invalid after traversing in step 205, the second element attribute combination of the associated element having a preset node relationship with the target element is obtained. Specifically, in this case, the framework will consider the associated elements having a specific node relationship with the target element, and these elements usually include the following types: the parent node element of the target element, other elements at the same level as the target element but belonging to the same parent node, or the superior node element of the target element. According to these associated elements, the test framework will extract the second element attribute combination for further generating a new XPath path to better locate the target element. By introducing the associated elements having a specific relationship with the target element, the embodiment of the present application can provide a new positioning basis through the relative relationship with the target element when the original XPath path is invalid, thereby increasing the success rate of path generation and improving the adaptability and robustness of the test framework in complex or dynamic UI structures.
[0048] Step 207: Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination and / or the XPath character string.
[0049] In some embodiments, the generating of the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination and / or the XPath string includes at least one of the following: Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the parent node element and / or the XPath string; Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the other elements and / or the XPath string; Obtain the third element attribute combination of each of the parent node elements, and generate an optional XPath path of the target element according to the third element attribute combination; wherein the optional XPath path includes at least one of the following items: generating a third XPath path according to the third element attribute combination of the level where the parent node element is located, and generating a fourth XPath path according to the fourth element attribute combination of the parent node element; wherein the fourth element attribute combination includes an element attribute combination of an associated element in the tree diagram that has a preset node relationship with the parent node element.
[0050] In the embodiment of the present application, first, according to each second element attribute combination of the parent node element and its priority, combined with the retained XPath string, the second XPath path is generated in sequence. If the XPath path generated by all attribute combinations of the parent node element is still invalid, then the new XPath path will continue to be generated according to the attribute combination and priority of other elements at the same level as the target element. If the target element cannot be located at this time, the parent node element will be further considered. It will obtain the third element attribute combination of the parent node and generate optional XPath paths in sequence. These optional paths include the XPath path generated according to the third element attribute combination of the level where the parent node element is located, or the XPath path generated according to the fourth element attribute combination of the parent node. The fourth element attribute combination contains the attribute combination of the associated element with the preset node relationship with the parent node. In this process, the test framework will generate the XPath path of each level in the order of priority and verify its validity one by one. If the path is valid, it will return immediately, and if it is invalid, it will continue to generate the path according to the next level. By traversing the parent node, other elements at the same level and the parent node element layer by layer, combined with the preset attribute combination priority, it is ensured that a valid XPath path can be accurately generated in a complex XML structure. This gradual fallback strategy improves the flexibility and stability of target element positioning, ensuring that the test framework can still find the target element efficiently and accurately in a changing UI structure.
[0051] Step 208: perform a search in the XML data according to each of the second XPath paths; and use the XPath path of the target element as the search result as the target path.
[0052] In the embodiment of the present application, according to each generated second XPath path, a query is performed in the XML data to verify whether these paths can successfully locate the target element. Specifically, the framework will query each second XPath path in turn. If the query result can accurately locate the target element, the path is selected as the XPath path of the target element and returned as the final target path. By verifying whether each generated second XPath path can accurately locate the target element, the validity and accuracy of the finally selected XPath path are ensured, thereby improving the reliability of element positioning in automated testing and enhancing the adaptability of the test framework in complex or dynamically changing UI interfaces.
[0053] In some embodiments, after obtaining the target path, the method further includes: When the number of levels of the target path is greater than a preset threshold, and the levels corresponding to the first and last nodes in the target path are different and not adjacent, the intermediate nodes except the first and last nodes in the target path are replaced with the first symbol in sequence, and it is verified whether the XPath path after each replacement is valid; If, according to the replaced XPath path, the element determined in the XML data includes the target element, the first symbol is retained and the next intermediate node is replaced; if, according to the replaced XPath path, the element determined in the XML data does not include the target element, the replacement is canceled and the next intermediate node is processed until the intermediate nodes in the target element are traversed to obtain the optimized target path.
[0054] In the embodiment of the present application, after obtaining the target path, the method is further optimized. Specifically, if the number of levels of the target path obtained is greater than the preset threshold, and the levels corresponding to the first and last nodes in the path are different and non-adjacent, then the framework will replace the intermediate nodes in the target path except the first and last nodes with the first symbol (such as the wildcard "*") in sequence, and verify whether the replaced XPath path is still valid. If the target element can be found in the XML data according to the replaced XPath path, then this replacement is retained and the next intermediate node is replaced; if the replaced path is invalid, the replacement is canceled and the next intermediate node is processed until all intermediate nodes are traversed, and finally an optimized target path is obtained. This process can optimize the generated XPath path, reduce the lengthy path part, and use wildcards to replace intermediate nodes to improve the flexibility and maintainability of the path, while ensuring that the path is still valid. Through this method, the complexity of the XPath path can be effectively reduced, and the performance of the automated testing framework can be improved, especially when facing a complex or dynamically changing UI interface, the reliability and adaptability of the test script are enhanced.
[0055] Figure 3 is a schematic diagram of a second example of an XPath path generation method according to an embodiment of the present disclosure. Figure 3 As shown, the embodiment of the present disclosure relates to an XPath path generation method, which includes: Step 301: define a temporary XPath string variable.
[0056] In the embodiment of the present application, the UI layer of the mobile operating system is mainly implemented based on the Qt / qml related solution, so the corresponding UI automation test framework is also developed based on this, in which the most basic elements that can be identified in the UI interface are the QQuickItem type and its subclasses in Qt. The test framework needs to organize all the object information of the QQuickItem type in XML text format and then package and output it for the test script to identify and call. Here, the test script needs to use XPath to accurately locate the specific QQuickItem object information node in the XML text. And this XPath generally has two sources, one is to write it by itself based on the experience of the script developer, the advantage is that the accuracy, flexibility and compatibility will be better, and the disadvantage is that it will seriously reduce the efficiency of script development; the other is to automatically generate according to certain rules, such as selecting one of several attributes of the XML node to generate a relative path or simply using an absolute path directly. The disadvantage of the absolute path is that the XPath string itself is too long, not easy to read and maintain, and the compatibility is poor. Any change in the entire path will cause the XPath to fail, and the relative path generated using a certain node attribute lacks universality, and not all XML nodes have attributes that can be accurately located. The XPath path generation method provided in the embodiment of the present application can solve the problems of low efficiency, long path and version compatibility caused by only being able to manually write a suitable XPath or use automatically generated absolute path XPath when writing system UI automated test scripts.
[0057] In an embodiment of the present application, a temporary XPath string variable is defined to store each generated XPath path. During the XPath path generation process, the temporary variable will gradually accumulate node information and eventually form a complete XPath path. For example, if you need to locate a certain UI element, you can first define an empty temporary variable: XPath = "", which is used for the subsequent splicing of the generated XPath path. The definition of a temporary XPath string variable in an embodiment of the present application makes the subsequent XPath path generation and splicing process orderly and efficient, providing a basis for the operation of subsequent steps.
[0058] Step 302, determining the focus element.
[0059] In the embodiment of the present application, the "focus element" to be currently located is determined. The focus element is the target element to be operated or located in the XML tree diagram.
[0060] Step 303: Generate an XPath path of the level where the focus element is located.
[0061] In the embodiment of the present application, based on the focus element, the XPath path of the level where it is located is generated. In this step, according to the attribute combination and preset priority of the focus element, XPath rules are generated one by one and spliced into a temporary XPath string variable. For example, assuming that the focus element is a button, its XML node attribute is <button id="submitBtn" class="btn"> Submit< / button> , you can generate an XPath path based on the attribute combination, such as XPath = " / / button[@id='submitBtn']". By generating the XPath path of the level where the focus element is located, you can directly help locate the element and ensure the smooth progress of subsequent verification steps.
[0062] Step 304 , determining whether the XPath path is valid; if the XPath path is valid, executing step 311 ; if the XPath path is invalid, executing step 305 .
[0063] Specifically, determine whether the XPath path generated in the previous step is valid. A valid XPath path should be able to accurately locate the target element. If the path is valid, continue to execute the subsequent steps; otherwise, go to step 305. For example, the generated XPath path is / / button[@id='submitBtn'], and a query is performed in the XML data. If the target button can be correctly located, the path is valid; if the button cannot be located, the path is invalid.
[0064] Step 305: Save the XPath string corresponding to the element attribute combination with the highest priority.
[0065] In the embodiment of the present application, if the generated XPath path is invalid, the XPath string corresponding to the highest priority attribute combination of the current focus element is saved for backup, so as to continue to generate other possible valid XPath paths. For example, assuming that the XPath path corresponding to the first priority attribute combination is invalid, the currently generated XPath rule (such as / / button[@id='submitBtn']) can be saved, and then the next priority XPath rule generation can be continued.
[0066] Step 306: Generate an XPath path of the level where the parent node of the focus element is located.
[0067] In an embodiment of the present application, if no valid XPath path can be obtained after traversing the XPath paths corresponding to all attribute combinations of the level where the target element is located, then the XPath path of the level where the parent node of the focus element is located is generated. XPath paths are generated level by level through the parent node of the focus element to increase the possibility of positioning. Among them, XPath paths are generated level by level through the parent node of the focus element, and the principle of attribute combination priority is also followed. Optionally, a connector ' / ' is used to splice to the front of the focus XPath, and ' / / ' is added to the front of the spliced string and then the whole is spliced to the front of the temporary XPath string variable to form a complete XPath.
[0068] Step 307 , determining whether the XPath path is valid; if the XPath path is valid, executing step 311 ; if the XPath path is invalid, executing step 308 .
[0069] In the embodiment of the present application, if the verification is valid, a relative path is generated, otherwise execution continues downward.
[0070] Step 308: Save the XPath string corresponding to the element attribute combination with the highest priority.
[0071] In the embodiment of the present application, when the XPath paths generated level by level through the parent node of the focus element are all invalid, the XPath string corresponding to the element attribute combination with the highest priority is still saved, which is the same as step 305.
[0072] Step 309: Generate an XPath path of the same-layer node of the focus element.
[0073] In the embodiment of the present application, each node of the same level and different class as the focus is traversed, and its single-layer XPath is obtained one by one (the attribute combination used must contain at least one of the two attributes of object name or text, and follow the same priority). Use the connector ' / .. / ' to splice to the front of the focus XPath, add ' / / ' to the front of the spliced string, and then splice the whole to the front of the temporary XPath string variable to form a complete XPath.
[0074] Step 310, determining whether the XPath path is valid, if the XPath path is valid, executing step 311, if the XPath path is invalid, executing step 312.
[0075] In the embodiment of the present application, it is verified whether each XPath path generated in step 309 is valid. If it is valid, the relative path is output; otherwise, step 312 is executed.
[0076] Step 311: Generate a relative XPath path.
[0077] Step 312, save the XPath string corresponding to the element attribute combination with the highest priority, and execute step 302 to re-determine the focus element.
[0078] In the embodiment of the present application, if in step 310, it is verified that all XPath paths generated in step 309 are invalid, the front part of the single-layer XPath with focus is spliced with the ' / ' connector, and then the whole is spliced to the front part of the temporary XPath string variable, and then the focus is moved up to the parent node to repeat steps 302 to 310 until the XPath verification passes or the focus is moved to the root node to form an absolute path XPath.
[0079] In some embodiments, after obtaining the target path, the method further includes: When the number of levels of the target path is greater than a preset threshold, and the levels corresponding to the first and last nodes in the target path are different and not adjacent, the intermediate nodes except the first and last nodes in the target path are replaced with the first symbol in sequence, and it is verified whether the XPath path after each replacement is valid; If, according to the replaced XPath path, the element determined in the XML data includes the target element, the first symbol is retained and the next intermediate node is replaced; if, according to the replaced XPath path, the element determined in the XML data does not include the target element, the replacement is canceled and the next intermediate node is processed until the intermediate nodes in the target element are traversed to obtain the optimized target path.
[0080] In the embodiment of the present application, after obtaining the target path, the method is further optimized. Specifically, if the number of levels of the target path obtained is greater than the preset threshold, and the levels corresponding to the first and last nodes in the path are different and non-adjacent, then the framework will replace the intermediate nodes in the target path except the first and last nodes with the first symbol (such as the wildcard "*") in sequence, and verify whether the replaced XPath path is still valid. If the target element can be found in the XML data according to the replaced XPath path, then this replacement is retained and the next intermediate node is replaced; if the replaced path is invalid, the replacement is canceled and the next intermediate node is processed until all intermediate nodes are traversed, and finally an optimized target path is obtained. This process can optimize the generated XPath path, reduce the lengthy path part, and use wildcards to replace intermediate nodes to improve the flexibility and maintainability of the path, while ensuring that the path is still valid. Through this method, the complexity of the XPath path can be effectively reduced, and the performance of the automated testing framework can be improved, especially when facing a complex or dynamically changing UI interface, the reliability and adaptability of the test script are enhanced.
[0081] Assume the HTML structure is as follows: Main Content Footer Content Another Content Assume the target element is: Main Content . First, define a temporary XPath string variable to store the XPath path generated below. For example: XPath = "". However, starting from the target element, generate XPath one by one according to the priority of the element attribute combination of the level where the target element is located. For example: Priority 1: Generate XPath using the id attribute; first try to locate the target element based on the id attribute: / / div[@id='main']; then concatenate it to the temporary XPath variable to obtain: XPath = " / / div[@id='main']"; then verify the validity, assuming that this XPath is invalid, because there are multiple identical div elements with id="main" on the page, and the target element cannot be uniquely located, then save it for later use and continue to the next priority. For example, Priority 2: Generate XPath using the id + class attribute combination: / / div[@id='main' and @class='content'], concatenate it to the temporary XPath variable to obtain XPath= " / / div[@id='main' and @class='content']"; then verify its validity; assuming that this XPath is valid, it uniquely locates the target element Main Content , the current validation passes and the XPath path is returned: / / div[@id='main' and @class='content'], otherwise it continues to execute priority 3, priority 4, etc. Assuming that after traversing all the XPath paths generated by the attribute combinations of the target element's level, no XPath path that passes the validation can be obtained, then the single-layer XPath of the target element's parent node is obtained; the parent node of the target element is . Parent node XPath: / / div[@id='container'], concatenate it to a temporary XPath variable: XPath = " / / div[@id='container'] / div[@id='main' and @class='content']"; then verify whether the XPath is valid: Assume that the XPath is valid and uniquely locates the target element Main Content . If the verification succeeds, the XPath path is returned: / / div[@id='container'] / div[@id='main' and @class='content']; if the verification fails, the XPath path generated by the attribute combination corresponding to the next level priority of the parent node is verified. This method is consistent with the XPath rule method for verifying the level of the target element, and will not be repeated here. If the target element is still not effectively located through the XPath of the parent node, or the path needs to be further optimized, other nodes at the same level of the target element will be traversed. These nodes are the same as the parent nodes of the target element, and the information of these nodes is used to assist in locating the target element. For example, nodes at the same level as the target element: Footer Content Another Content Then traverse the sibling nodes , generate the XPath for the sibling node: / / div[@id='footer'], and then concatenate it to the temporary XPath variable to get: XPath = " / / div[@id='container'] / div[@id='footer'] / .. / div[@id='main'and @class='content']"; However, verify the XPath: Assuming that the XPath is invalid, continue to traverse the XPath paths corresponding to other attribute combinations of the sibling node. If they are all invalid, traverse the next sibling node. If no valid XPath path can be obtained after traversing each sibling node, the parent node of the target element is used as the target element and the above process is executed; if the parent node of the target element is used as the target element and the above process is executed, a valid XPath path still cannot be obtained, the parent node of the parent node is used as the target element and the above process is executed until the XPath verification passes or the focus moves to the root node to form an absolute path XPath. Among them, the absolute path is: / html / body / div[@id='container'] / div[@id='main' and @class='content'].
[0082] Based on the same principle as the method provided in the embodiment of the present application, the embodiment of the present application also provides an XPath path generation device, such as Figure 4 As shown, the device comprises: Acquisition module 1, used to acquire the first element attribute combination of the target element in the tree diagram of XML data and the level at which it is located; A first processing module 2 is configured to generate an optional XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to a second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element having a preset node relationship with the target element in the tree diagram; The second processing module 3 is used to query the XML data according to the optional XPath path to obtain a query result, and use the query result as the XPath path of the target element as the target path.
[0083] In some embodiments, the first processing module is specifically used to: Generate the first XPath path in sequence according to the preset priority corresponding to each combination of the first element attributes; Accordingly, the second processing module is specifically used for: According to each of the first XPath paths, a query is performed in the XML data; if the query result includes the target element, the XPath path of the target element whose query result is the target element is used as the target path; if the query result does not include the target element, the XPath string corresponding to the element attribute combination with the highest priority in the first element attribute combination is retained.
[0084] In some embodiments, the first processing module is specifically used to: Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination and / or the XPath string; Accordingly, the second processing module is specifically used for: According to each of the second XPath paths, a query is performed in the XML data; if the query result includes the target element, the query result is the XPath path of the target element as the target path.
[0085] In some embodiments, the associated element having a preset node relationship with the target element includes at least one of the following: The parent node element of the target element in the tree diagram; Other elements at the same level as the target element in the tree diagram and belonging to the same parent node element; The parent node element of the target element in the tree diagram.
[0086] In some embodiments, the first processing module is specifically used to: generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the parent node element and / or the XPath string; Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the other elements and / or the XPath string; Obtain the third element attribute combination of each of the parent node elements, and generate an optional XPath path of the target element according to the third element attribute combination; wherein the optional XPath path includes at least one of the following items: generating a third XPath path according to the third element attribute combination of the level where the parent node element is located, and generating a fourth XPath path according to the fourth element attribute combination of the parent node element; wherein the fourth element attribute combination includes an element attribute combination of an associated element in the tree diagram that has a preset node relationship with the parent node element.
[0087] In some embodiments, the second processing module is further specifically configured to: When the number of levels of the target path is greater than a preset threshold, and the levels corresponding to the first and last nodes in the target path are different and not adjacent, the intermediate nodes except the first and last nodes in the target path are replaced with the first symbol in sequence, and it is verified whether the XPath path after each replacement is valid; If, according to the replaced XPath path, the element determined in the XML data includes the target element, the first symbol is retained and the next intermediate node is replaced; if, according to the replaced XPath path, the element determined in the XML data does not include the target element, the replacement is canceled and the next intermediate node is processed until the intermediate nodes in the target element are traversed to obtain the optimized target path.
[0088] In some embodiments, the element attribute combination includes at least one of the following: Object name; Object name and class name; Object name, class name, and text; text; Text and class names; Class name and index; Class name.
[0089] The XPath path generation device provided in the embodiment of the present application can achieve Figures 1 to 3 To avoid repetition, the various processes implemented in the method embodiment are not described here.
[0090] The XPath path generation device provided by the present application generates an optional XPath path through the element attribute combination of the target element, avoiding the tediousness and inefficiency of the traditional manual writing of the XPath path, and also avoiding the problem of the absolute path being too long and difficult to maintain. Specifically, through the element attribute combination of the level where the target element is located in the tree diagram of the extensible markup language XML data, and / or the element attribute combination of the associated element having a preset node relationship with the target element, multiple optional paths are generated, and the relative XPath path that can be used to uniquely locate the target element is verified, which significantly improves the generation efficiency and accuracy of the XPath path, and enhances compatibility and universality. The XPath path generation method provided by the embodiment of the present application, when the XML data structure changes, the path can still remain valid, because the target path generated by the embodiment of the present application depends on the element attribute combination of the target element, rather than the global structure of the entire XML tree, and the absolute path generated by the prior art usually starts from the root node of the XML document, describing the complete path from the root node to the target element. Since the entire path depends on the global structure of the XML data, any change in a node (such as adding, deleting or reordering nodes) may cause the absolute path to fail. Compared with the prior art, the embodiments of the present application avoid the lengthiness and maintenance difficulty of absolute paths by generating flexible relative XPath paths, improve the generation efficiency, accuracy and compatibility of XPath paths, and significantly enhance the stability and maintainability of automated testing.
[0091] The XPath path generation device of the embodiment of the present application can execute the XPath path generation method provided in the embodiment of the present application, and its implementation principle is similar. The actions performed by each module and unit in the XPath path generation device in each embodiment of the present application correspond to the steps in the XPath path generation method in each embodiment of the present application. For the detailed functional description of each module of the XPath path generation device, please refer to the description in the corresponding XPath path generation method shown in the previous text, which will not be repeated here.
[0092] Based on the same principle as the method shown in the embodiment of the present application, the embodiment of the present application also provides an electronic device, which may include but is not limited to: a processor and a memory; a memory for storing a computer program; a processor for executing the XPath path generation method shown in any optional embodiment of the present application by calling a computer program. Compared with the prior art, the XPath path generation method provided by the present application generates an optional XPath path through the element attribute combination of the target element, avoiding the cumbersomeness and inefficiency of the traditional manual writing of the XPath path, and also avoiding the problem of the absolute path being too long and difficult to maintain. Specifically, through the element attribute combination of the level where the target element is located in the tree diagram of the extensible markup language XML data, and / or the element attribute combination of the associated element having a preset node relationship with the target element, multiple optional paths are generated, and the relative XPath path that can be used to uniquely locate the target element is verified, which significantly improves the generation efficiency and accuracy of the XPath path, and enhances compatibility and universality.
[0093] In an optional embodiment, an electronic device is also provided, such as Figure 5 As shown, Figure 5 The electronic device 5000 shown includes: a processor 5001 and a memory 5003. The processor 5001 and the memory 5003 are connected, such as through a bus 5002. Optionally, the electronic device 5000 may also include a transceiver 5004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 5004 is not limited to one, and the structure of the electronic device 5000 does not constitute a limitation on the embodiments of the present application.
[0094] Processor 5001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. It may implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the disclosure of this application. Processor 5001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
[0095] The bus 5002 may include a path to transmit information between the above components. The bus 5002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 5002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0096] The memory 5003 may be a ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, a RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, Blu-ray disk, etc.), magnetic disk storage medium, other magnetic storage devices, or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation herein.
[0097] The memory 5003 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 5001. The processor 5001 is used to execute the computer program stored in the memory 5003 to implement the steps shown in the above method embodiment.
[0098] Among them, electronic devices include but are not limited to: mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0099] An embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps and corresponding contents of the aforementioned method embodiment can be implemented.
[0100] The embodiment of the present application also provides a computer program product, including a computer program, which can implement the steps and corresponding contents of the aforementioned method embodiment when executed by a processor.
[0101] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.
[0102] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.
[0103] The above is only an optional implementation method for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the solution of the present application, other similar implementation methods based on the technical ideas of the present application are also within the protection scope of the embodiments of the present application.
Claims
1. An XPath path generation method, characterized in that: include: Obtain the first element attribute combination of the target element at the level in the tree diagram of the extensible markup language XML data; Generate an optional Extensible Markup Language path XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to the second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element having a preset node relationship with the target element in the tree diagram; According to the optional XPath path, a query is performed in the XML data to obtain a query result, and the query result is the XPath path of the target element as the target path.
2. The XPath path generation method according to claim 1, characterized in that: The step of generating an optional XPath path of the target element according to the first element attribute combination includes: Generate the first XPath path in sequence according to the preset priority corresponding to each combination of the first element attributes; Accordingly, searching in the XML data according to the optional XPath path includes: According to each of the first XPath paths, a query is performed in the XML data; if the query result includes the target element, the XPath path of the target element whose query result is the target element is used as the target path; if the query result does not include the target element, the XPath string corresponding to the element attribute combination with the highest priority in the first element attribute combination is retained.
3. The XPath path generation method according to claim 2, characterized in that: In the case that the query result does not include the target element, generating an optional XPath path of the target element according to the first element attribute combination includes: Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination and / or the XPath string; Accordingly, searching in the XML data according to the optional XPath path includes: According to each of the second XPath paths, a query is performed in the XML data; if the query result includes the target element, the query result is the XPath path of the target element as the target path.
4. The XPath path generation method according to any one of claims 1 to 3, characterized in that: The associated element having a preset node relationship with the target element includes at least one of the following: The parent node element of the target element in the tree diagram; Other elements at the same level as the target element in the tree diagram and belonging to the same parent node element; The parent node element of the target element in the tree diagram.
5. The XPath path generation method according to claim 4, characterized in that: The generating the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination and / or the XPath string includes at least one of the following: Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the parent node element and / or the XPath string; Generate the second XPath path in sequence according to the preset priority corresponding to each second element attribute combination of the other elements and / or the XPath string; Obtain the third element attribute combination of each of the parent node elements, and generate an optional XPath path of the target element according to the third element attribute combination; wherein the optional XPath path includes at least one of the following items: generating a third XPath path according to the third element attribute combination of the level where the parent node element is located, and generating a fourth XPath path according to the fourth element attribute combination of the parent node element; wherein the fourth element attribute combination includes an element attribute combination of an associated element in the tree diagram that has a preset node relationship with the parent node element.
6. The XPath path generation method according to any one of claims 1 to 5, characterized in that: After obtaining the target path, the method further includes: When the number of levels of the target path is greater than a preset threshold, and the levels corresponding to the first and last nodes in the target path are different and not adjacent, the intermediate nodes except the first and last nodes in the target path are replaced with the first symbol in sequence, and it is verified whether the XPath path after each replacement is valid; If, according to the replaced XPath path, the element determined in the XML data includes the target element, the first symbol is retained and the next intermediate node is replaced; if, according to the replaced XPath path, the element determined in the XML data does not include the target element, the replacement is canceled and the next intermediate node is processed until the intermediate nodes in the target element are traversed to obtain the optimized target path.
7. The XPath path generation method according to any one of claims 1 to 6, characterized in that: The element attribute combination includes at least one of the following: Object name; Object name and class name; Object name, class name, and text; text; Text and class names; Class name and index; Class name.
8. An XPath path generation device, characterized in that: include: An acquisition module, used for acquiring the first element attribute combination of the target element at the level in the tree diagram of the XML data; A first processing module, configured to generate an optional XPath path of the target element according to the first element attribute combination; wherein the optional XPath path includes at least one of the following: a first XPath path generated according to the first element attribute combination, and a second XPath path generated according to a second element attribute combination; wherein the second element attribute combination includes an element attribute combination of an associated element having a preset node relationship with the target element in the tree diagram; The second processing module is used to query the XML data according to the optional XPath path to obtain a query result, and use the query result as the XPath path of the target element as the target path.
9. An electronic device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.