python selenium of CSS positioning

ccs advantages: CSS relative xpath syntax than xpath simple positioning speed ratio xpath faster

css disadvantages: css does not support the use of logical operators to locate, and xpath support. css positioning grammatical forms, relative xpath more difficult to remember.

css positioning of the proposed multi-use, this positioning method is very powerful, fast speed and high accuracy positioning. As difficult to remember, cooked just fine for hard working people, this is not a problem.

CSS_selector common symbols:

  #   Represents the id

  .   Represents the class

  >   Represents the child element hierarchy

  

1. By id attribute Location:

find_element_by_css_selector ( "# id attribute values ")

实例:find_element_by_css_selector("#kw")

 

2. By class_name attribute Location:

find_element_by_css_selector ( ". class attribute value ")

实例:find_element_by_css_selector(".s_ipt")

 

3. By targeting other properties:

find_element_by_css_selector ( "[ attribute =" attribute value "]")

find_element_by_css_selector ( "[ attribute = attribute value ]") ---------------- Note that this attribute value is not quoted

实例1find_element_by_css_selector("[name=‘kw’]")

实例2.1find_element_by_css_selector("[style=‘display’]")

Example 2.2 : find_element_by_css_selector ( "[the display style =]") --------- Note that this attribute value is not quoted

Expressly exemplified here twice, it is stressed here plus without quotation marks does not matter, does not affect the position.

 

4. By positioning parent-child relationships:

When unable to obtain information if you do not know someone's identity card number, name, phone number and other contact, but you know someone father's cell phone number, then you can find someone by his father. That is, through ( " His father [phone = phone number ]> I ") to find someone.

When the term is to be replaced when we locate elements found only element of the property value can not identify, then we can consider combined property with his father tags to locate elements. E.g:

find_element_by_css_selector ( "input # id attribute value > lower tag ")

实例:find_element_by_css_selector(“input#kw>div”)

 

5. By positioning grandfather relationship:

If his father did not phone number, then you can look up his grandfather. That is, that is, through ( " his grandfather [phone = phone number ]> his father > I "), to find someone.

When the term is to be replaced when we locate elements found only element property value is not the father of the label can be identified, then we can consider in conjunction with the grandfather label attribute to locate elements. E.g:

Example:

find_element_by_css_selector(“input#kw>div>div#ko”)

Positioning discuz search bar:

find_element_by_css_selector(".wp>div>form>table>tbody>tr>td>input").send_keys(u"郑迎")

find_element_by_css_selector("div.wp>div>form>table>tbody>tr>td>input").send_keys(u"郑迎")

 

Guess you like

Origin www.cnblogs.com/Mr-ZY/p/11696474.html