A method for locating IE browser elements based on CSS selectors

By intercepting mouse events and sorting the same tags, the CSS selector of IE browser elements is extracted, which solves the problem of time-consuming and laborious manual positioning in the existing technology and realizes fast and automatic positioning of IE browser elements.

CN114579025BActive Publication Date: 2024-10-01SHENZHEN QIANHAI HUANRONG LIANYI INFORMATION TECHNOLOGY SERVICES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210205261.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-02
Publication Date
2024-10-01
Estimated Expiration
2042-03-02

AI Technical Summary

Technical Problem

When using the IE browser, the existing technology requires humans to manually view the DOM tree to find the characteristics of page elements, such as element id or className, which makes positioning time-consuming, laborious and not universal.

Method used

By intercepting mouse events, moving the mouse to the page element triggers the WM_MOUSEHOVER event, obtaining the window class name, judging and obtaining the IHtmlDocument2 interface, searching upward for the parent element, sorting the same tags, and extracting the unique CSS selector, thereby realizing the positioning of IE browser elements. .

Benefits of technology

The CSS selector features are automatically extracted through a computer program, which significantly reduces the time for positioning elements in the IE browser, making the operation convenient and fast.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention discloses an IE browser element positioning method based on CSS selector. When the mouse is moved to the form, the WM_MOUSEHOVER event is triggered to obtain the window class name under the current mouse coordinate point; the obtained window class name is judged to be "Internet Explorer_Server", and the COM pointer of the IHtmlDocument2 interface is obtained; the HTML element where the mouse position is located is obtained; the parent element is searched upward to obtain the order of the element with the same label in the child elements of the parent element; all the obtained orders of the element with the same label in the child elements of the parent element are sorted; the CSS selector feature is extracted according to the order, and the unique CSS selector is found to realize the positioning of the IE browser element. The invention obtains the CSS unique selector of the page element in the IE browser under the mouse by moving the mouse, and the positioning operation is convenient and fast.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of computer software, and in particular to an IE browser element positioning method based on CSS selector. Background Art

[0002] When using IE browser, to locate a page element, you often need to manually check the DOM tree to find the element features, such as element ID or className, and use the Javascript native API to locate the element based on the manually identified element ID or className features. This method is often time-consuming and labor-intensive, and is not a universal method.

[0003] Therefore, the prior art has defects and needs to be improved. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide an IE browser element positioning method based on CSS selectors, which can obtain the CSS unique selector of the page element in the IE browser under the mouse by moving the mouse, and reduce the IE browser element positioning time.

[0005] The technical solution of the present invention is as follows: A method for locating an element of an IE browser based on a CSS selector comprises the following steps: Step S1: intercepting a mouse event, and when the mouse is moved to a form, triggering a WM_MOUSEHOVER event, and when responding to and processing the HOVER event, obtaining the window class name under the current mouse coordinate point; Step S2: judging whether the obtained window class name is "Internet Explorer_Server", if yes, proceed to step S3, otherwise return to repeat step S1; step S3: obtain the COM pointer of the IHtmlDocument2 interface according to the window ID value in the window class name; and, obtain the HTML element where the mouse position is located according to the IHtmlDocument2 interface; step S4: according to the HTML element where the mouse position is located, search upward for its parent element, and obtain the ranking of the element with the same tag in the child elements of the parent element; step S5: repeat step 6 until the parent element found has a legal ID value or the tag is; step S6: sort out all the obtained rankings of the element with the same tag in the child elements of the parent element; according to its ranking, extract its CSS selector features, find out its unique CSS selector, and locate the IE browser element according to the CSS selector.

[0006] Applied to the above technical solution, in the IE browser element positioning method based on CSS selector, in the step S1, the mouse event is intercepted by the message interception technology of the windows system.

[0007] Applied to the above technical solution, in the IE browser element positioning method based on CSS selector, in step S6: when sorting all the obtained elements with the same tag in the child elements of the parent element, the sorting is done in a similar format as follows:

[0008] content_left>DIV:nth-of-type(1)>DIV:nth-of-type(1)>DIV:nth-of-type(2), based on its similar format, extract its CSS selector features and find its unique CSS selector.

[0009] The beneficial effects of the present invention are:

[0010] The present invention searches for the parent element of the HTML element where the mouse is located by moving the mouse, obtains the order of the element with the same tag among the child elements of the parent element, and automatically extracts the CSS features of the IE browser element according to the order of the same tag, thereby realizing the positioning of the IE browser element according to the CSS selector, and positioning is performed through a computer program, and the positioning operation is convenient and fast. DETAILED DESCRIPTION

