Object positioning method and apparatus, electronic device, and computer-readable storage medium

By presetting the database to store element attributes and their effectiveness identifiers and using polling to locate elements, the problems of high element positioning failure rate and high maintenance cost in the existing technology are solved, and efficient and accurate element positioning is achieved.

CN116842226BActive Publication Date: 2025-10-21CHONGQING SELIS PHOENIX INTELLIGENT INNOVATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310787965.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-29
Publication Date
2025-10-21
Estimated Expiration
2043-06-29

AI Technical Summary

Technical Problem

The element object positioning method and path in the existing technology have low fault tolerance, resulting in a high probability of positioning failure, high maintenance costs, and prone to manual operation errors, which affect test efficiency and accuracy.

Method used

A preset database is used to store multiple element attributes and validity identifiers of the target element, and polling is used to locate the element. If it fails, the element attribute is marked as invalid, and if it succeeds, it is marked as valid, realizing multi-path positioning and reducing the need for manual maintenance.

Benefits of technology

It improves the robustness and accuracy of element positioning, reduces the requirements for automated testing, avoids manual operation errors, and improves positioning efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116842226B_ABST
    Figure CN116842226B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of software testing, and provides an object positioning method and device, electronic equipment and a computer readable storage medium. The method comprises the following steps: pre-storing element positioning information corresponding to an element information identifier in a preset database, so that when element positioning is needed, the element positioning information of the element information identifier can be obtained from the preset database, and the element positioning information can be used to position a target element in a polling mode by using multiple element attributes of the target element and the validity identifiers of the element attributes, if the positioning fails, the element attributes can be identified as invalid, subsequent personnel maintenance is facilitated, if the positioning succeeds, the element attributes can be identified as successful and an element object of the target element is returned. In this way, the robustness of element positioning can be improved in the mode of multiple element attributes (i.e. multiple methods and multiple positioning paths) of the target element.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software testing technology, and in particular to an object positioning method, device, electronic device, and computer-readable storage medium. Background Art

[0002] Selenium is a tool for testing web applications. Its main functions include testing browser compatibility, testing applications to see if they work well across different browsers and operating systems, testing system functionality, creating regression tests, and verifying software functionality. Selenium tests run directly in the browser, just like real users would. Supported browsers include Internet Explorer, Mozilla, and Firefox.

[0003] Existing Selenium automated testing element location methods generally locate elements through a single find_element_by_xx() method. In addition, the location method and location path are both pre-fixed in the test code and are hard-coded. However, this hard-coded method is not conducive to maintaining the location method and location path. For example, when element location fails, the code needs to be modified or the location method and path needs to be adjusted, which requires manual rewriting of the code. As a result, when writing code, the fault tolerance of the location method and location path is low, resulting in an increased probability of element location failure and high maintenance costs. This will greatly increase the amount of data required for manual maintenance of the code, and the testing process will also be more cumbersome, making the manual element location process in the element location task time-consuming, labor-intensive, and inefficient. It is also prone to location errors caused by manual operation errors, and the cost of element object location is increased. Therefore, a new object location solution is urgently needed. Summary of the Invention

[0004] In view of this, the embodiments of the present application provide an object positioning method, device, electronic device and computer-readable storage medium to solve the problem in the prior art that the positioning method of the positioning code of the element object and the low fault tolerance of the positioning path lead to an increased probability of element positioning failure, the maintenance work is cumbersome, difficult and highly redundant, resulting in a significant increase in the amount of data required for manual maintenance of the code, and the testing process is also relatively cumbersome, which in turn leads to the manual element positioning process in the element positioning task being time-consuming, labor-intensive and inefficient, and prone to positioning errors caused by manual operation errors, and the cost of element object positioning is increased.

[0005] A first aspect of an embodiment of the present application provides an object positioning method, comprising:

[0006] Obtaining an element locating instruction, wherein the element locating instruction includes an element information identifier corresponding to a target element;

[0007] Using the element information identifier to query a preset database, obtain element location information of the element information identifier; wherein the element location information includes multiple element attributes of the target element and effectiveness identifiers of each element attribute, and the effectiveness identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute;

[0008] The target element is located using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element is located unsuccessfully using the element attribute of the target element, the effectiveness identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element using an element attribute of the target element and the effectiveness identifier of the element attribute is continued; if the target element is located successfully using the element attribute, the effectiveness identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element.

[0009] According to a second aspect of the present application, an object positioning device is provided, comprising:

[0010] An instruction acquisition module is configured to acquire an element location instruction, wherein the element location instruction includes an element information identifier corresponding to a target element;

