Web automation Framework Lazyui User's Manual (3)--a single XPath crawl plugin (selenium element fetch, there is no request!) )

Source: Internet
Author: User
Tags manual file upload unique id xpath
Overview

A previous blog post roughly describes the first demo based on Lazyui, which describes the design and use of this tool in detail.

element Get plugin : Lazyui Elements Extractor, as a chrome plugin, used to crawl common controls on a page (either batch or single fetch), to get the XPath of the frame and three uniquely positioned controls on which the control is located , and generates Java code based on the Lazyui framework to solve the problem of fetching complex elements.
Download: http://download.csdn.net/detail/kaka1121/9571942 Drag-and-drop install to Chrome to right-click

Tool Origin:

Familiar with the control to get the students know that selenium webdriver positioning elements There are about eight ways to see:

http://blog.csdn.net/kaka1121/article/details/51850881

The first seven ways can be attributed to the seventh, that is, the use of XPath, and element positioning related to the XPath syntax, see:

http://blog.csdn.net/kaka1121/article/details/51811296

Element acquisition, one of the most important things in web-side automation, takes up about 3 of the work, and element positioning can be attributed to XPath acquisition.

Therefore, how to obtain a stable XPath with uniquely positioned elements becomes a priority in Web automation.

The acquisition of XPath, under careful summary and scrutiny, can be replaced with tools, and with good front-end testability (unique ID, etc.), can greatly simplify the work of web automation.

Tool design ideas: 1. The type of control the tool needs to crawl:

There are probably several common controls:

① input box (contains input area)

② button

③ drop-down menu

④ Radio Box

⑤ check box

⑥ links (text and pictures)

⑦ Standard Form

⑧ Standard Calendar

⑨ Text Area

⑩ standard File Upload

Can be further abstracted into the following eight kinds of controls, and provide their corresponding common methods:

1. Enter the control ① and provide the method:

Tap, empty, enter, get text

2. Click on the control ②⑥ to provide the method:

Click

3. Drop-down CONTROL ③, provide method:

Selected according to the displayed text (visibletext), selected according to the displayed text, checked according to the sequence number, reversed by the ordinal, selected based on value (value), all selectable, get all options, clear as the initial state

4. Click the control ④⑤ to provide the method:

Tick, uncheck, check to see if the tick is selected

5. Table Control ⑦, provides methods:

Get the text value of all cells, get the text value of a column cell in a row, get the table size & number of rows & columns

6. Calendar control ⑧, provides methods:

Clears the date, enters the date, gets the current input date text

7. Text control ⑨, providing methods:

Get text, click

8. Upload the control ⑩ and provide the method:

Uploading files

2. Individual controls get the requirements:

By right-clicking on a control, you can get up to three relative XPath that uniquely locates the element and mark it as one of the 8 abstract controls above. The name of the control node that can be crawled:

Input (type== "text", "Submit", "button", "Reset", "image", "checkbox", "Radio", "File")
TextArea, select, table, A, button, Span, img, I, font, div

corresponding to the 8 types of controls abstracted above, the following figure:

Crawl Priority & Strategy

As shown in the figure above:

1. If an ID exists and is unique, the ID is used directly, and its XPath is:

input[@id = ' main ')

2. Second, if name exists and is unique, the name is used directly, and its XPath is:

a[@name = ' name ']

3. Again, if text is present and unique, it is directly in text and its XPath is:

Span[contains (Text (), ' AAA ')

4. If there is no unique location, and the name, text, and the combination can be uniquely positioned, then its XPath is similar:

select[@name = ' name ' and contains (text (), ' AAA ')

5. If it cannot be uniquely positioned, then try "value", "title", "Class", "style", and then its XPath is similar if it can be positioned by its unique location:

xxx[@class (or value, title, style) = ' class '

6. If you cannot locate it yet, recursively look for its parent node (look at ID, name, text, title) until it finds a unique one.

Then, starting with its parent node, take the absolute path (element index), add it to the unique location, and its XPath is similar:

input[@id = ' main ']/div[1]/span[2]

Of course, this should start with the development of testability, add unique ID, name and so on.

7. If you cannot find a unique location, look for all of its child nodes (look at ID, name, text, title) until it finds a unique one.

Then use its child node XPath to uniquely locate its XPath similar to the following:

input[@id = ' main ']/parent::xxx 8. If you can't locate it yet, look for all of its sibling nodes (look at the ID, name, text, title), and index itself in the sibling node until it finds a unique one.

input[@id = ' main ']/parent::xxx/xx[3]

9. The above is not satisfied, then give its absolute path (element index), to uniquely locate, its XPath similar:

/XXX[1]/XX[2]/X[5]/XXXXX[2]

3. Example:

Right-click

Fetch Result:

As shown in the figure above, Baidu homepage-"Baidu a bit" button for the grab object, grabbed out of the three can be uniquely positioned XPath as shown in Figure ③.

In addition, the plugin also crawls the control's frame (①), where there is no frame information.

As shown in ② above, the control is recognized as the Click Class and provides a "click" method.

As shown in ④ above, the control is named "Su" and is called with the name, with the note "Su" (⑤) as the description of the control.

Click "Generate Code"

Generate framework-based code in:

@Xpath (xpath={"//input[@id = ' su ']", "//input[contains (@value, ' Baidu Bit ')]", "//input[contains (@class, ' BG S_BTN Btnhover ')] "})
@Frame (frame= "")
@Description (description= "su")
Public Click su;

With the framework, the control can be clicked.



This is what a single crawl is all about, and for bulk crawls, click:

Web automation Framework Lazyui User's Manual (4)--Control Grabber elements Extractor detailed (bulk fetch)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.