[0011] The following specific embodiments describe the present invention in detail.

[0012] The present embodiment provides an IE browser element positioning method based on CSS selector, and the IE browser element positioning method includes the following steps: Step S1: intercepting mouse events through the message interception technology of the Windows system, after intercepting the mouse events, when the mouse is moved to the form, triggering the WM_MOUSEHOVER event, the IE browser responds to and processes the HOVER event, when responding to and processing the HOVER event, the computer program obtains the window class name under the current mouse coordinate point; wherein, the HOVER event refers to an event that simulates a hover and stop event; when the mouse moves to a matching element, the specified first function number will be triggered; when the mouse moves out of this element, the specified second function will be triggered; and, it will be accompanied by a detection of whether the mouse is still in a specific element, if so, it will continue to maintain the "hover" state without triggering the move-out event.

[0013] After obtaining the window class name under the current mouse coordinate point, proceed to step S2: determine whether the obtained window class name is "Internet Explorer_Server". If so, proceed to step S3, otherwise return to repeat step S1, and continue to execute step S1 to obtain the window class name until the obtained window class name is "Internet Explorer_Server".

[0014] Step S3: Obtain the COM pointer of the IHtmlDocument2 interface according to the window ID value in the window class name; wherein COM is the Component Object Model (COM), which is a set of component object interface standards based on the Windows platform, consisting of a set of construction specifications and a component object library. Component objects do not use methods but use interfaces to describe themselves. An interface is defined as "a set of semantically related functions implemented on an object", and its essence is a set of function pointer tables, each of which must be initialized to point to a specific function body. There is no limit to the number of interfaces implemented by a component object.

[0015] Then, the HTML element where the mouse is located is obtained according to the IHtmlDocument2 interface and its COM pointer.

[0016] And, execute step S4: according to the HTML element where the mouse is located, search upward for its parent element and obtain the order of the element with the same tag among the child elements of the parent element; and step S5: repeat step 6 until the parent element being searched has a legal ID value or tag, then stop searching.

[0017] The last step S6: sort out the order of all the elements with the same tag in the child elements of the parent element; extract the CSS selector features according to the order, find out the unique CSS selector, and locate the IE browser element according to the CSS selector.

[0018] Specifically, in step S6, when sorting all the obtained elements with the same tag in the child elements of the parent element, the sorting is done in a format similar to the following:

[0019] content_left>DIV:nth-of-type(1)>DIV:nth-of-type(1)>DIV:nth-of-type(2), based on its similar format, extract its CSS selector features and find its unique CSS selector.

[0020] Among them, since the elements in the HTML page are controlled by CSS selectors, the CSS selector features of the same tag can be extracted by sorting the elements with the same tag in the child elements of different parent elements, thereby obtaining the unique CSS selector of the IE browser element, and locating the IE browser element through the unique CSS selector; using the CSS selector to locate the IE browser element can be achieved through existing technical means.

[0021] The present invention searches for the parent element of the HTML element where the mouse is located by moving the mouse, obtains the order of the element with the same tag among the child elements of the parent element, and automatically extracts the CSS features of the IE browser element according to the order of the same tag, thereby realizing the positioning of the IE browser element according to the CSS selector, and positioning is performed through a computer program, and the positioning operation is convenient and fast.

[0022] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for locating IE browser elements based on CSS selectors, characterized in that: The steps include: Step S1: intercept mouse events, and when the mouse moves to the form, trigger the WM_MOUSEHOVER event, and when responding to the HOVER event, obtain the window class name under the current mouse coordinate point; Step S2: Determine whether the acquired window class name is "Internet Explorer_Server", if yes, proceed to step S3, otherwise return to repeat step S1; Step S3: obtaining the COM pointer of the IHtmlDocument2 interface according to the window ID value in the window class name; and obtaining the HTML element where the mouse position is located according to the IHtmlDocument2 interface; Step S4: according to the HTML element where the mouse is located, search upwards for its parent element, and obtain the order of the element with the same tag among the child elements of the parent element; Step S5: Repeat step 6 until the parent element to be found has a legal ID value or a tag; Step S6: sorting all the obtained elements with the same tag in the child elements of the parent element; extracting the CSS selector features according to the sorting, finding the unique CSS selector, and locating the IE browser element according to the CSS selector; In the step S1, the mouse event is intercepted by using the message interception technology of the Windows system; In step S6, when sorting all the obtained elements with the same tag in the child elements of the parent element, the elements are sorted into a similar format as follows: content_left>DIV:nth-of-type(1)>DIV:nth-of-type(1)>DIV:nth-of-type(2). According to the similar format, the CSS selector features are extracted. Find its unique CSS selector.