[0011] an information acquisition module configured to query a preset database using the element information identifier to obtain element location information of the element information identifier; wherein the element location information includes multiple element attributes of the target element and a validity identifier of each element attribute, and the validity identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute;

[0012] An element positioning module is configured to locate the target element using an element attribute of the target element and a validity identifier of the element attribute; if the target element is successfully located using the element attribute, the validity identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element; if the target element is failed to be located using the element attribute of the target element, the validity identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element using an element attribute of the target element and the validity identifier of the element attribute is continued.

[0013] According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, which stores a computer program. When the computer program is executed by a processor, the steps of the above method are implemented.

[0014] Compared with the prior art, the embodiment of the present application has the following advantages: after obtaining an element location instruction, the embodiment of the present application includes an element information identifier corresponding to the target element, and the element information identifier can be used to query a preset database to obtain the element location information of the element information identifier; wherein, the element location information includes multiple element attributes of the target element and the effectiveness identifier of each element attribute, and the effectiveness identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute. Then, the target element can be located using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element fails to be located using the element attribute of the target element, the effectiveness identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element using the element attribute of the target element and the effectiveness identifier of the element attribute is continued; if the target element is successfully located using the element attribute, the effectiveness identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element. It can be seen that in this embodiment, the element location information corresponding to the element information identifier for locating the target element is pre-stored in a preset database. In this way, when element location is required, the element location information of the element information identifier can be obtained through the preset database, and the multiple element attributes of the target element in the element location information and the effectiveness identifier of each element attribute can be used to locate the target element in a polling manner. If the location fails, the element attribute can be marked as invalid, which is convenient for subsequent personnel to maintain. If the location is successful, the element attribute can be marked as successful and the element object of the target element can be returned. In this way, the robustness of element location can be improved by using multiple element attributes of the target element (i.e., multiple methods and multiple positioning paths); in addition, the element location information of the element information identifier in the preset database can be directly maintained, that is, the user only needs to maintain the element location information of the element information identifier in the preset database without rewriting the element location code, which reduces the requirements for automated testing and does not require manual adjustment of the element location code. In addition, the problem of verification errors caused by manual operation errors can be avoided, and the accuracy of the location results of the element location and the efficiency of element location can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0016] Figure 1 is a schematic diagram of an application scenario of an embodiment of the present application;

[0017] Figure 2 This is a flow chart of an object positioning method provided in an embodiment of the present application;

[0018] Figure 3a 1 is a flow chart of another object positioning method provided in an embodiment of the present application;

[0019] Figure 3b 1 is a flow chart of another object positioning method provided in an embodiment of the present application;

[0020] Figure 4 1 is a schematic structural diagram of an object positioning device provided in an embodiment of the present application;

[0021] Figure 5 This is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0022] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0023] An object positioning method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.

[0024] Figure 1 1 is a schematic diagram of an application scenario of an embodiment of the present application. The application scenario may include terminal devices 1, 2 and 3, a server 4 and a network 5.

[0025] The terminal devices 1, 2 and 3 can be hardware or software. When the terminal devices 1, 2 and 3 are hardware, they can be various electronic devices with display screens and supporting communication with the server 4, including but not limited to smart phones, tablet computers, laptop computers and desktop computers; when the terminal devices 1, 2 and 3 are software, they can be installed in the electronic devices mentioned above. The terminal devices 1, 2 and 3 can be implemented as multiple software or software modules, or as a single software or software module, and the embodiments of the present application are not limited to this. Furthermore, various applications can be installed on the terminal devices 1, 2 and 3, such as data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.

[0026] Server 4 can be a server that provides various services, for example, a backend server that receives requests sent by terminal devices that establish communication connections with it. The backend server can receive and analyze the requests sent by the terminal devices, and generate processing results. Server 4 can be a single server, a server cluster consisting of multiple servers, or a cloud computing service center, and the embodiments of the present application are not limited thereto.

[0027] It should be noted that the server 4 can be either hardware or software. When the server 4 is hardware, it can be various electronic devices that provide various services to the terminal devices 1, 2, and 3. When the server 4 is software, it can be multiple software or software modules that provide various services to the terminal devices 1, 2, and 3, or it can be a single software or software module that provides various services to the terminal devices 1, 2, and 3, and this embodiment of the application does not limit this.

[0028] The network 5 can be a wired network connected by coaxial cable, twisted pair and optical fiber, or it can be a wireless network that can interconnect various communication devices without wiring, such as Bluetooth, Near Field Communication (NFC), infrared, etc., which is not limited in the embodiment of the present application.

