Web page element positioning method and device, electronic equipment and storage medium
By analyzing test cases and generating content trees, combined with preset bit components, the problem of restricted element positioning in traditional web automation tests is solved, more efficient and accurate Web page element positioning is achieved, and the automated test process is optimized.
Patent Information
- Application Number
- CN202510139813.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-08
- Publication Date
- 2025-05-13
AI Technical Summary
The existing Web automation testing methods are based on traditional element positioning methods, and there are problems such as limited element positioning scenarios, high learning costs and poor maintainability.
By analyzing test cases, key information about web page elements is obtained, content tree is generated based on the web page source code, and preset bit components (text and picture components) are used for positioning to achieve accurate positioning of text and picture elements.
The Web page element positioning process is optimized, the positioning accuracy and efficiency is improved, the workers are repetitive operations are reduced, and the maintenance of Web automation testing is improved.
Smart Images

Figure CN119988232A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of automated testing technology, and in particular to a method, device, electronic device, and storage medium for locating elements on a Web page. Background Art
[0002] In the context of the current rapidly developing software industry, companies are using a lot of new front-end technologies when building web pages.
[0003] Commonly used Web automation testing methods are often based on traditional element positioning methods, such as Selenium and Appium. However, most of the traditional element positioning methods have shortcomings such as limited element positioning scenarios, high learning costs for positioning methods, and poor maintainability. Summary of the invention
[0004] The embodiments of the present application provide a method, device, electronic device, and storage medium for locating a Web page element to optimize the process of locating a Web page element.
[0005] The present application embodiment adopts the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides a method for locating a web page element, wherein the method comprises:
[0007] Parse the test cases to obtain key information of Web page elements;
[0008] Generate content tree based on Web page source code;
[0009] If the key information type is text, then obtaining a text element positioning result in the Web page by using a preset first positioning component according to the content tree;
[0010] If the key information type is a picture, a preset second positioning component is used to obtain a positioning result of the picture element in the Web page.
[0011] In some embodiments, if the key information type is text, a text element positioning result in the Web page is obtained by using a preset first positioning component according to the content tree.
[0012] According to the path of the text element in the key information, searching the content tree for the root node of the path;
[0013] The root node is used as the root node of the search, and the keywords to be searched are obtained from the key information to obtain the text element positioning result in the Web page.
[0014] In some embodiments, if the key information type is a picture, using a preset second positioning component to obtain a positioning result of a picture element in a Web page includes:
[0015] Segment the image according to the image elements in the key information, and identify whether there is text in each segmented image;
[0016] If yes, then use the text extraction algorithm to extract the text for comparison;
[0017] If not, a Gaussian filter is used to generate a group of images with the same image resolution from high to low, and the original image recognition algorithm is used to compare them one by one to obtain the image element positioning result in the Web page.
[0018] In some embodiments, generating a content tree based on a Web page source code includes:
[0019] Based on the Web page source code, the elements whose element contents are not empty and the content and tags of the elements in the Web page are extracted, and organized into a tree diagram according to the nested relationship of the codes to generate the content tree.
[0020] In some embodiments, the parsing of the test case to obtain key information of the Web page element includes:
[0021] The test case is parsed to obtain a web page element containing any one or more key information of the path of the page where the action is located, the specific content of the action, and the object of the action practice.
[0022] In some embodiments, the parsing of the test case to obtain key information of the Web page element includes:
[0023] The part of the key information that belongs to the picture is extracted, and the picture file is searched in the local picture folder to obtain the Web page element that converts the key information into image information.
[0024] In some embodiments, the method further comprises:
[0025] Parse and obtain each test step in the test case, and parse the test step into four elements including path, action, scope, and object;
[0026] According to the keywords of the objects in the test case and the checkpoint, the test case is converted into a tuple pair consisting of path, action, scope, and object.
[0027] In a second aspect, an embodiment of the present application further provides a Web page element positioning device, wherein the device comprises:
[0028] Parsing module, used to parse test cases and obtain key information of Web page elements;
[0029] Content tree generation module, used to generate content tree based on Web page source code;
[0030] A first component module, configured to obtain a text element location result in a Web page by using a preset first location component according to the content tree when the key information type is text;
[0031] The second component module is used to obtain the positioning result of the picture element in the Web page by using the preset second positioning component when the key information type is a picture.
[0032] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor; and a memory arranged to store computer executable instructions, wherein the executable instructions, when executed, cause the processor to perform the above method.
[0033] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, which stores one or more programs. When the one or more programs are executed by an electronic device including multiple application programs, the electronic device executes the above method.
[0034] At least one of the above technical solutions adopted in the embodiments of the present application can achieve the following beneficial effects: parsing test cases, obtaining key information of Web page elements, and generating a content tree based on the Web page source code. For scenarios where the key information type is text, a preset first positioning component is used according to the content tree to obtain the positioning result of text elements in the Web page. For scenarios where the key information type is an image, a preset second positioning component is used to obtain the positioning result of image elements in the Web page. Through the above methods, the positioning results of text elements in the Web page and / or the positioning results of image elements in the Web page are obtained respectively, which can meet the needs of Web page element positioning, optimize the Web automated testing process, and reduce workers' repeated operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0036] Figure 1 A schematic diagram of the process of locating a Web page element in an embodiment of the present application;
[0037] Figure 2 This is a schematic diagram of the structure of a Web page element positioning device in an embodiment of the present application;
[0038] Figure 3 This is a schematic diagram of the structure of an electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in combination with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.
[0040] Commonly used Web automation testing methods are often based on traditional element positioning methods, such as selenium and appium. However, with the popularity of react and vue, and the emergence of component libraries such as element and antd, the traditional element positioning method has the following shortcomings:
[0041] (1) The element positioning scenario is limited. In some cases, the use of traditional positioning methods (such as id, class, tag, etc.) may not be able to accurately find the target element, resulting in positioning failure.
[0042] (2) The learning cost of positioning methods is high. Traditional positioning methods require writing complex codes, including selectors, DOM traversal, etc., which increases development difficulty and maintenance costs.
[0043] (3) As for the poor maintainability, the code of the traditional positioning method is usually complex and difficult to maintain, thus increasing the maintenance cost of the code.
[0044] In addition, XPath is also widely used for locating web page elements. XPath (XML Path Language) is a language for finding information in XML documents. It can be used to traverse elements and attributes in XML documents. XPath positioning is commonly used in crawlers and automated testing. It selects nodes in XML documents by using path expressions. The main disadvantages of XPath are as follows:
[0045] (1) XPath does not adapt well to page changes. Once the page structure changes, the path written in XPath becomes invalid and the script must be re-edited. The pages of the front-end of the constantly iterating project will inevitably change frequently, resulting in a lot of maintenance work on the script.
[0046] (2) XPath expressions are relatively complex, and the learning cost is high for inexperienced people. The use of XPath requires testers to be familiar with the relevant syntax of the XML language, and cannot express their own needs in a way close to actual natural language. Once written, error troubleshooting also requires a lot of energy from testers.
[0047] (3) The image recognition in the existing Airtest platform has problems such as low text recognition efficiency and high recognition error rate caused by differences in image resolution.
[0048] In view of the above-mentioned shortcomings, an embodiment of the present application provides a method that adapts to the complex and changeable scenarios of Web page positioning and can help users quickly and accurately locate Web page elements in different scenarios.
[0049] The technical solutions provided by various embodiments of the present application are described in detail below in conjunction with the accompanying drawings.
[0050] The present application embodiment provides a method for locating a Web page element, such as Figure 1 As shown, a schematic diagram of the flow chart of the method for locating a Web page element in an embodiment of the present application is provided, and the method at least includes the following steps S110 to S140:
[0051] Step S110, parsing the test case to obtain key information of the Web page elements.
[0052] A test case is a set of test inputs, execution conditions, and expected results compiled for a specific purpose to verify whether a specific software requirement is met. By analyzing the test case, you can obtain the purpose, process, and expected results of software testing.
[0053] By extracting key information from the test case steps, we can clarify the key content to be done in each step of the test case, which mainly includes the path of the page where the test case action is located, the specific content of the test case action, and the object of the test case action practice.
[0054] Furthermore, keywords are extracted from the test case, and it is determined whether the keywords appear on the page in the form of graphics or text. If it is a graphic, the image found by the keyword is passed to the next module. If it is text, the keyword is passed to the next module.
[0055] Step S120: Generate a content tree based on the Web page source code.
[0056] Identify the types of functional elements on a web page, such as search boxes, tables, pie charts, etc. And express the functional nesting relationship of the entire web page in the form of a tree diagram, which can facilitate the subsequent search and positioning of keywords. Generate a content tree based on the source code of the web page, and express the internal component structure and content of the page in a tree structure to facilitate subsequent retrieval and search.
[0057] It should be noted that when searching, matching is mainly based on the element label expression pattern of common components (filter boxes, tables, input boxes, buttons, pie charts).
[0058] Step S130: If the key information type is text, a preset first positioning component is used according to the content tree to obtain a text element positioning result in the Web page.
[0059] The "preset first positioning component" is used to locate text-type keywords. When locating text, the element content is screened through the content tree, which can be mainly divided into single element content matching and multiple matching situations.
[0060] Step S140: If the key information type is a picture, a preset second positioning component is used to obtain a positioning result of the picture element in the Web page.
[0061] The "preset second positioning component" is used to handle the situation where the keyword to be identified is an image. This part mainly improves the image recognition process and algorithm based on the existing Airtest platform.
[0062] It should be noted that Airtest is a cross-platform UI automation testing framework based on image recognition, supporting platforms such as Windows, Android and iOS. The Airtest framework is based on a graphical scripting language Sikuli. After referencing this framework, you no longer need to write code line by line. You can capture pictures of buttons or input boxes and use pictures to form test scenarios.
[0063] Through the above method, first, the test case is read to parse the specific test steps into a tuple containing key information. Then, the web page source code is read to parse the front-end code into a content tree containing information such as page nesting structure, page element set, and element relative position. Finally, according to the content in the test step information tuple, the tuple position in the front-end code is searched on the content tree to complete the positioning work. And if the image needs to be located, the Airtest platform image recognition algorithm is used for positioning.
[0064] Through the above method, the test case is parsed to obtain the key information of the Web page elements, and a content tree is generated based on the Web page source code. For the scenario where the key information type is text, the preset first positioning component is used according to the content tree to obtain the text element positioning result in the Web page. For the scenario where the key information type is a picture, the preset second positioning component is used to obtain the picture element positioning result in the Web page. Through the above method, the text element positioning result in the Web page and / or the picture element positioning result in the Web page are obtained respectively, which can meet the needs of Web page element positioning, optimize the Web automated testing process, and reduce workers' repeated operations.
[0065] Different from the problem of XPath's poor adaptability to page changes in related technologies, this method obtains key information of Web page elements by parsing test cases; generates a content tree based on the Web page source code; and enables the content tree to dynamically parse the web page.
[0066] Different from the related technologies, XPath, which is a positioning method strongly related to page code, generates a content tree based on the Web page source code, extracts relevant information of key functional components in the front-end page as the content tree, and uses the content tree as the page positioning search data structure to improve the indexing efficiency of key information.
[0067] Different from the related art, the image recognition in the Airtest platform has the problems of low text recognition efficiency and large recognition error rate caused by differences in image resolution. The improved Airtest image recognition solves the problems of low text recognition efficiency and large recognition error rate caused by image resolution.
[0068] In one embodiment of the present application, if the key information type is text, a preset first positioning component is used according to the content tree to obtain the text element positioning result in the Web page, and according to the path of the text element in the key information, the root node of the path is retrieved in the content tree; the root node is used as the search root node, and the keywords to be searched in the key information are obtained to obtain the text element positioning result in the Web page.
[0069] Based on the text positioning component, the text type keywords are positioned. When positioning text, the element content is screened through the content tree. It is mainly divided into single matching and multiple matching of element content.
[0070] First, define the range of elements to be found.
[0071] In this step, the path calculated from the key information extracted from the test case is obtained, and the path is retrieved in the content tree established when the content tree is generated to obtain the root node of the search path.
[0072] Second, find the exact element location.
[0073] In this step, the root node obtained in the scope of the element to be searched is used as the root node of the search, and the object parsed in the key information extracted from the test case is obtained to determine the keywords to be searched. If there are multiple keywords in the approximate range defined in the scope of the element to be searched, the distance between the object and multiple keywords is calculated, and the positioning element with a closer distance is selected.
[0074] In one embodiment of the present application, if the key information type is a picture, a preset second positioning component is used to obtain the positioning result of the picture element in the Web page, including: segmenting the image according to the picture elements in the key information, and identifying whether there is text in each segmented image; if yes, using a text extraction algorithm to extract the text for comparison; if not, using a Gaussian filter to generate a group of images with the same image resolution from high to low, and using the original image recognition algorithm to compare them one by one to obtain the positioning result of the picture element in the Web page.
[0075] Based on the image positioning component, it is used to handle the situation where the keyword to be recognized is an image. The main improvement is to improve the image recognition process and algorithm on the Airtest platform. The existing Airtest platform has the following two problems: (1) The resolution and size of the image have a great impact on the recognition result; (2) For mixed images of graphics and text, it is still regarded as a simple image, and the general image matching algorithm is used, which reduces the efficiency and success rate of recognition.
[0076] In response to the above two problems: improve the existing image recognition algorithm process of the Airtest platform, add text recognition function, and make up for the low efficiency of the original system in image and text mixed image recognition. At the same time, use Gaussian low-pass filter to gradually reduce the image resolution, generate a group of images with the same image resolution from high to low, and compare them one by one to reduce the problem of low recognition rate caused by image resolution difference.
[0077] First, we detect whether there is text in the image to be matched. This part first segments the image, and then uses the text recognition algorithm to identify whether there is text in each sub-image. Since most of the text on the web page uses standard printed fonts, the experimental results show that the recognition success rate is 10% higher than that of pure images.
[0078] Then, the text content is recognized, and the position of the image to be recognized is determined by searching the content tree based on the recognized text. If the text appears in many positions, the image recognition algorithm continues to recognize.
[0079] Finally, we identify the image based on its content and add a Gaussian filter to the original image recognition algorithm of the Airtest platform. We gradually reduce the image pixels and generate a group of images with the same resolution from high to low. We compare them one by one to reduce the problem of reduced recognition rate caused by differences in image resolution.
[0080] Preferably, the main steps of Gaussian filtering are as follows: use a Gaussian filter to smooth the image; downsample the smoothed image, and the downsampling factor is usually ; continue to perform the same operation on the resulting image, and repeat this step multiple times. After each cycle, a smaller, smoother, and lower-resolution image will be obtained.
[0081] In one embodiment of the present application, generating a content tree based on a Web page source code includes: based on the Web page source code, extracting elements whose element contents are not empty in the Web page and the content and tags of the elements, and organizing them into a tree diagram according to the nested relationship of the code to generate the content tree.
[0082] The goal of generating a content tree is to identify the types of functional elements on the page, such as search boxes, tables, pie charts, etc. The functional nesting relationship of the entire page is expressed in the form of a tree diagram. The content tree can facilitate the subsequent search and positioning of keywords. Since the positions of some page elements will change randomly, the content tree needs to be rebuilt if the page is refreshed.
[0083] The specific process of generating a content tree is to extract elements whose content is not empty in a Web page, extract the content and tags of the elements, and organize them into a tree diagram according to the nested relationship of the code. It is mainly divided into at least three steps:
[0084] S1, generate page tree.
[0085] The HTML code of the web page itself is arranged in a tree structure. This step simplifies the nodes of the tree structure into core key-value pairs consisting of <element tag, element content, absolute path>.
[0086] S2, page tree pruning.
[0087] Delete some nodes in the tree that are not used to display specific content on the page. When pruning, it is mainly processed according to the type of element tags. Tags that are used to identify styles and do not involve key content will be deleted.
[0088] For example, the label is <style>,<code>等类型的键值对。这里对页面树进行减枝主要是为了更加明晰的体现页面关键内容之间的包含关系和依赖关系,方便转化为内容树。可以理解,上述页面树减枝仅为举例,并不用于限定本申请实施例中的保护范围。
[0089] S3,生成内容树。
[0090] 将页面的内部组件结构和内容用树形结构的方式表达出来,方便后续检索和查找。这里查找主要是根据常用组件的元素标签表达模式进行匹配。常用元素包括但不限于:筛选框、表格、输入框、按钮、饼图等。总结常用元素的表达模式,通过模式进行匹配,将内容标签换成具体的元素类型。
[0091] 在本申请的一个实施例中,所述解析测试用例,得到Web页面元素的关键信息,包括:解析所述测试用例,得到包含动作所在页面的路径,动作具体内容以及动作实践的对象中任意一种或多种关键信息的Web页面元素。
[0092] 提取关键信息,主要从测试用例步骤提取关键信息,明确用例每个步骤中要做的关键内容,主要包括动作所在页面的路径,动作具体内容和动作实践的对象。
[0093] 在本申请的一个实施例中,所述解析测试用例,得到Web页面元素的关键信息,包括:提取所述关键信息中属于图片的部分,并在本地图片文件夹中查找对图片文件,得到将关键信息转变为图像信息的Web页面元素。
[0094] 将关键信息映射为图片,完成部分文字形式关键字到图片的映射。由于系统中很多关键字在页面并非以文字出现,而是以图片形式出现。比如"帮助”图标,提取关键字中属于图标的部分,在图标文件夹中查找对应图标文件,将文字信息转变为图像信息。
[0095] 在本申请的一个实施例中,所述方法还包括:解析得到所述测试用例中的每个测试步骤,并将所述测试步骤解析成包含路径、动作、范围、对象的四个元素;根据测试用例和检查点中的所述对象的关键字,将测试用例转换成由路径、动作、范围、对象组成的元组对。
[0096] 完成上面的要求需要从测试用例设计层面加以规范,具体规则如下:
[0097] 规则1,解析测试用例中的每个步骤,将测试步骤解析成为"路径”、"动作”、"范围”、"对象”四个元素。其中"路径”表示本条测试步骤所处的页面路径,帮助后续程序查找到测试步骤所处的页面。"动作”表示测试步骤中的谓语,例如点击,筛选这样的动作。"对象”表示动作的客体,即谁承受这个动作,比如某个筛选框。"范围”表示对象的修饰语,比如某些筛选动作的条件。规则2,在测试用例编写时"路径”、"动作”、"范围”、"对象”这四个元素使用不同的方式进行标记。规则3,提取用例和检查点中的"对象”作为关键字。规则4,根据上述规则,将测试用例转换成由"路径”-"动作”-"范围”-"对象”组成的元组对。
[0098] 本申请实施例还提供了Web页面元素定位装置200,如图2所示,提供了本申请实施例中Web页面元素定位装置的结构示意图,所述Web页面元素定位装置200至少包括:解析模块210、内容树生成模块220、第一组件模块230以及第二组件模块240,其中:
[0099] 在本申请的一个实施例中,所述解析模块210具体用于:解析测试用例,得到Web页面元素的关键信息。
[0100] 测试用例是为某个特殊目标而编制的一组测试输入、执行条件以及预期结果,用于核实是否满足某个特定软件需求。通过解析测试用例,可以获取软件测试的目的、过程以及预期结果。
[0101] 通过从测试用例步骤提取得到的关键信息,可以明确测试用例的每个步骤中要做的关键内容。即主要包括测试用例的动作所在页面的路径,测试用例的动作具体内容以及测试用例的动作实践的对象。
[0102] 进一步地,从测试用例中提取关键字,并判断关键字是以图形还是以文字的形式出现在页面上。如果是图形,则向下个模块传入关键字查找到的图片。如果是文字,则向下个模块传入关键字。
[0103] 在本申请的一个实施例中,所述内容树生成模块220具体用于:基于Web页面源码,生成内容树。
[0104] 识别Web页面上的功能元素种类,比如搜索框,表格,饼图等。并将整个Web页面的功能嵌套关系以树形图的方式表达出来,可以方便后续关键字的查找与定位。根据Web页面源码生成得到内容树,将页面的内部组件结构和内容用树形结构的方式表达出来,方便后续检索和查找。
[0105] 需要注意的是,在查找时主要是根据常用组件(筛选框、表格、输入框、按钮、饼图)的元素标签表达模式进行匹配。
[0106] 在本申请的一个实施例中,所述第一组件模块230具体用于:如果所述关键信息类型为文字,则根据所述内容树采用预设第一定位组件得到Web页面中文字元素定位结果。
[0107] "预设第一定位组件”用于对文字类型的关键字进行定位。文字定位时通过内容树进行元素内容的筛查,主要可以分成元素内容单一匹配和多匹配的情况。
[0108] 在本申请的一个实施例中,所述第二组件模块240具体用于:如果所述关键信息类型为图片,则采用预设第二定位组件得到Web页面中图片元素定位结果。
[0109] "预设第二定位组件”用于处理待识别关键字是图像的情况。这部分主要在现有Airtest平台的基础上对图像识别的流程和算法加以改进。
[0110] 需要注意的是,Airtest是一个跨平台的、基于图像识别的UI自动化测试框架,支持平台有Windows、Android和iOS。Airtest框架基于一种图形脚本语言Sikuli,引用该框架后,不再需要逐行写代码,通过截取按钮或输入框的图片,用图片组成测试场景。
[0111] 能够理解,上述Web页面元素定位装置,能够实现前述实施例中提供的Web页面元素定位方法的各个步骤,关于Web页面元素定位方法的相关阐释均适用于Web页面元素定位装置,此处不再赘述。
[0112] 图3是本申请的一个实施例电子设备的结构示意图。请参考图3,在硬件层面,该电子设备包括处理器,可选地还包括内部总线、网络接口、存储器。其中,存储器可能包含内存,例如高速随机存取存储器(Random-Access Memory,RAM),也可能还包括非易失性存储器(non-volatile memory),例如至少1个磁盘存储器等。当然,该电子设备还可能包括其他业务所需要的硬件。
[0113] 处理器、网络接口和存储器可以通过内部总线相互连接,该内部总线可以是ISA(Industry Standard Architecture,工业标准体系结构)总线、PCI(PeripheralComponent Interconnect,外设部件互连标准)总线或EISA(Extended Industry StandardArchitecture,扩展工业标准结构)总线等。所述总线可以分为地址总线、数据总线、控制总线等。为便于表示,图3中仅用一个双向箭头表示,但并不表示仅有一根总线或一种类型的总线。
[0114] 存储器,用于存放程序。具体地,程序可以包括程序代码,所述程序代码包括计算机操作指令。存储器可以包括内存和非易失性存储器,并向处理器提供指令和数据。
[0115] 处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行,在逻辑层面上形成Web页面元素定位装置。处理器,执行存储器所存放的程序,并具体用于执行以下操作:
[0116] 解析测试用例,得到Web页面元素的关键信息;
[0117] 基于Web页面源码,生成内容树;
[0118] 如果所述关键信息类型为文字,则根据所述内容树采用预设第一定位组件得到Web页面中文字元素定位结果;
[0119] 如果所述关键信息类型为图片,则采用预设第二定位组件得到Web页面中图片元素定位结果。
[0120] 上述如本申请图1所示实施例揭示的Web页面元素定位装置执行的方法可以应用于处理器中,或者由处理器实现。处理器可能是一种集成电路芯片,具有信号的处理能力。在实现过程中,上述方法的各步骤可以通过处理器中的硬件的集成逻辑电路或者软件形式的指令完成。上述的处理器可以是通用处理器,包括中央处理器(Central ProcessingUnit,CPU)、网络处理器(Network Processor,NP)等;还可以是数字信号处理器(DigitalSignal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。可以实现或者执行本申请实施例中的公开的各方法、步骤及逻辑框图。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合本申请实施例所公开的方法的步骤可以直接体现为硬件译码处理器执行完成,或者用译码处理器中的硬件及软件模块组合执行完成。软件模块可以位于随机存储器,闪存、只读存储器,可编程只读存储器或者电可擦写可编程存储器、寄存器等本领域成熟的存储介质中。该存储介质位于存储器,处理器读取存储器中的信息,结合其硬件完成上述方法的步骤。
[0121] 该电子设备还可执行图1中Web页面元素定位装置执行的方法,并实现Web页面元素定位装置在图1所示实施例的功能,本申请实施例在此不再赘述。
[0122] 本申请实施例还提出了一种计算机可读存储介质,该计算机可读存储介质存储一个或多个程序,该一个或多个程序包括指令,该指令当被包括多个应用程序的电子设备执行时,能够使该电子设备执行图1所示实施例中Web页面元素定位装置执行的方法,并具体用于执行:
[0123] 解析测试用例,得到Web页面元素的关键信息;
[0124] 基于Web页面源码,生成内容树;
[0125] 如果所述关键信息类型为文字,则根据所述内容树采用预设第一定位组件得到Web页面中文字元素定位结果;
[0126] 如果所述关键信息类型为图片,则采用预设第二定位组件得到Web页面中图片元素定位结果。
[0127] 本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
[0128] 本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和 / 或方框图来描述的。应理解可由计算机程序指令实现流程图和 / 或方框图中的每一流程和 / 或方框、以及流程图和 / 或方框图中的流程和 / 或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的装置。
[0129] 这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能。
[0130] 这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的步骤。
[0131] 在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入 / 输出接口、网络接口和内存。
[0132] 内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和 / 或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
[0133] 计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
[0134] 还需要说明的是,术语"包括”、"包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句"包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
[0135] 本领域技术人员应明白,本申请的实施例可提供为方法、系统或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
[0136] 以上所述仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。< / style>
Claims
1. A method for locating a web page element, wherein: The method comprises: Parse the test cases to obtain key information of Web page elements; Generate content tree based on Web page source code; If the key information type is text, then obtaining a text element positioning result in the Web page by using a preset first positioning component according to the content tree; If the key information type is a picture, a preset second positioning component is used to obtain a positioning result of the picture element in the Web page.
2. The method of claim 1, wherein: If the key information type is text, a preset first positioning component is used according to the content tree to obtain a text element positioning result in the Web page, According to the path of the text element in the key information, searching the content tree for the root node of the path; The root node is used as the root node of the search, and the keywords to be searched are obtained from the key information to obtain the text element positioning result in the Web page.
3. The method of claim 2, wherein if the key information type is a picture, using a preset second positioning component to obtain a positioning result of the picture element in the Web page comprises: Segment the image according to the image elements in the key information, and identify whether there is text in each segmented image; If yes, then use the text extraction algorithm to extract the text for comparison; If not, a Gaussian filter is used to generate a group of images with the same image resolution from high to low, and the original image recognition algorithm is used to compare them one by one to obtain the image element positioning result in the Web page.
4. The method of claim 1, wherein: The generating of the content tree based on the Web page source code includes: Based on the Web page source code, the elements whose element contents are not empty and the content and tags of the elements in the Web page are extracted, and organized into a tree diagram according to the nested relationship of the codes to generate the content tree.
5. The method of claim 1, wherein: The test case is parsed to obtain key information of the web page elements, including: The test case is parsed to obtain a web page element containing any one or more key information of the path of the page where the action is located, the specific content of the action, and the object of the action practice.
6. The method of claim 1, wherein: The test case is parsed to obtain key information of the web page elements, including: The part of the key information that belongs to the picture is extracted, and the picture file is searched in the local picture folder to obtain the Web page element that converts the key information into image information.
7. The method according to claim 5, further comprising: Parse and obtain each test step in the test case, and parse the test step into four elements including path, action, scope, and object; According to the keywords of the objects in the test case and the checkpoint, the test case is converted into a tuple pair consisting of path, action, scope, and object.
8. A Web page element positioning device, wherein: The device comprises: Parsing module, used to parse test cases and obtain key information of Web page elements; Content tree generation module, used to generate content tree based on Web page source code; A first component module, configured to obtain a text element location result in a Web page by using a preset first location component according to the content tree when the key information type is text; The second component module is used to obtain the positioning result of the picture element in the Web page by using the preset second positioning component when the key information type is a picture.
9. An electronic device, comprising: processor; as well as A memory arranged to store computer executable instructions, which when executed cause the processor to perform the method of any one of claims 1 to 7.
10. A computer-readable storage medium storing one or more programs, which, when executed by an electronic device including a plurality of application programs, causes the electronic device to execute any one of the methods of claims 1 to 7.