[ summary of the invention ]
Various aspects of the present disclosure provide a method and an apparatus for positioning a page element, so as to improve efficiency of positioning the page element.
One aspect of the present application provides a method for positioning a page element, including:
determining page elements to be positioned in a target page;
obtaining a path of the page element according to at least one of a generation mode of the ID attribute of the page element, a self-defined attribute of the page element and uniqueness of the CLASS attribute of the page element; wherein,
the custom attribute includes other attributes in addition to the ID attribute and the CLASS attribute.
The above aspect and any possible implementation manner further provide an implementation manner, where obtaining a path of the page element according to at least one of a generation manner of an ID attribute of the page element, a custom attribute of the page element, and a uniqueness of a CLASS attribute of the page element includes:
if the page element contains an ID attribute and the ID attribute of the page element does not contain dynamically changing characters, taking the ID attribute of the page element as a path of the page element;
and if the page element contains the ID attribute and the ID attribute of the page element contains the dynamically changed character, taking the part of the ID attribute of the page element except the dynamically changed character as the path of the page element.
The above aspect and any possible implementation manner further provide an implementation manner, where obtaining a path of the page element according to at least one of a generation manner of an ID attribute of the page element, a custom attribute of the page element, and a uniqueness of a CLASS attribute of the page element includes:
and if the page element does not contain the ID attribute and the page element contains the unique custom attribute, taking the custom attribute as the path of the page element.
The above aspect and any possible implementation manner further provide an implementation manner, where obtaining a path of the page element according to at least one of a generation manner of an ID attribute of the page element, a custom attribute of the page element, and a uniqueness of a CLASS attribute of the page element includes:
if the page element does not contain the ID attribute and the unique custom attribute and the page element contains the unique CLASS attribute, taking the unique CLASS attribute as the path of the page element;
if the page element does not contain an ID attribute and a unique custom attribute, and the page element contains a non-unique CLASS attribute or does not contain a CLASS attribute,
acquiring a previous-level page element of the page element in the target page, wherein the previous-level page element comprises an ID attribute or a unique CLASS attribute, and taking the ID attribute or the unique CLASS attribute of the previous-level page element and the non-unique CLASS attribute or the page tag of the page element as a path of the page element; or
Acquiring at least two upper-level page elements of the page elements in the target page, wherein the upper-level page element at the highest level of the at least two upper-level page elements contains an ID attribute or a unique CLASS attribute, and the other upper-level page elements except the upper-level page element at the highest level of the at least two upper-level page elements do not contain the ID attribute or the unique CLASS attribute, and taking the ID attribute or the unique CLASS attribute of the upper-level page element at the highest level, the page tags of the other upper-level page elements, and the non-unique CLASS attribute of the page elements or the page tags of the page elements as paths of the page elements.
The above aspects and any possible implementation further provide an implementation, if the page element does not contain an ID attribute and a unique custom attribute, and the page element contains a non-unique CLASS attribute or does not contain a CLASS attribute;
acquiring a previous-level page element of the page elements in the target page;
if the upper-level page element contains an ID attribute or a unique CLASS attribute, taking the ID attribute or the unique CLASS attribute of the upper-level page element and the non-unique CLASS attribute or the page tag of the page element as the path of the page element;
if the previous-level page element does not contain the ID attribute or the unique CLASS attribute, sequentially acquiring the previous-level page elements of the previous-level page element until the previous-level page element containing the ID attribute or the unique CLASS attribute is acquired, and taking the ID attribute or the unique CLASS attribute of the previous-level page element, the page tags of the other previous-level page elements, and the non-unique CLASS attribute or the page tags of the page elements as the path of the page elements.
The above aspect and any possible implementation manner further provide an implementation manner, where after obtaining the path of the page element according to at least one of a generation manner of the ID attribute of the page element, a customization attribute of the page element, and a uniqueness of the CLASS attribute of the page element, the method further includes:
establishing a corresponding relation between the target page and the element information of the page elements; wherein the element information includes a name attribute of the page element and a path of the page element.
In another aspect of the present application, there is provided a page element positioning apparatus, including:
the determining unit is used for determining page elements to be positioned in the target page;
the positioning unit is used for acquiring a path of the page element according to at least one item of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element; wherein,
the custom attribute includes other attributes in addition to the ID attribute and the CLASS attribute.
The above-described aspects and any possible implementation further provide an implementation of the positioning unit, which is specifically configured to
If the page element contains an ID attribute and the ID attribute of the page element does not contain dynamically changing characters, taking the ID attribute of the page element as a path of the page element;
and if the page element contains the ID attribute and the ID attribute of the page element contains the dynamically changed character, taking the part of the ID attribute of the page element except the dynamically changed character as the path of the page element.
The above-described aspects and any possible implementation further provide an implementation of the positioning unit, which is specifically configured to
And if the page element does not contain the ID attribute and the page element contains the unique custom attribute, taking the custom attribute as the path of the page element.
The above-described aspects and any possible implementation further provide an implementation of the positioning unit, which is specifically configured to
If the page element does not contain the ID attribute and the unique custom attribute and the page element contains the unique CLASS attribute, taking the unique CLASS attribute as the path of the page element;
if the page element does not contain an ID attribute and a unique custom attribute, and the page element contains a non-unique CLASS attribute or does not contain a CLASS attribute,
acquiring a previous-level page element of the page element in the target page, wherein the previous-level page element comprises an ID attribute or a unique CLASS attribute, and taking the ID attribute or the unique CLASS attribute of the previous-level page element and the non-unique CLASS attribute or the page tag of the page element as a path of the page element; or
Acquiring at least two upper-level page elements of the page elements in the target page, wherein the upper-level page element at the highest level of the at least two upper-level page elements contains an ID attribute or a unique CLASS attribute, and the other upper-level page elements except the upper-level page element at the highest level of the at least two upper-level page elements do not contain the ID attribute or the unique CLASS attribute, and taking the ID attribute or the unique CLASS attribute of the upper-level page element at the highest level, the page tags of the other upper-level page elements, and the non-unique CLASS attribute of the page elements or the page tags of the page elements as paths of the page elements.
The above aspects and any possible implementation further provide an implementation, if the page element does not contain an ID attribute and a unique custom attribute, and the page element contains a non-unique CLASS attribute or does not contain a CLASS attribute; the positioning unit is particularly used for
Acquiring a previous-level page element of the page elements in the target page;
if the upper-level page element contains an ID attribute or a unique CLASS attribute, taking the ID attribute or the unique CLASS attribute of the upper-level page element and the non-unique CLASS attribute or the page tag of the page element as the path of the page element;
if the previous-level page element does not contain the ID attribute or the unique CLASS attribute, sequentially acquiring the previous-level page elements of the previous-level page element until the previous-level page element containing the ID attribute or the unique CLASS attribute is acquired, and taking the ID attribute or the unique CLASS attribute of the previous-level page element, the page tags of the other previous-level page elements, and the non-unique CLASS attribute or the page tags of the page elements as the path of the page elements.
The above-mentioned aspects and any possible implementation further provide an implementation, and the apparatus further includes a establishing unit configured to establish the first connection between the first network and the second network
Establishing a corresponding relation between the target page and the element information of the page elements; wherein the element information includes a name attribute of the page element and a path of the page element.
According to the technical scheme, the page element to be positioned in the target page is determined, the path of the page element is obtained according to at least one of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element, so that the positioning of the page element can be realized, and the path of the page element can be obtained without traversing the DOM tree of the target page step by step.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained according to at least one item of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element, so that the flexibility and the reliability of the positioning of the page element are improved.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained without depending on the DOM tree of the target page, the problem of failure in obtaining the path of the page element caused by the change of the DOM tree of the target page in the prior art can be solved, and the reliability of positioning the page element is improved.
[ detailed description ] embodiments
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. 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 application.
It should be noted that the terminal referred to in the embodiments of the present application may include, but is not limited to, a mobile phone, a Personal Digital Assistant (PDA), a wireless handheld device, a Tablet Computer (Tablet Computer), a Personal Computer (PC), an MP3 player, an MP4 player, and the like.
In addition, the term "and/or" herein is only one kind of association relationship describing an associated object, and means that there may be three kinds of relationships, for example, a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the character "/" herein generally indicates that the former and latter related objects are in an "or" relationship.
Fig. 1 is a schematic flowchart of a method for positioning a page element according to an embodiment of the present application, as shown in fig. 1.
101. And determining page elements to be positioned in the target page.
Specifically, the page element may include, but is not limited to, at least one of the following: text, labels, hyperlinks, buttons, input boxes, and drop-down boxes, which are not limited in this embodiment. This page element is the page element that needs to be located.
Optionally, in a possible implementation manner of this embodiment, in 101, a mouse event of a page element in the target page may be monitored specifically. If a mouse move (hover) event occurs, a page tag corresponding to the mouse move event can be acquired, and then the page element to be positioned can be determined according to the page tag.
It can be understood that, after the page tag corresponding to the mouse-in event is acquired, it is necessary to determine whether the acquired page tag is an HTML root tag. If the acquired page tag is an HTML root tag, namely < HTML > … </HTML >, continuing to monitor the mouse event of the page element in the target page; if the acquired page tag is not the HTML root tag, the page element to be positioned can be determined according to the page tag.
102. And obtaining the path of the page element according to at least one item of the generation mode of the Identification (ID) attribute of the page element, the self-defining attribute of the page element and the uniqueness of the CLASS (CLASS) attribute of the page element.
Wherein,
an ID attribute of a page element for uniquely identifying a page element. The ID attribute may be generated in a static manner or a dynamic manner, which is not particularly limited in this embodiment. The ID attribute generated by adopting a static generation mode contains fixed and unchangeable characters; the ID attributes generated by the dynamic generation method may include not only fixed and unchangeable characters but also dynamically changing characters, such as numbers 0 to 9, or, for example, a special symbol # or x.
The custom attribute includes other attributes besides the ID attribute and the CLASS attribute, for example, a NAME (NAME) attribute, a VALUE (VALUE) attribute, a TITLE (TITLE) attribute, and the like, which is not particularly limited in the present embodiment.
The CLASS attribute of the page element specifies the CLASS name (ClassName) of the page element.
It is understood that the pages referred to in the present application may be Web pages (Web pages) written based on HyperText Markup Language (HTML), and may also be referred to as Web pages.
It should be noted that the execution main bodies of 101 and 102 may be positioning devices, and may be located in a local client to perform offline positioning, or may also be located in a server on a network side to perform online positioning, which is not particularly limited in this embodiment.
It should be understood that the client may be an application installed on the terminal, or may also be a browser, and the positioning device may be a plug-in of the browser, as long as it can realize positioning of the page element to realize an objective existence form of path acquisition of the page element, which is not limited in this embodiment.
By adopting the technical scheme provided by the embodiment, the path of the page element can be obtained without performing step-by-step traversal operation on the DOM tree of the target page, so that all paths from the page element to the root node of the DOM tree do not need to be obtained and are used as the path of the page element.
In this way, the page element to be positioned in the target page is determined, and then the path of the page element is obtained according to at least one item of the uniqueness among the generation mode of the ID attribute of the page element, the custom attribute of the page element and the CLASS attribute of the page element, so that the positioning of the page element can be realized.
Optionally, in a possible implementation manner of this embodiment, in 102, it may be specifically determined whether the page element includes an ID attribute, and if the page element includes the ID attribute, it may be further determined whether the ID attribute of the page element includes a dynamically changing character.
For example, if the page element includes an ID attribute and the ID attribute of the page element does not include dynamically changing characters, the ID attribute of the page element is used as a path of the page element. If the page label is in the form of
<div class="parent">
<div id="child"></div>
</div>
Then, the path of the page element composed of the page tag may be # child, and may also be written in the form of div [ ID = "child" ] or the like, which indicates that the ID attribute is a child page element.
Or, for another example, if the page element includes an ID attribute and the ID attribute of the page element includes a dynamically changing character, a portion of the ID attribute of the page element, other than the dynamically changing character, is used as a path of the page element. Specifically, a regular matching mode may be specifically adopted to filter out the dynamically changing characters in the ID attribute of the page element, and a part of the ID attribute of the page element, except for the dynamically changing characters, is used as a path of the page element. If the page label is in the form of
<input type="text"size="10"name="provideProducts2"value=""class="input-text"id="yui-gen8">
Then the path of the page element composed of the page tag can be input [ ID ^ = yui-gen ], which indicates that the tag in the page element is input, and the ID attribute is beginning with yui-gen.
Optionally, in a possible implementation manner of this embodiment, in 102, it may be specifically determined whether the page element includes an ID attribute, and if the page element does not include an ID attribute, it may be further determined whether the page element includes a unique custom attribute, that is, a custom attribute uniquely identifying one page element.
For example, if the page element does not include an ID attribute and the page element includes a unique custom attribute, the custom attribute is used as a path of the page element. If the page label is in the form of
<input type="text"data-value="company-name">
Then, the path of the page element composed by the page tag may be input [ data-value = "company-name" ].
Optionally, in a possible implementation manner of this embodiment, in 102, it may be specifically determined whether the page element includes an ID attribute, and if the page element does not include an ID attribute, it may be further determined whether the page element includes a unique custom attribute, and if the page element does not include a unique custom attribute, that is, includes a non-unique custom attribute or does not include a custom attribute, it may be determined whether the page element includes a CLASS attribute, and if the page element includes a CLASS attribute, it is further determined whether the CLASS attribute is unique.
For example, if the page element does not include an ID attribute and a unique custom attribute, and the page element includes a unique CLASS attribute, that is, a CLASS attribute that uniquely identifies a page element, the unique CLASS attribute is used as a path of the page element. If the page label is in the form of
<div class="company-name">…</div>
Then, the path of the page element composed by the page tag may be div [ class = "company-name" ].
Or, for another example, if the page element does not include an ID attribute and a unique custom attribute, and the page element includes a unique CLASS attribute or does not include a CLASS attribute, acquiring a previous page element of the page element in the target page, where the previous page element includes an ID attribute or a unique CLASS attribute, and using the ID attribute or the unique CLASS attribute of the previous page element, and the unique CLASS attribute of the page element or a page tag of the page element as a path of the page element. If the page label is in the form of
Then, the path of the page element composed by the page tag a may be div [ id = "search-content" ] div [ class = "span" ], and the path of the page tag a may be div [ id = "search-content" ] div [ class = "span" ] a.
Or, for another example, if the page element does not include an ID attribute and a unique custom attribute, and the page element includes a unique CLASS attribute or does not include a CLASS attribute, at least two upper level page elements of the page element are obtained in the target page, the upper level page element at the highest level of the at least two upper level page elements includes an ID attribute or a unique CLASS attribute, and other upper level page elements except the upper level page element at the highest level of the at least two upper level page elements do not include an ID attribute or a unique CLASS attribute, the ID attribute or the unique CLASS attribute of the upper level page element at the highest level, the page tags of the other upper level page elements, and the non-unique CLASS attribute or the page tags of the page element at the highest level are used as the path of the page element. If the page label is in the form of
Then, the path of the page element composed by the page tag a may be div [ id = "search-content" ] div [ class = "span" ] div a.
Specifically, a top-level page element of the page elements may be obtained in the target page. If the upper-level page element contains an ID attribute or a unique CLASS attribute, taking the ID attribute or the unique CLASS attribute of the upper-level page element and the non-unique CLASS attribute or the page tag of the page element as the path of the page element; if the previous-level page element does not contain the ID attribute or the unique CLASS attribute, sequentially acquiring the previous-level page elements of the previous-level page element until the previous-level page element containing the ID attribute or the unique CLASS attribute is acquired, and taking the ID attribute or the unique CLASS attribute of the previous-level page element, the page tags of the other previous-level page elements, and the non-unique CLASS attribute or the page tags of the page elements as the path of the page elements.
It should be noted that, if a page element, for example, a previous page element or a previous page element of the previous page element includes an ID attribute, it may be further determined whether the ID attribute of the page element includes dynamically changing characters, so as to determine how the ID attribute becomes a part of a path of the page element.
For example, if the ID attribute of the page element does not contain dynamically changing characters, the ID attribute of the page element is used as a part of the path of the page element.
Or, for another example, if the ID attribute of the page element includes dynamically changing characters, a portion of the ID attribute of the page element other than the dynamically changing characters is used as a portion of the path of the page element. Specifically, a regular matching manner may be specifically adopted, where the ID attribute of the page element, except for the dynamically changing character, takes a part of the ID attribute of the page element, except for the dynamically changing character, as a part of a path of the page element.
Optionally, in a possible implementation manner of this embodiment, after 102, a corresponding relationship between the target page and the element information of the page element may be further established; wherein the element information includes a name attribute of the page element and a path of the page element.
Specifically, the obtained path of the page element and the NAME (NAME) attribute of the page element may be stored in a database and associated to the target page by a remote interface call, for example, ajax remote call. The data format of the interface may be, but is not limited to, json (javascript object notification) format, and the like. In the UI test process, the UI script may obtain element information of all page elements in the target page according to a Uniform Resource Locator (URL) of the target page, and further obtain a path of the page element according to a name attribute of the specified page element.
Therefore, if the path of the page element changes, the technical scheme provided by the application can be adopted to obtain the path after the page element changes, and the path contained in the element information of the page element can be directly updated without modifying the UI script, so that the maintenance cost of the UI script is reduced.
In this embodiment, the page element to be positioned in the target page is determined, and then the path of the page element is obtained according to at least one of the generation manner of the ID attribute of the page element, the custom attribute of the page element, and the uniqueness of the CLASS attribute of the page element, so that the positioning of the page element can be realized.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained according to at least one item of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element, so that the flexibility and the reliability of the positioning of the page element are improved.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained without depending on the DOM tree of the target page, the problem of failure in obtaining the path of the page element caused by the change of the DOM tree of the target page in the prior art can be solved, and the reliability of positioning the page element is improved.
It should be noted that, for simplicity of description, the above-mentioned method embodiments are described as a series of acts or combination of acts, but those skilled in the art will recognize that the present application is not limited by the order of acts described, as some steps may occur in other orders or concurrently depending on the application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
Fig. 2 is a schematic structural diagram of a positioning apparatus for a page element according to another embodiment of the present application, as shown in fig. 2. The positioning means of the page element of the present embodiment may include a determination unit 21 and a positioning unit 22.
The determining unit 21 is configured to determine a page element to be located in the target page.
Specifically, the page element may include, but is not limited to, at least one of the following: text, labels, hyperlinks, buttons, input boxes, and drop-down boxes, which are not limited in this embodiment. This page element is the page element that needs to be located.
Optionally, in a possible implementation manner of this embodiment, the determining unit 21 may specifically monitor a mouse event of a page element in the target page. If a mouse move (hover) event occurs, a page tag corresponding to the mouse move event can be acquired, and then the page element to be positioned can be determined according to the page tag.
It can be understood that, after the determining unit 21 obtains the page tag corresponding to the mouse-in event, it needs to determine whether the obtained page tag is an HTML root tag. If the acquired page tag is an HTML root tag, namely < HTML > … </HTML >, continuing to monitor the mouse event of the page element in the target page; if the acquired page tag is not the HTML root tag, the page element to be positioned can be determined according to the page tag.
The positioning unit 22 is configured to obtain a path of the page element according to at least one of a generation manner of the ID attribute of the page element, a custom attribute of the page element, and a uniqueness of the CLASS attribute of the page element.
Wherein,
an ID attribute of a page element for uniquely identifying a page element. The ID attribute may be generated in a static manner or a dynamic manner, which is not particularly limited in this embodiment. The ID attribute generated by adopting a static generation mode contains fixed and unchangeable characters; the ID attributes generated by the dynamic generation method may include not only fixed and unchangeable characters but also dynamically changing characters, such as numbers 0 to 9, or, for example, a special symbol # or x.
The custom attribute includes other attributes besides the ID attribute and the CLASS attribute, for example, a NAME (NAME) attribute, a VALUE (VALUE) attribute, a TITLE (TITLE) attribute, and the like, which is not particularly limited in the present embodiment.
The CLASS attribute of the page element specifies the CLASS name (ClassName) of the page element.
It is understood that the pages referred to in the present application may be Web pages (Web pages) written based on HyperText Markup Language (HTML), and may also be referred to as Web pages.
It should be noted that the positioning device for the page element provided in this embodiment may be located in a local client to perform offline positioning, or may also be located in a server on a network side to perform online positioning, which is not particularly limited in this embodiment.
It should be understood that the client may be an application installed on the terminal, or may also be a browser, and the positioning device may be a plug-in of the browser, as long as it can realize positioning of the page element to realize an objective existence form of path acquisition of the page element, which is not limited in this embodiment.
By adopting the technical scheme provided by the embodiment, the path of the page element can be obtained without performing step-by-step traversal operation on the DOM tree of the target page, so that all paths from the page element to the root node of the DOM tree do not need to be obtained and are used as the path of the page element.
In this way, the page element to be positioned in the target page is determined by the determining unit, and then the positioning unit obtains the path of the page element according to at least one item of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element, so that the positioning of the page element can be realized.
Optionally, in a possible implementation manner of this embodiment, the positioning unit 22 may specifically determine whether the page element includes an ID attribute, and if the page element includes the ID attribute, then may further determine whether the ID attribute of the page element includes a dynamically changing character.
For example, the positioning unit 22 may be specifically configured to use the ID attribute of the page element as the path of the page element if the page element includes the ID attribute and the ID attribute of the page element does not include dynamically changing characters. If the page label is in the form of
<div class="parent">
<div id="child"></div>
</div>
Then, the path of the page element composed of the page tag may be # child, and may also be written in the form of div [ ID = "child" ] or the like, which indicates that the ID attribute is a child page element.
For another example, the positioning unit 22 may be specifically configured to, if the page element includes an ID attribute and the ID attribute of the page element includes a dynamically changing character, use a portion of the ID attribute of the page element, except for the dynamically changing character, as a path of the page element. Specifically, the positioning unit 22 may specifically adopt a regular matching manner to filter out the dynamically changing characters in the ID attribute of the page element, and use a part of the ID attribute of the page element, except for the dynamically changing characters, as the path of the page element. If the page label is in the form of
<input type="text"size="10"name="provideProducts2"value=""class="input-text"id="yui-gen8">
Then the path of the page element composed of the page tag can be input [ ID ^ = yui-gen ], which indicates that the tag in the page element is input, and the ID attribute is beginning with yui-gen.
Optionally, in a possible implementation manner of this embodiment, the positioning unit 22 may specifically determine whether the page element includes an ID attribute, and if the page element does not include the ID attribute, may further determine whether the page element includes a unique custom attribute, that is, a custom attribute uniquely identifying one page element.
For example, the positioning unit 22 may be specifically configured to use the custom attribute as the path of the page element if the page element does not include the ID attribute and the page element includes the unique custom attribute.
If the page label is in the form of
<input type="text"data-value="company-name">
Then, the path of the page element composed by the page tag may be input [ data-value = "company-name" ].
Optionally, in a possible implementation manner of this embodiment, the positioning unit 22 may specifically determine whether the page element includes an ID attribute, and if the page element does not include the ID attribute, further determine whether the page element includes a unique custom attribute, and if the page element does not include the unique custom attribute, that is, includes the non-unique custom attribute or does not include the custom attribute, determine whether the page element includes a CLASS attribute, and if the page element includes the CLASS attribute, then determine whether the CLASS attribute is unique.
For example, the positioning unit 22 may be specifically configured to use the unique CLASS attribute as the path of the page element if the page element does not include the ID attribute and the unique custom attribute, and the page element includes the unique CLASS attribute, that is, the CLASS attribute uniquely identifying one page element. If the page label is in the form of
<div class="company-name">…</div>
Then, the path of the page element composed by the page tag may be div [ class = "company-name" ].
For another example, the positioning unit 22 may be specifically configured to, if the page element does not include an ID attribute and a unique custom attribute, and the page element includes a unique CLASS attribute or does not include a CLASS attribute, obtain a previous page element of the page element in the target page, where the previous page element includes an ID attribute or a unique CLASS attribute, and use the ID attribute or the unique CLASS attribute of the previous page element, and the unique CLASS attribute or the page tag of the page element as the path of the page element. If the page label is in the form of
Then, the path of the page element composed by the page tag a may be div [ id = "search-content" ] div [ class = "span" ], and the path of the page tag a may be div [ id = "search-content" ] div [ class = "span" ] a.
Alternatively, for another example, the positioning unit 22 may be specifically configured to determine that the page element does not include an ID attribute and a unique custom attribute, and the page element contains no unique CLASS attribute or no CLASS attribute, obtaining at least two upper page elements of the page elements in the target page, the upper page element of the highest level of the at least two upper page elements containing an ID attribute or a unique CLASS attribute, the other upper page elements except the highest upper page element of the at least two upper page elements do not include an ID attribute or a unique CLASS attribute, the ID attribute or the unique CLASS attribute of the highest upper page element, the page tags of the other upper page elements, and the non-unique CLASS attribute of the page element or the page tag of the page element as the path of the page element. If the page label is in the form of
Then, the path of the page element composed by the page tag a may be div [ id = "search-content" ] div [ class = "span" ] div a.
Specifically, if the page element does not contain the ID attribute and the unique custom attribute, and the page element contains the unique CLASS attribute or does not contain the CLASS attribute; the positioning unit 22 may be specifically configured to obtain a higher-level page element of the page elements in the target page; if the upper-level page element contains an ID attribute or a unique CLASS attribute, taking the ID attribute or the unique CLASS attribute of the upper-level page element and the non-unique CLASS attribute or the page tag of the page element as the path of the page element; if the previous-level page element does not contain the ID attribute or the unique CLASS attribute, sequentially acquiring the previous-level page elements of the previous-level page element until the previous-level page element containing the ID attribute or the unique CLASS attribute is acquired, and taking the ID attribute or the unique CLASS attribute of the previous-level page element, the page tags of the other previous-level page elements, and the non-unique CLASS attribute or the page tags of the page elements as the path of the page elements.
It should be noted that, if a page element, for example, a previous page element or a previous page element of the previous page element includes an ID attribute, the positioning unit 22 may further determine whether the ID attribute of the page element includes dynamically changing characters, so as to determine how the ID attribute becomes a part of the path of the page element.
For example, the positioning unit 22 may be specifically configured to use the ID attribute of the page element as a part of the path of the page element if the ID attribute of the page element does not include dynamically changing characters.
Or, for another example, the positioning unit 22 may be specifically configured to, if the ID attribute of the page element includes a dynamically changing character, use a portion of the ID attribute of the page element, other than the dynamically changing character, as a part of the path of the page element. Specifically, a regular matching manner may be specifically adopted, where the ID attribute of the page element, except for the dynamically changing character, takes a part of the ID attribute of the page element, except for the dynamically changing character, as a part of a path of the page element.
Optionally, in a possible implementation manner of this embodiment, as shown in fig. 3, the positioning apparatus for page elements provided in this embodiment may further include an establishing unit 31, configured to establish a corresponding relationship between the target page and the element information of the page element; wherein the element information includes a name attribute of the page element and a path of the page element.
Specifically, the establishing unit 31 may specifically store the obtained path of the page element and a NAME (NAME) attribute of the page element in a database through a remote interface call, for example, ajax remote call, and associate the obtained path and NAME attribute with the target page. The data format of the interface may be, but not limited to, json (javascript Object notification) format, etc. In the UI test process, the UI script may obtain element information of all page elements in the target page according to a Uniform Resource Locator (URL) of the target page, and further obtain a path of the page element according to a name attribute of the specified page element.
Therefore, if the path of the page element changes, the technical scheme provided by the application can be adopted to obtain the path after the page element changes, and the path contained in the element information of the page element can be directly updated without modifying the UI script, so that the maintenance cost of the UI script is reduced.
In this embodiment, the determining unit determines the page element to be positioned in the target page, and then the positioning unit obtains the path of the page element according to at least one of the generation manner of the ID attribute of the page element, the custom attribute of the page element, and the uniqueness of the CLASS attribute of the page element, so that the positioning of the page element can be realized.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained according to at least one item of the generation mode of the ID attribute of the page element, the self-defined attribute of the page element and the uniqueness of the CLASS attribute of the page element, so that the flexibility and the reliability of the positioning of the page element are improved.
In addition, by adopting the technical scheme provided by the application, the path of the page element can be obtained without depending on the DOM tree of the target page, the problem of failure in obtaining the path of the page element caused by the change of the DOM tree of the target page in the prior art can be solved, and the reliability of positioning the page element is improved.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to execute some steps of the methods according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.