[0029] The user can establish a communication connection with the server 4 via the network 5 through the terminal devices 1, 2 and 3 to receive or send information, etc. Specifically, when the user needs to test the web page of the Web application in the terminal devices 1, 2 and 3, the test trigger instruction can be output to the terminal devices 1, 2 and 3, and the terminal devices 1, 2 and 3 can send the element positioning instruction to the server 4, wherein the element positioning instruction includes the element information identifier corresponding to the target element. After the server 4 obtains the element positioning instruction, the server 4 can first use the element information identifier to query the preset database to obtain the element positioning information of the element information identifier; wherein, the element positioning information includes multiple element attributes of the target element and the effectiveness identifier of each element attribute, and the effectiveness identifier of the element attribute is used to reflect the positioning result of locating the target element using the element attribute. Then, the server 4 can use an element attribute of the target element and the effectiveness identifier of the element attribute to locate the target element; if the target element fails to be located using the element attribute of the target element, the effectiveness identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of using the element attribute of the target element and the effectiveness identifier of the element attribute to locate the target element is continued; if the target element is successfully located using the element attribute, the effectiveness identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element. In this way, the present embodiment stores the element location information corresponding to the element information identifier for locating the target element in a preset database in advance. In this way, when element location is needed, the element location information of the element information identifier can be obtained through the preset database, and the multiple element attributes of the target element in the element location information and the effectiveness identifiers of each element attribute can be used to locate the target element in a polling manner. If the location fails, the element attribute can be marked as invalid, which is convenient for subsequent personnel to maintain. If the location is successful, the element attribute can be marked as successful and the element object of the target element is returned. In this way, the robustness of element positioning can be improved by using multiple element attributes of the target element (i.e., multiple methods, multiple positioning paths); in addition, the element positioning information of the element information identifier in the preset database can be directly maintained, that is, the user only needs to maintain the element positioning information of the element information identifier in the preset database, without having to rewrite the element positioning code, which reduces the requirements for automated testing and does not require manual adjustment of the element positioning code, thereby avoiding the problem of verification errors caused by manual operation errors, and improving the accuracy of the positioning results of element positioning and the efficiency of element positioning.

[0030] It should be noted that the specific types, quantities and combinations of the terminal devices 1, 2 and 3, the server 4 and the network 5 can be adjusted according to the actual needs of the application scenario, and the embodiments of the present application do not limit this.

[0031] Figure 2 This is a flow chart of an object positioning method provided in an embodiment of the present application. Figure 2 The object positioning method can be Figure 1 The server executes. Figure 2 As shown, the object positioning method includes:

[0032] S201, obtaining an element positioning instruction.

[0033] In this embodiment, the element location instruction can be understood as an instruction for triggering element location on a page. The element location instruction includes an element information identifier corresponding to the target element. It is understood that the element information identifier is a unique identifier corresponding to the target element, that is, the element information identifiers of different elements are different. It should be noted that an element can be understood as an element object, and an element object can be an element on a page, for example, a button or a component on a web page.

[0034] In one implementation, element object location can be just one step in a test case, that is, the timing for obtaining the element location specification can be obtained during the test process of the test case. Specifically, in response to a test start instruction for a target test case, a test can be performed based on the target test case; if the element location task is executed during the test process of the target test case, the element location instruction is obtained. The target test case can be understood as the case being tested. For example, the target test case can be used to test whether a webpage can be opened or whether the functions of the buttons on the webpage (such as the return, forward, and search functions corresponding to the buttons) are normal. If there is a step in the target test case that requires element location, for example, when it is necessary to test whether the return button on the webpage can perform the return function normally, it is necessary to first locate the return button (i.e., the target element object); then, during the test process of the target test case (i.e., the process of executing the target test case), when it is necessary to execute the element location task, the element location instruction can be obtained. It should be noted that since the element location task has been determined in advance, the element information identifier can be determined based on the element location task, for example, the element information identifier can be determined based on the name of the element object corresponding to the element location task.

[0035] It should be noted that the method described in this embodiment can be implemented by element locating code (such as Selenium). In one implementation, the code of the element locating code can be Python.

[0036] S202: Query a preset database using the element information identifier to obtain element location information of the element information identifier.

[0037] Among them, the element positioning information may include multiple element attributes of the target element and the effectiveness identifier of each element attribute. Element attributes can be understood as attribute information of the target element. For example, in one implementation, the element attributes of the target element may include: ID, name (name), category name (class_name), tag name (tag_name), hyperlink text (link_text), style attribute (css_selector), XML path language (xpath). The effectiveness identifier of the element attribute is used to reflect the positioning result of locating the target element using the element attribute. For example, the effectiveness identifier of the element attribute can be an invalid identifier or a valid identifier. If the effectiveness identifier is an invalid identifier, it means that the element attribute cannot locate the target element. If the effectiveness identifier is a valid identifier, it means that the element attribute can locate the target element. It should be noted that the initialized effectiveness identifier of the element attribute is a valid identifier.

