On the last day of 2014, commemorate it with a short essay.
Often see a classmate said UI Automation test positioning difficult, can not find the north. This is good, positioning is difficult, flexible and complex, requires experience plus technology, but there is writing can be distilled out as a thought to the wider.
Simply put, the UI element positioning idea should look like this:
Boulevard to Jane
The main road to Jane refers to the obvious characteristics of the elements must be used to locate the obvious characteristics. For example has the ID has the name element, does not Shejinqiuyuan, must use the simplest method to locate.
Divide
In general, good HTML code page structure is very clear. Many students in the use of class positioning often find that the page has a lot of the same name class, it is difficult to locate the class you need. This is the time to apply the idea of divide and conquer, that is, divide and conquer. The page is divided into separate areas (a bit like the section in the HTML5) so that each region's class is characteristic, and it's easy to locate it.
From big to small
Similar to the above thought, the first positioning of the larger features of the element, and then to the surface to locate the specific small elements. This is the level of positioning I've been stressing.
as appropriate
Positioning the most afraid of hanging in a tree to die. When you're not working in a way, you need to change the way you do. such as the use of XPath positioning in Firefox is completed, the results went to IE on a variety of wall, this is because the low version of IE XPath support is not good, so some expressions are not recognized. You need to do it in a different way. Another auto-generated XPath is the Devil, don't sell your soul out to the devil.
Static and dynamic combination
Some elements have special properties, but these properties are dynamically variable. I remember that I specifically told this question in the WordPress actual combat. For example, each new article ID is post-(post_id) Form, this time we will find a way to get post_id, and then stitching the string to get the ID of the new article, and then through this ID to locate the element.
Same direction
I remember some students with similar to sizzle and other JS framework combined with Webdriver JS engine to do the element positioning and testing, and then suddenly feel that they force the table, rampant bully thieves. In fact Webdriver now use is also sizzle, inject sizzle actually is not need. But in the same way, as long as the graceful positioning (do not use the machine automatically generated XPath) to the element, all methods and means are equivalent.
UI Automation test Element positioning idea