CN109977267B - Method and device for determining XPath path - Google Patents

Method and device for determining XPath path Download PDF

Info

Publication number
CN109977267B
CN109977267B CN201910106725.1A CN201910106725A CN109977267B CN 109977267 B CN109977267 B CN 109977267B CN 201910106725 A CN201910106725 A CN 201910106725A CN 109977267 B CN109977267 B CN 109977267B
Authority
CN
China
Prior art keywords
xpath
determining
elements
path
positioning result
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910106725.1A
Other languages
Chinese (zh)
Other versions
CN109977267A (en
Inventor
戴亦斌
金伟光
王晓磊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Testin Information Technology Co Ltd
Original Assignee
Beijing Testin Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Testin Information Technology Co Ltd filed Critical Beijing Testin Information Technology Co Ltd
Priority to CN201910106725.1A priority Critical patent/CN109977267B/en
Publication of CN109977267A publication Critical patent/CN109977267A/en
Application granted granted Critical
Publication of CN109977267B publication Critical patent/CN109977267B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The invention discloses a method and a device for determining an XPath (x-ray path), belonging to the technical field of databases, wherein the method comprises the following steps: determining brother elements of the elements to be positioned; constructing a first XPath path based on the sibling elements; positioning the element to be positioned according to the first XPath to obtain a first positioning result; and determining an XPath corresponding to the element to be positioned according to the first positioning result. The first XPath path is constructed only according to brother elements of the elements to be positioned, the elements to be positioned are positioned based on the first XPath path, the XPath path corresponding to the elements to be positioned is determined, the purpose that the determined XPath path is the shortest path is achieved, the situation that the elements to be positioned cannot be positioned due to the fact that a certain part of the XPath path changes is avoided, the compatibility of the XPath path on the mobile terminal is stronger, and meanwhile the searching accuracy of the XPath path is improved.

Description

Method and device for determining XPath path
Technical Field
The invention relates to the technical field of databases, in particular to a method and a device for determining an XPath path.
Background
XPath is an XML Path language, which is a language used to determine the location of a part of an XML (subset of standard generalized markup languages) document. XPath is based on XML tree structures with different types of nodes. XPath uses path expressions, which are the written sequence of steps from one XML node (the current context node) to another node or group of nodes, to pick a node or set of nodes in an XML document.
When the mobile terminal script is recorded, the XPath path is an important path of a positioning element, the positioning element is fast and accurate through the XPath path, the traditional XPath path is from the most original parent level element to the element to be positioned, but because of the characteristic of the mobile terminal, the same app is likely to be different on different types of mobile phones or different systems of the same type of mobile phones, thus the compatibility of the XPath path on the mobile terminal is poor, for example, the element can be found on the mobile phone, and the element cannot be found on another mobile phone.
Disclosure of Invention
The embodiment of the invention provides a method and a device for determining an XPath, which are used for solving the problem of poor compatibility of the XPath on a mobile terminal in the prior art.
In order to solve the technical problem, the invention is realized as follows:
in a first aspect, a method for determining an XPath path is provided, where the method includes:
determining brother elements of the elements to be positioned;
constructing a first XPath path based on the sibling elements;
positioning the element to be positioned according to the first XPath to obtain a first positioning result;
and determining an XPath corresponding to the element to be positioned according to the first positioning result.
Optionally, the determining, according to the first positioning result, an XPath path corresponding to the element to be positioned includes:
and if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath.
Optionally, the determining, according to the first positioning result, an XPath path corresponding to the element to be positioned includes:
if the first positioning result is that a plurality of elements are positioned, acquiring a parent element of the element to be positioned;
constructing a second XPath path based on the parent element;
positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
and determining an XPath corresponding to the element to be positioned according to the second positioning result.
Optionally, the determining, according to the second positioning result, an XPath corresponding to the element to be positioned includes:
and if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath.
Optionally, the determining, according to the second positioning result, an XPath corresponding to the element to be positioned includes:
if the second positioning result is that a plurality of elements are positioned, acquiring a parent element of the parent element;
constructing a third XPath path based on the parent element of the parent element;
positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
and determining an XPath corresponding to the element to be positioned according to the third positioning result.
Optionally, the constructing a first XPath path based on the sibling elements includes:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions and element identification identifications.
Optionally, the XPath path is an XPath path with text attributes; or
The XPath is an XPath without text attributes.
Optionally, the element to be positioned is a control in the application to be tested.
Optionally, before determining the sibling element to be located, the method further includes:
and acquiring and storing all elements in the application to be tested, wherein all elements comprise the element to be positioned and the sibling element.
In a second aspect, an apparatus for determining an XPath path is provided, the apparatus comprising:
the determining module is used for determining brother elements of the elements to be positioned;
a construction module, configured to construct a first XPath path based on the sibling elements;
the positioning module is used for positioning the element to be positioned according to the first XPath to obtain a first positioning result;
and the determining module is further configured to determine, according to the first positioning result, an XPath corresponding to the element to be positioned.
Optionally, the positioning module is configured to:
and if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath.
Optionally, the positioning module includes:
the obtaining submodule is used for obtaining a parent element of the element to be positioned if the first positioning result indicates that a plurality of elements are positioned;
the construction submodule is used for constructing a second XPath path based on the parent-level element;
the first positioning submodule is used for positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
and the determining submodule determines an XPath corresponding to the element to be positioned according to the second positioning result.
Optionally, the first positioning sub-module is configured to:
and if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath.
Optionally, the first positioning sub-module includes:
the obtaining sub-module is further configured to obtain a parent element of the parent element if the second positioning result indicates that the plurality of elements are positioned;
the construction submodule is also used for constructing a third XPath path based on the parent element of the parent element;
the second positioning submodule is used for positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
and the determining submodule is further used for determining an XPath corresponding to the element to be positioned according to the third positioning result.
Optionally, the building module includes:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions and element identification identifications.
Optionally, the XPath path is an XPath path with text attributes; or
The XPath is an XPath without text attributes.
Optionally, the element to be positioned is a control in the application to be tested.
Optionally, before the determining module, the apparatus further includes:
and the acquisition module is used for acquiring and storing all elements in the application to be tested, wherein all elements comprise the elements to be positioned and the sibling elements.
In the embodiment of the invention, the first XPath path is firstly constructed according to brother elements of the elements to be positioned, but not according to parent elements, brother elements or other elements of the elements to be positioned, the elements to be positioned are positioned according to the first XPath path to obtain a first positioning result, and finally, the XPath corresponding to the elements to be positioned is determined according to the first positioning result.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the invention and not to limit the invention. In the drawings:
FIG. 1 is a flow diagram of a method of determining an XPath path, in accordance with an embodiment of the present invention;
FIG. 2 is a schematic diagram of a tree structure of an XPath path of another embodiment of the present invention;
FIG. 3 is a schematic diagram of a tree structure of an XPath path for a further embodiment of the present invention;
FIG. 4 is a schematic diagram of a tree structure of an XPath path for a further embodiment of the present invention;
FIG. 5 is a schematic diagram of a tree structure of an XPath path of another embodiment of the present invention;
FIG. 6 is a code diagram of a method of determining an XPath path, according to one embodiment of the invention;
FIG. 7 is a schematic interface diagram of a control in an application under test according to yet another embodiment of the present invention;
fig. 8 is a schematic structural diagram of an apparatus for determining an XPath path according to still another embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to solve the problem of poor compatibility of the XPath path on the mobile terminal in the prior art, as shown in fig. 1, a method for determining the XPath path is provided, and the method comprises the following steps:
s110, determining brother elements of the elements to be positioned.
In some embodiments, in order to quickly and accurately locate an element to be located, a sibling element of the element to be located is determined first, the determined sibling element is subjected to subsequent processing, instead of determining an initial parent element of the element to be located, the initial parent element is processed to obtain a sibling element of the element to be located, steps of obtaining the sibling element by the initial parent element are omitted, and then the element to be located can be quickly and accurately located through the sibling element.
For example, as shown in fig. 2, assuming that the second element C is an element to be positioned, the remaining elements C are siblings of the element to be positioned, the element B is a parent element of the element C, the element a is a parent element of the element B, and the element a is also an initial parent element of the element C, first determining that the siblings of the element to be positioned are the first element C and the third element C, and waiting for subsequent processing, instead of determining the initial parent element a of the element to be positioned first, obtaining the element B according to the initial parent element a, and finally obtaining the siblings of the element to be positioned as the first element C and the third element C, and waiting for subsequent processing.
And S120, constructing a first XPath path based on the sibling elements.
In some embodiments, the first XPath path is constructed according to the sibling element, the sibling element and the element to be positioned belong to the sibling element, instead of constructing the first XPath path according to the parent element, the sibling element or other elements, and the first XPath path is constructed based on only the sibling element, so that the purpose that the first XPath path is the shortest path is achieved, the stability of the first XPath path is improved, and the compatibility of the first XPath path in the mobile terminal is also improved. That is, the longer the first XPath path is, the lower the stability of the first XPath path is, for example, a slight change in the interface of the mobile terminal may reduce the accuracy of positioning the first XPath path.
In addition, the longer the XPath path is, the lower the stability is, as shown in fig. 2, if the element to be located is the first element C, a variety of XPath paths can be selected, for example, the element a-element B-first element C is located to the first element C through the conventional XPath path, or the element B-first element C is located to the first element C through the XPath path, so that the element to be located can be located for the element B-first element C according to the XPath path regardless of whether the element a and the element B change or other elements are added between the element a and the element B.
As shown in fig. 3, if the element to be located is G, for example, the element a-element B-element E-element G is located to the element G to be located according to the conventional XPath, or the element E-element G is located according to the XPath, so no matter whether the element a, the element B, and the element E are changed or other elements are added between the element a and the element B, and between the element table B and the element E, the element to be located can be located according to the XPath and the element E-element G, that is, the shorter the XPath is, the higher the stability of the XPath is, that is, the stronger the compatibility of the XPath in the mobile terminal is.
S130, positioning the element to be positioned according to the first XPath to obtain a first positioning result.
S140, according to the first positioning result, the XPath corresponding to the element to be positioned.
In some embodiments, the element to be positioned can be quickly and accurately positioned according to the first XPath path to obtain a first positioning result, and the XPath path is obtained according to the first positioning result.
For example, as shown in fig. 4, if the element to be located is the second element D, an XPath is obtained according to the first location result, where the XPath is a prefollowing/D/affluxing/D, that is, it means that an element in front of the element to be located is D, an element behind the element to be located is D, and if the XPath is a unique XPath meeting the above conditions, the XPath is the XPath corresponding to the element to be located, and is also the shortest XPath.
Based on the method, firstly, the first XPath path is built only according to brother elements of the elements to be positioned, but not according to parent elements, brother elements or other elements of the elements to be positioned, secondly, the elements to be positioned are positioned according to the first XPath path, a first positioning result is obtained, and finally, the XPath corresponding to the elements to be positioned is determined according to the first positioning result.
Optionally, the determining, according to the first positioning result, an XPath path corresponding to the element to be positioned includes:
and if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath.
In some embodiments, if the first positioning result is that a unique element is positioned, the element is an element to be positioned, and the XPath corresponding to the element to be positioned is the first XPath.
As shown in fig. 4, if the element to be located is a third element D, the sibling elements of the element to be located are a first element D and a second element D, a first XPath path is constructed based on the first element D and the second element D, the third element D is located based on the first XPath path, so as to obtain a first location result, the first location result is located to the third element D, the XPath path corresponding to the third element D is a first XPath path, the first XPath path indicates that two elements are D in front of the third element D, and no element is behind the third element D, the first XPath path is a unique XPath path meeting the above conditions, and the first XPath path is an XPath path corresponding to the third element D and is also the shortest XPath path.
Optionally, the determining, according to the first positioning result, an XPath path corresponding to the element to be positioned includes:
if the first positioning result is that a plurality of elements are positioned, acquiring a parent element of the element to be positioned;
constructing a second XPath path based on the parent element;
positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
and determining an XPath corresponding to the element to be positioned according to the second positioning result.
In some embodiments, if the first positioning result indicates that the plurality of elements are positioned, it indicates that the element to be positioned is not positioned yet, and the XPath path corresponding to the element to be positioned cannot be determined, first obtain a parent element of the element to be positioned, construct a second XPath path according to the parent element, then position the element to be positioned according to the first XPath path and the second XPath path, obtain a second positioning result, and finally determine the XPath path corresponding to the element to be positioned according to the second positioning result, and so on, until it is determined that the XPath path corresponding to the element to be positioned is the shortest and only XPath path, thereby improving the compatibility of the XPath path at the mobile terminal.
Optionally, the determining, according to the second positioning result, an XPath corresponding to the element to be positioned includes:
and if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath.
In some embodiments, if the second positioning result is that a unique element is positioned, the element is an element to be positioned, and the XPath corresponding to the element to be positioned is a combined path of the first XPath path and the second XPath path.
As shown in fig. 5, if the element to be located is the third element C on the left, the sibling elements of the element to be located are the first element C and the second element C, a first XPath is constructed based on the first element C and the second element C, the first XPath indicates that there are two elements C in front of the element to be located and there is no element behind the element, the third element C is located based on the first XPath to obtain a first location result, the first location result indicates that there are two elements C meeting the above condition, it indicates that there is not yet located the third element C on the left and there is no XPath corresponding to the third element C on the left, then the parent element B of the two third elements C is determined, a second XPath is constructed based on the parent element B, the second XPath indicates that there is no element in front of the parent element B and there are four elements B behind the element B, a second location result is obtained according to the first XPath and the second XPath, the second positioning result positions a unique element, the unique element is a third element C on the left side, and an XPath corresponding to the third element C on the left side is a combined path of the first XPath and the second XPath.
Optionally, the determining, according to the second positioning result, an XPath corresponding to the element to be positioned includes:
if the second positioning result is that a plurality of elements are positioned, acquiring a parent element of the parent element;
constructing a third XPath path based on the parent element of the parent element;
positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
and determining an XPath corresponding to the element to be positioned according to the third positioning result.
In some embodiments, if the second positioning result locates multiple elements, it is described that the element to be positioned is not yet located, and the XPath corresponding to the element to be positioned cannot be determined, first obtaining a parent element of the parent element, constructing a third XPath based on the parent element of the parent element, then positioning the element to be positioned according to the first XPath, the second XPath, and the third XPath, obtaining a third positioning result, and finally determining the XPath corresponding to the element to be positioned according to the third positioning result, if the third positioning result locates a unique element, determining the unique element as the element to be positioned, and determining the XPath corresponding to the element to be positioned as a combined path of the first ath, the second XPath, and the third XPath. Otherwise, if the third positioning result is that multiple elements are positioned, the step executed after the multiple elements are positioned is repeatedly executed, which is not described herein again.
As shown in fig. 5, if the element to be located is the second left element D, the sibling elements of the element to be located are the first element D and the third element D, a first XPath is constructed based on the first element D and the third element D, the first XPath indicates that there is an element D in front of the element to be located and there is an element D behind the element, the second element D is located based on the first XPath to obtain a first location result, the first location result is that there are two elements D meeting the above condition, it is indicated that there is not a second left element D yet located, and there is no XPath corresponding to the second element D yet determined, then the parent element C of the second element D is determined, a second XPath is constructed based on the parent element C, the second XPath indicates that there is no element C in front of the parent element C, and there are two elements C behind the element C, a second location result is obtained according to the first XPath path and the second XPath path, and if the second positioning result is still that two elements D meeting the condition are positioned, determining the parent element B of the two parent elements C again, constructing a third XPath based on the parent element B, wherein the third XPath indicates that no element exists in the front of the parent element B and four elements B exist behind the parent element B, obtaining a third positioning result according to the first XPath, the second XPath and the third XPath, positioning the third positioning result to an unique element, wherein the unique element is a left second element D, and the XPath corresponding to the left second element D is a combined path of the first XPath, the second XPath and the third XPath.
Optionally, the constructing a first XPath path based on the sibling elements includes:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions and element identification identifications.
In some embodiments, it can be known from the foregoing embodiments that the first XPath path is constructed based on sibling elements, and more specifically, the first XPath path is constructed according to identification attribute information of the sibling elements, where the identification attribute information includes an element type class, an element position request, and an element identification id, and in addition, in some cases, the identification attribute information further includes a text of the element, which is not described in detail herein.
Optionally, the element to be positioned is a control in the application to be tested.
In some embodiments, when the element to be located is a control in the application to be tested, as shown in fig. 6, the element to be located is an input control of 12 rows in the application to be tested, and the input control can be found through a conventional XPath path/html/body/div/form/p [1]/input, but if any part in the XPath path changes, the input control cannot be found, but the input control can be found through a first XPath path// p/input [ @ name = 'usrName' ], and various changes in the previous part can be ignored, thereby enhancing the robustness of the XPath path.
Optionally, the XPath path is an XPath path with text attributes; or
The XPath is an XPath without text attributes.
In some embodiments, when the element to be located is a control in the application to be tested, text attributes of some controls may change along with refreshing or version updating, and then the XPath path is an XPath path without text attributes, changes to the text attributes are ignored, text attributes of some controls are fixed, and then the XPath path is an XPath path with text attributes.
When the XPath path is an XPath path with a text attribute, for example, the XPath path with a text attribute is// node [ @ text = 'f775ed6e2ca38254b3ad379239723a' and @ class = 'UIAButton' [ position/5] [ text/discovery ], the resolution is: the text of the parent element is "f 775ed6e2ca38254b3ad379239723 a", a control of type UIAButton, and in the fifth position, the element to be positioned is such a control as "found" as shown in fig. 7.
When the XPath path is an XPath path without a text attribute, for example, the XPath path without a text attribute is// node [ @ class = 'UIAButton' ] position/5] [ text/discovery ], the resolution is: a control whose parent element is of type UIAButton, and such a control at the fifth position whose element to be located is "found".
Optionally, before determining the sibling element to be located, the method further includes:
and acquiring and storing all elements in the application to be tested, wherein all elements comprise the element to be positioned and the sibling element.
In some embodiments, before determining the sibling element to be located, all elements in the application to be detected are obtained and stored, and then the relationship between the elements in the application to be detected is known, where all elements include the element to be located, the sibling element, the parent element, or other elements, which is not described in detail here.
In a second aspect, as an embodiment, as shown in fig. 8, there is provided an apparatus for determining an XPath path, the apparatus 80 including:
a determining module 81, configured to determine a sibling element of an element to be located;
a construction module 82 configured to construct a first XPath path based on the sibling elements;
the positioning module 83 is configured to position the element to be positioned according to the first XPath to obtain a first positioning result;
the determining module 81 is further configured to determine, according to the first positioning result, an XPath corresponding to the element to be positioned.
Optionally, as an embodiment, the positioning module 83 is configured to:
and if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath.
Optionally, as an embodiment, the positioning module 83 includes:
the obtaining submodule is used for obtaining a parent element of the element to be positioned if the first positioning result indicates that a plurality of elements are positioned;
the construction submodule is used for constructing a second XPath path based on the parent-level element;
the first positioning submodule is used for positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
and the determining submodule determines an XPath corresponding to the element to be positioned according to the second positioning result.
Optionally, as an embodiment, the first positioning sub-module is configured to:
and if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath.
Optionally, as an embodiment, the first positioning sub-module includes:
the obtaining sub-module is further configured to obtain a parent element of the parent element if the second positioning result indicates that the plurality of elements are positioned;
the construction submodule is also used for constructing a third XPath path based on the parent element of the parent element;
the second positioning submodule is used for positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
and the determining submodule is further used for determining an XPath corresponding to the element to be positioned according to the third positioning result.
Optionally, as an embodiment, the building module 82 includes:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions and element identification identifications.
Optionally, as an embodiment, the XPath path is an XPath path with a text attribute; or
The XPath is an XPath without text attributes.
Optionally, as an embodiment, the element to be positioned is a control in the application to be tested.
Optionally, as an embodiment, before the determining module 81, the apparatus further includes:
and the acquisition module is used for acquiring and storing all elements in the application to be tested, wherein all elements comprise the elements to be positioned and the sibling elements.
The device provided by the embodiment of the present invention can implement each process implemented in the method embodiments of fig. 1 to fig. 7, and is not described here again to avoid repetition.
While the present invention has been described with reference to the embodiments shown in the drawings, the present invention is not limited to the embodiments, which are illustrative and not restrictive, and it will be apparent to those skilled in the art that various changes and modifications can be made therein without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (3)

1. A method of determining an XPath path, comprising:
determining brother elements of the elements to be positioned;
constructing a first XPath path based only on the sibling elements;
positioning the element to be positioned according to the first XPath to obtain a first positioning result;
determining an XPath corresponding to the element to be positioned according to the first positioning result;
wherein, the determining the XPath corresponding to the element to be positioned according to the first positioning result includes:
if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath;
determining an XPath path corresponding to the element to be positioned according to the first positioning result, including:
if the first positioning result is that a plurality of elements are positioned, acquiring a parent element of the element to be positioned;
constructing a second XPath path based on the parent element;
positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
determining an XPath corresponding to the element to be positioned according to the second positioning result;
determining an XPath corresponding to the element to be positioned according to the second positioning result, including:
if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath;
determining an XPath corresponding to the element to be positioned according to the second positioning result, including:
if the second positioning result is that a plurality of elements are positioned, acquiring a parent element of the parent element;
constructing a third XPath path based on the parent element of the parent element;
positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
determining an XPath corresponding to the element to be positioned according to the third positioning result;
when the element to be positioned is a control in the application to be tested, the text attributes of some controls can change along with refreshing or version updating, so that the XPath is an XPath without text attributes, the change of the text attributes is ignored, the text attributes of some controls are fixed, and the XPath is an XPath with text attributes;
the constructing a first XPath path based on the sibling elements comprises:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions, element identification identifications and text texts of the elements.
2. The method of claim 1, wherein prior to determining sibling elements to be located, the method further comprises:
and acquiring and storing all elements in the application to be tested, wherein all elements comprise the element to be positioned and the sibling element.
3. An apparatus for determining an XPath path, comprising:
the determining module is used for determining brother elements of the elements to be positioned;
a construction module for constructing a first XPath path based only on the sibling elements;
the positioning module is used for positioning the element to be positioned according to the first XPath to obtain a first positioning result;
the determining module is further configured to determine, according to the first positioning result, an XPath corresponding to the element to be positioned;
wherein the positioning module is configured to:
if the first positioning result is that a unique element is positioned, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is the first XPath;
the positioning module includes:
the first obtaining submodule is used for obtaining a parent element of the element to be positioned if the first positioning result indicates that a plurality of elements are positioned;
a first constructing submodule, configured to construct a second XPath path based on the parent element;
the first positioning submodule is used for positioning the element to be positioned according to the first XPath and the second XPath to obtain a second positioning result;
the first determining submodule determines an XPath corresponding to the element to be positioned according to the second positioning result;
the first positioning sub-module is configured to:
if the unique element is positioned according to the second positioning result, determining that the unique element is the element to be positioned, and determining that an XPath corresponding to the element to be positioned is a combined path of the first XPath and the second XPath;
the first positioning sub-module comprises:
the second obtaining sub-module is further configured to obtain a parent element of the parent element if the second positioning result indicates that multiple elements are positioned;
the second constructing submodule is also used for constructing a third XPath path based on the parent element of the parent element;
the second positioning submodule is used for positioning the element to be positioned according to the first XPath path, the second XPath path and the third XPath path to obtain a third positioning result;
the second determining submodule is further used for determining an XPath corresponding to the element to be positioned according to the third positioning result;
when the element to be positioned is a control in the application to be tested, the text attributes of some controls can change along with refreshing or version updating, so that the XPath is an XPath without text attributes, the change of the text attributes is ignored, the text attributes of some controls are fixed, and the XPath is an XPath with text attributes;
the constructing a first XPath path based on the sibling elements comprises:
and constructing a first XPath based on the identification attribute information of the sibling elements, wherein the identification attribute information comprises element types, element positions, element identification identifications and text texts of the elements.
CN201910106725.1A 2019-02-02 2019-02-02 Method and device for determining XPath path Active CN109977267B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910106725.1A CN109977267B (en) 2019-02-02 2019-02-02 Method and device for determining XPath path

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910106725.1A CN109977267B (en) 2019-02-02 2019-02-02 Method and device for determining XPath path

Publications (2)

Publication Number Publication Date
CN109977267A CN109977267A (en) 2019-07-05
CN109977267B true CN109977267B (en) 2021-09-03

Family

ID=67076891

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910106725.1A Active CN109977267B (en) 2019-02-02 2019-02-02 Method and device for determining XPath path

Country Status (1)

Country Link
CN (1) CN109977267B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605675A (en) * 2013-10-30 2014-02-26 北京京东尚科信息技术有限公司 XML (extensive markup language) path expression extracting method and device
CN104657377A (en) * 2013-11-20 2015-05-27 阿里巴巴集团控股有限公司 Multi-channel webpage control positioning method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103605675A (en) * 2013-10-30 2014-02-26 北京京东尚科信息技术有限公司 XML (extensive markup language) path expression extracting method and device
CN104657377A (en) * 2013-11-20 2015-05-27 阿里巴巴集团控股有限公司 Multi-channel webpage control positioning method and device

Also Published As

Publication number Publication date
CN109977267A (en) 2019-07-05

Similar Documents

Publication Publication Date Title
CN108170809B (en) Table building script generation method, device, equipment and computer readable storage medium
CN109460220B (en) Message predefined code generation method and device, electronic equipment and storage medium
CN113190781B (en) Page layout method, device, equipment and storage medium
JP2020187733A (en) Application programming interface documentation annotation
CN111399822B (en) Micro-service development method, device, equipment and computer storage medium
CN108008936B (en) Data processing method and device and electronic equipment
CN108959095B (en) Method for verifying XML document based on XML Schema
CN113094617B (en) Web element positioning method and application and storage medium thereof
CN107347048A (en) The method, apparatus and system of data check
CN108664546B (en) XML data structure conversion method and device
CN104317909A (en) Method and device for verifying data of points of interest
CN110941779A (en) Page loading method and device, storage medium and electronic equipment
US10372760B2 (en) Building queries directed to objects hosted on clouds
CN114707051A (en) Web page similar element searching method and system
CN109977267B (en) Method and device for determining XPath path
CN110007842A (en) Web page contents choosing method and device
CN103500169A (en) File comparison device and file comparison method
CN113157904A (en) Sensitive word filtering method and system based on DFA algorithm
CN110929100B (en) Method and device for acquiring value taking path, storage medium and electronic equipment
CN109474822B (en) Android television multi-language automatic testing method and device
CN110188432B (en) System architecture verification method, electronic device and computer-readable storage medium
CN108196921B (en) Document development method and device, computer equipment and storage medium
CN112784540B (en) Document number checking method and device
CN112597186A (en) Data query method, computer equipment and storage medium
CN113536762A (en) JSON text comparison method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20210716

Address after: 100016 no.4301, No.52 Jiuxianqiao hospital, Chaoyang District, Beijing

Applicant after: BEIJING TESTIN INFORMATION TECHNOLOGY Co.,Ltd.

Address before: Room 2016, building 2, No.8, Fenghuang Third Road, Zhongxin Guangzhou Knowledge City, Guangzhou 510260, Guangdong Province

Applicant before: GUANGZHOU TESTIN INFORMATION TECHNOLOGY Co.,Ltd.

GR01 Patent grant
GR01 Patent grant