[0038] It should be noted that the preset database can pre-store multiple element attributes of the target element and the effectiveness identifier of each element attribute. For example, in the preset database, a table can be used to save these positioning information, and a field of the table can be used as the effectiveness identifier. For example, the table field is effective, and the value of the field is 1 for valid, and the value is 0 for invalid. In one implementation method, the preset database can be a Mysql database. Specifically, the preset element information identifier that is the same as the element information identifier can be queried in the preset database; then, the element positioning information corresponding to the preset element information identifier can be used as the element positioning information corresponding to the element information identifier.

[0039] S202, locate the target element using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element fails to be located using the element attribute of the target element, set the effectiveness identifier of the element attribute to an invalid identifier, and use the next element attribute of the element attribute as the target element attribute, and continue to execute the step of locating the target element using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element is successfully located using the element attribute, set the effectiveness identifier of the element attribute to a valid identifier, and use the located element object as the element object corresponding to the target element.

[0040] In this embodiment, after obtaining multiple element attributes of a target element and the effectiveness identifiers of each element attribute, the target element can be located sequentially using the element attributes whose effectiveness identifiers are valid identifiers. Specifically, in one implementation, a preset database also stores the positioning methods corresponding to each element attribute. If the effectiveness identifier of an element attribute is a valid identifier, the positioning method corresponding to the element attribute can be determined first; then, the positioning method corresponding to the element attribute can be used to locate the element, obtaining an element positioning result for the target element; wherein the element positioning result is positioning success or positioning failure.

[0041] For example, the positioning methods corresponding to each element attribute can be as follows: the positioning method of the element attribute ID can be find_element(By.ID,"element ID"); the positioning method of the element attribute name (name) can be find_element(By.NAME,"element name"); the positioning method of the element attribute category name (class_name) can be find_element(By.CLASS_NAME,"element CLASS name"); the positioning method of the element attribute tag name (tag_name) can be find_element(By.TAG_NAME,"element TAG tag"); the positioning method of the element attribute hyperlink text (link_text) can be find_element(By.LINK_TEXT,"news section"); the positioning method of the element attribute XML path language (xpath) can be find_element(By.XPATH,"XPATH path"); the positioning method of the element attribute style attribute (css_selector) can be find_element(By.CSS_SELECTOR,"CSS style attribute").

[0042] In this embodiment, for example, Figure 3a and Figure 3b As shown, the element attribute with the effectiveness identifier as the valid identifier can be located first through a loop method. If the location is successful, the located element object is returned, and the effectiveness identifier of the element attribute is set to the valid identifier and the loop ends. If the location fails, the effectiveness identifier of the element attribute is set to the invalid identifier, and the loop enters the next element attribute until all element attributes corresponding to the target element are located once.

[0043] Specifically, the target element is first located using an element attribute of the target element and the effectiveness identifier of the element attribute. That is, if the effectiveness identifier of the element attribute is a valid identifier, the location method corresponding to the element attribute is determined, and the element location method corresponding to the element attribute is used to locate the element, obtaining an element location result of the target element; wherein the element location result is a location success or a location failure. If the target element is not located using the element attribute of the target element, that is, the target element is not located using the element attribute of the target element, the effectiveness identifier of the element attribute can be set to an invalid identifier, and the next element attribute of the element attribute can be used as the target element attribute, and the step of locating the target element using the element attribute of the target element and the effectiveness identifier of the element attribute is continued until an element attribute is successfully located or all element attributes are used to attempt to locate the target element. If the target element is successfully located using the element attribute, that is, the target element is located using the element attribute of the target element, the effectiveness identifier of the element attribute can be set to a valid identifier, and the located element object can be used as the element object corresponding to the target element, so that the element object corresponding to the target element can be returned.

[0044] It should be noted that, in one implementation, if the element positioning results of all element attributes of the target element are all positioning failures, that is, all element attributes corresponding to the target element cannot locate the target element, that is, the validity identifiers of all element attributes corresponding to the target element are all invalid identifiers; then a positioning failure prompt message corresponding to the target element can be generated, so as to use the positioning failure prompt message to remind the user to perform manual inspection. The positioning failure prompt message includes the basic attribute information of the target element. For example, the basic attribute information of the target element may include information such as the page to which the target element belongs and the element name. In one implementation, if Figure 3a and Figure 3b As shown, if the element positioning results of all element attributes of the target element are positioning failures, that is, the validity identifiers of all element attributes corresponding to the target element are invalid identifiers, it means that all positioning methods have failed. It is necessary to send the failed element information (that is, positioning failure prompt information) to the corresponding developer through the DingTalk robot to manually check the cause of the failure and repair it. In this way, it is convenient to maintain the abnormal positioning.

