Selenium ---- Xpath use

Xpath
xpath is an XML Path Language, it is to find a path element by element tag

With tools
can make use Firefox Firebug plugin to practice and Firepath

Xpath positioning method
fixed format: // * [@ attribute name = '']
1.xpath support id, class, name positioning
  by positioning id, such as: // * [@ id = ' i1']
  by targeting class, such as: // * [@ class = 'inner ']
  by positioning name, such as: // * [@ name = ' name']

2.xpath support attribute positioning when no label id, class, when the name three attributes, you can use the property to locate
  @ representative of what property to locate, you can take back any attribute tags, such as: // [@value = 'beijing']

3.xpath label positioning support, when repeated tag attributes, tag can be filtered by
  the tag name * into arbitrary, can be screened according to the label, such as: // input [@ placeholder = 'username']

4.xpath support level filtering
  xpath can / be carried out by levels, the hierarchy found in line with the label, such as: // form / div / input [ @ id = 'inner']
  When the hierarchy is repeated, by single hierarchy positioning properties, such as: // form / div [@ class = 'login_name'] / input

5.xpath support subscript, index positioning, as a brother of an element and its label, this is not through the hierarchy to locate, you can use the subscript to locate
  through the index, locate properties in the list, the index and the python not the same, an XPath index from the start, such as: // select [@ name = ' city'] [1] / option [1]

6.xpath positioning support logic operation: and or or
  to narrow the scope by filtration and, only when the conditions are met in order to locate, such as: // select [@ name = ' city' and @ size = '4']
  by or to filter, as long as there is a match to conform to, such as: // select [@ name = ' city' or @ size = '4']

 

Guess you like

Origin www.cnblogs.com/yttbk/p/11027455.html