[0045] Compared with the prior art, the embodiment of the present application has the following advantages: after obtaining an element location instruction, the embodiment of the present application includes an element information identifier corresponding to the target element, and the element information identifier can be used to query a preset database to obtain the element location information of the element information identifier; wherein, the element location information includes multiple element attributes of the target element and the effectiveness identifier of each element attribute, and the effectiveness identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute. Then, the target element can be located using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element fails to be located using the element attribute of the target element, the effectiveness identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element using the element attribute of the target element and the effectiveness identifier of the element attribute is continued; if the target element is successfully located using the element attribute, the effectiveness identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element. It can be seen that in this embodiment, the element location information corresponding to the element information identifier for locating the target element is pre-stored in a preset database. In this way, when element location is required, the element location information of the element information identifier can be obtained through the preset database, and the multiple element attributes of the target element in the element location information and the effectiveness identifier of each element attribute can be used to locate the target element in a polling manner. If the location fails, the element attribute can be marked as invalid, which is convenient for subsequent personnel to maintain. If the location is successful, the element attribute can be marked as successful and the element object of the target element can be returned. In this way, the robustness of element location can be improved by using multiple element attributes of the target element (i.e., multiple methods and multiple positioning paths); in addition, the element location information of the element information identifier in the preset database can be directly maintained, that is, the user only needs to maintain the element location information of the element information identifier in the preset database without rewriting the element location code, which reduces the requirements for automated testing and does not require manual adjustment of the element location code. In addition, the problem of verification errors caused by manual operation errors can be avoided, and the accuracy of the location results of the element location and the efficiency of element location can be improved.

[0046] In some embodiments, after the steps of setting the effectiveness flag of the element attribute to a valid flag if the target element is successfully located using the element attribute, and using the located element object as the element object corresponding to the target element, the method may further include:

[0047] If there is an element attribute with an invalid validity flag among the multiple element attributes of the target element, the element attribute with an invalid validity flag is repaired using the element attribute that has been successfully located. If the validity flags of the multiple element attributes of the target element are all invalid validity flags, the location is terminated.

[0048] like Figure 3a and Figure 3b As shown, after successfully locating the target element using an element attribute in the positioning information, if there is at least one element attribute with a validity identifier as an invalid identifier among the multiple element attributes of the target element, the element attribute with a validity identifier as an invalid identifier can be repaired using the element attribute that successfully located the target element.

[0049] As an example, the hypertext markup language text information corresponding to the element attribute of the target element that is successfully located can be obtained first. For example, in one implementation, Figure 3a and Figure 3b As shown, the html text information (i.e., hypertext markup language text information) of the element attribute that successfully locates the target element can be obtained through the element's outerHTML method. For example, the hypertext markup language text information can include information such as tag, id, class, and class_name.

[0050] For each element attribute with a validity identifier of invalid, if the hypertext markup language text information includes a candidate element attribute of the same attribute type as the element attribute with a validity identifier of invalid, that is, if the hypertext markup language text information includes the element attribute with a validity identifier of invalid, then the candidate element attribute can be used to repair the element attribute with a validity identifier of invalid. In one implementation, Figure 3a and Figure 3bAs shown, the candidate element attribute can be used to locate the target element first. If the element object is not located using the candidate element attribute, the repair fails. If the element object is located using the candidate element attribute, the coordinate information of the element object can be obtained. If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, it means that the candidate element attribute in the hypertext markup language text information is an element attribute that can be used to locate the target object, indicating that the candidate element attribute is a correct element attribute, which means that the repair is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, it means that the candidate element attribute in the hypertext markup language text information is an element attribute that cannot be used to locate the target object, indicating that the candidate element attribute is an incorrect element attribute, which means that the repair fails. If the repair is successful, the element attribute with the validity identifier as the invalid identifier in the preset database can be replaced with the candidate element attribute, and the validity identifier of the candidate element attribute can be set to a valid identifier.

[0051] If the hypertext markup language text information does not include a candidate element attribute of the same attribute type as the element attribute whose validity identifier is an invalid identifier, or if the element attribute repair fails, it means that the candidate element attribute in the hypertext markup language text information is an element attribute that cannot be used to locate the target object, indicating that the candidate element attribute is an incorrect element attribute. In this way, the target element can be located by using all the candidate element attributes in the hypertext markup language text information. In one implementation, Figure 3a and Figure 3bAs shown, the CSS positioning data corresponding to the hypertext markup language text information can be generated based on all the candidate element attributes in the hypertext markup language text information. For example, all the attributes in html (i.e., hypertext markup language text information) can be used for css_selector combination positioning, such as using the element attributes id, class, tag tags and other attributes in html (i.e., hypertext markup language text information). After these attributes are identified, they are combined according to preset rules to form CSS positioning data. For example, if the id is kw and the tag tag is input, they can be combined into a CSS positioning data: find_element_by_css_selector("input#kw"). If the element object is not located using the CSS positioning data corresponding to the hypertext markup language text information, it means that the positioning has failed. If the element object is located using the CSS positioning data corresponding to the hypertext markup language text information, it means that the positioning is successful and the coordinate information of the element object can be obtained. If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, it means that the positioning is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, it means that the positioning fails.

[0052] If all candidate element attributes are used to successfully locate the target element, the element attribute with the invalid validity flag in the preset database can be replaced with the candidate element attribute, and the validity flag of the candidate element attribute can be set to the valid flag. In this way, all element attributes corresponding to the target element in the preset database can be located to the element object corresponding to the target element.

[0053] If the target element cannot be located using all the candidate element attributes, the target element can be located using the RPA element location method and the candidate element attributes. For example, the RPA method of xpath can be used for calculation and location. If the target element is successfully located using the RPA element location method and the candidate element attributes, the element attribute with the invalid validity identifier in the preset database can be replaced with the candidate element attribute, and the validity identifier of the candidate element attribute can be set to a valid identifier. In this way, all the element attributes corresponding to the target element in the preset database can be located to the element object corresponding to the target element. If the target element cannot be located using the RPA element location method and the candidate element attributes, it means that the location is complete.

[0054] As can be seen, in this embodiment, after successfully locating the target element using the element attribute, the validity flag of the element attribute is set to the valid flag, and after the located element object is used as the element object corresponding to the target element, if there is an element attribute with a validity flag set as the invalid flag among the multiple element attributes of the target element, the element attribute with the validity flag set as the invalid flag is repaired using the element attribute that successfully located the target element. In this way, the element attribute with the validity flag set as the invalid flag can be maintained, reducing manual maintenance costs.

[0055] All of the above optional technical solutions can be combined in any way to form optional embodiments of the present application, and will not be described in detail here.

[0056] The following are device embodiments of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

[0057] Figure 4 Schematic diagram of an object positioning device provided in an embodiment of the present application. Figure 4 As shown, the object positioning device includes:

[0058] The instruction acquisition module 401 is configured to acquire an element location instruction, wherein the element location instruction includes an element information identifier corresponding to a target element;

[0059] The information acquisition module 402 is configured to query a preset database using the element information identifier to obtain element location information of the element information identifier; wherein the element location information includes multiple element attributes of the target element and a validity identifier of each element attribute, and the validity identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute;

[0060] The element positioning module 403 is configured to locate the target element by using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element is successfully located by using the element attribute, the effectiveness identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element; if the target element is failed to be located by using the element attribute of the target element, the effectiveness identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element by using an element attribute of the target element and the effectiveness identifier of the element attribute is continued.

[0061] According to the technical solution provided by the embodiment of the present application, since the element positioning information corresponding to the element information identifier for locating the target element is pre-stored in a preset database, when element positioning is required, the element positioning information of the element information identifier can be obtained through the preset database, and the multiple element attributes of the target element in the element positioning information and the effectiveness identifier of each element attribute can be used to locate the target element in a polling manner. If the positioning fails, the element attribute can be marked as invalid, which is convenient for subsequent personnel to maintain. If the positioning is successful, the element attribute can be marked as successful and the element object of the target element can be returned. In this way, the robustness of element positioning can be improved by using multiple element attributes of the target element (i.e., multiple methods and multiple positioning paths); in addition, the element positioning information of the element information identifier in the preset database can be directly maintained, that is, the user only needs to maintain the element positioning information of the element information identifier in the preset database without rewriting the element positioning code, which reduces the requirements for automated testing and does not require manual adjustment of the element positioning code, thereby avoiding the problem of verification errors caused by manual operation errors, and improving the accuracy of the positioning results of the element positioning and the efficiency of the element positioning.

[0062] In some embodiments, the element location module 403 is configured to:

[0063] If the validity identifier of the element attribute is a valid identifier, then determining the positioning method corresponding to the element attribute;

[0064] The element is located using the location method corresponding to the element attribute to obtain an element location result of the target element; wherein the element location result is a location success or a location failure.

[0065] In some embodiments, the element positioning module 403 is further configured to:

[0066] If the element positioning results of all element attributes of the target element are positioning failures, positioning failure prompt information corresponding to the target element is generated; wherein the positioning failure prompt information includes basic attribute information of the target element.

[0067] In some embodiments, the element locating module 403 is further configured to: after the step of setting the effectiveness identifier of the element attribute to a valid identifier if the target element is successfully located using the element attribute, and using the located element object as the element object corresponding to the target element, if there is an element attribute with an effectiveness identifier as an invalid identifier among the multiple element attributes of the target element, then using the element attribute that successfully locates the target element to repair the element attribute with an effectiveness identifier as an invalid identifier.

[0068] In some embodiments, the element location module 403 is configured to:

[0069] Obtaining the hypertext markup language text information corresponding to the element attribute of the target element that is successfully located;

[0070] For each element attribute whose validity identifier is an invalid identifier, if the hypertext markup language text information includes a candidate element attribute of the same attribute type as the element attribute whose validity identifier is an invalid identifier, repair the element attribute whose validity identifier is an invalid identifier using the candidate element attribute;

[0071] If the repair is successful, the element attribute with the validity flag as the invalid flag in the preset database is replaced with the candidate element attribute, and the validity flag of the candidate element attribute is set to the valid flag;

[0072] If the hypertext markup language text information does not include a candidate element attribute of the same attribute type as the element attribute whose validity identifier is an invalid identifier, or if the element attribute repair fails, then all candidate element attributes in the hypertext markup language text information are used to locate the target element;

[0073] If the target element is successfully located using all candidate element attributes, the element attribute with the invalid validity flag in the preset database is replaced with the candidate element attribute, and the validity flag of the candidate element attribute is set to be a valid flag;

[0074] If the target element cannot be located using all candidate element attributes, the target element is located using the RPA element positioning method and the candidate element attributes; if the target element is successfully located using the RPA element positioning method and the candidate element attributes, the element attribute with the effectiveness identifier as an invalid identifier in the preset database is replaced with the candidate element attribute, and the effectiveness identifier of the candidate element attribute is set to a valid identifier.

[0075] In some embodiments, the element positioning module 403 is further configured to:

[0076] Using the candidate element attributes, locate the target element;

[0077] If the element object is located using the candidate element attribute, the coordinate information of the element object is obtained; if the element object is not located using the candidate element attribute, the repair fails;

[0078] If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, the repair is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, the repair fails.

[0079] In some embodiments, the element positioning module 403 is further configured to:

[0080] Generate CSS positioning data corresponding to the hypertext markup language text information according to all candidate element attributes in the hypertext markup language text information;

[0081] If the element object is located using the CSS positioning data corresponding to the hypertext markup language text information, the coordinate information of the element object is obtained; if the element object is not located using the CSS positioning data corresponding to the hypertext markup language text information, the positioning fails;

[0082] If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, the positioning is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, the positioning fails.

[0083] Figure 5 Schematic diagram of the electronic device 5 provided in the embodiment of the present application. Figure 5 As shown, the electronic device 5 of this embodiment includes: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable by the processor 501. When the processor 501 executes the computer program 503, the steps of the above-mentioned method embodiments are implemented. Alternatively, when the processor 501 executes the computer program 503, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0084] The electronic device 5 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 5 may include but is not limited to a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5 This is merely an example of the electronic device 5 and does not limit the electronic device 5 . The electronic device 5 may include more or fewer components than shown in the figure, or different components.

[0085] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0086] The memory 502 can be an internal storage unit of the electronic device 5, such as a hard disk or memory of the electronic device 5. The memory 502 can also be an external storage device of the electronic device 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. The memory 502 can also include both an internal storage unit of the electronic device 5 and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the electronic device.

[0087] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.

[0088] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and when the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0089] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.

Claims

1. An object positioning method, characterized in that: include: Obtaining an element locating instruction, wherein the element locating instruction includes an element information identifier corresponding to a target element; Using the element information identifier to query a preset database, obtaining element positioning information of the element information identifier; wherein the element positioning information includes multiple element attributes of the target element and effectiveness identifiers of each element attribute, and the effectiveness identifier of the element attribute is used to reflect the positioning result of locating the target element using the element attribute; The target element is located by using an element attribute of the target element and the effectiveness identifier of the element attribute; if the target element is located unsuccessfully by using the element attribute of the target element, the effectiveness identifier of the element attribute is set as an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element by using an element attribute of the target element and the effectiveness identifier of the element attribute is continued; if the target element is located successfully by using the element attribute, the effectiveness identifier of the element attribute is set as a valid identifier, and the located element object is used as the element object corresponding to the target element.

2. The method according to claim 1, characterized in that The locating the target element by using an element attribute of the target element and a validity identifier of the element attribute includes: If the validity identifier of the element attribute is a valid identifier, determining the positioning method corresponding to the element attribute; Element positioning is performed using the positioning method corresponding to the element attribute to obtain an element positioning result of the target element; wherein the element positioning result is positioning success or positioning failure.

3. The method according to claim 2, characterized in that The method further comprises: If the element positioning results of all element attributes of the target element are positioning failures, positioning failure prompt information corresponding to the target element is generated; wherein the positioning failure prompt information includes basic attribute information of the target element.

4. The method according to claim 1, wherein After the steps of setting the effectiveness identifier of the element attribute to a valid identifier if the target element is successfully located using the element attribute, and using the located element object as the element object corresponding to the target element, the method further includes: If there is an element attribute with a validity identifier of an invalid flag among the multiple element attributes of the target element, the element attribute with a validity identifier of an invalid flag is repaired by using the element attribute that successfully locates the target element.

5. The method according to claim 4, characterized in that The repairing of the element attribute with the validity flag as the invalid flag by using the element attribute of the target element that has been successfully located includes: Obtaining hypertext markup language text information corresponding to the element attribute that successfully locates the target element; For each element attribute whose validity identifier is an invalidation identifier, if the hypertext markup language text information includes a candidate element attribute of the same attribute type as the element attribute whose validity identifier is an invalidation identifier, repair the element attribute whose validity identifier is an invalidation identifier by using the candidate element attribute; If the repair is successful, the element attribute with the validity identifier as the invalid identifier in the preset database is replaced with the candidate element attribute, and the validity identifier of the candidate element attribute is set to the valid identifier; If the hypertext markup language text information does not include a candidate element attribute of the same attribute type as the element attribute whose validity identifier is an invalid identifier, or if the element attribute repair fails, then all candidate element attributes in the hypertext markup language text information are used to locate the target element; If the target element is successfully located using all candidate element attributes, the element attribute with the invalid validity flag in the preset database is replaced with the candidate element attribute, and the validity flag of the candidate element attribute is set to a valid flag; If the target element cannot be located using all candidate element attributes, the target element is located using the RPA element positioning method and the candidate element attributes; if the target element is successfully located using the RPA element positioning method and the candidate element attributes, the element attribute with the effectiveness identifier as the invalid identifier in the preset database is replaced with the candidate element attribute, and the effectiveness identifier of the candidate element attribute is set to the valid identifier.

6. The method according to claim 5, characterized in that The repairing of the element attribute with the validity identifier as the invalid identifier by using the candidate element attribute includes: Locating the target element using the candidate element attributes; If the element object is located using the candidate element attributes, the coordinate information of the element object is obtained; if the element object is not located using the candidate element attributes, the repair fails; If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, the repair is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, the repair fails.

7. The method according to claim 5, characterized in that The method of locating the target element by using all candidate element attributes in the hypertext markup language text information includes: generating CSS positioning data corresponding to the hypertext markup language text information according to all candidate element attributes in the hypertext markup language text information; If the element object is located using the CSS positioning data corresponding to the hypertext markup language text information, the coordinate information of the element object is obtained; if the element object is not located using the CSS positioning data corresponding to the hypertext markup language text information, the positioning fails; If the coordinate information of the element object is the same as the coordinate information of the element object corresponding to the target element, the positioning is successful; if the coordinate information of the element object is different from the coordinate information of the element object corresponding to the target element, the positioning fails.

8. An object positioning device, characterized in that: include: An instruction acquisition module is configured to acquire an element positioning instruction, wherein the element positioning instruction includes an element information identifier corresponding to a target element; an information acquisition module configured to query a preset database using the element information identifier to obtain element location information of the element information identifier; wherein the element location information includes multiple element attributes of the target element and a validity identifier of each element attribute, and the validity identifier of the element attribute is used to reflect the location result of locating the target element using the element attribute; An element positioning module is configured to locate the target element by using an element attribute of the target element and a validity identifier of the element attribute; if the target element is successfully located by using the element attribute, the validity identifier of the element attribute is set to a valid identifier, and the located element object is used as the element object corresponding to the target element; if the target element is failed to be located by using the element attribute of the target element, the validity identifier of the element attribute is set to an invalid identifier, and the next element attribute of the element attribute is used as the target element attribute, and the step of locating the target element by using an element attribute of the target element and the validity identifier of the element attribute is continued.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Method and device for outputting information

    CN110096392A

  • Automatic testing method and device

    CN113590496A