Did the automated test so long, has not combed the element to locate this piece of content, its importance is self-evident. Take advantage of the weekend and have time to comb it.
1, location by ID
Driver.find_element_by_css_selector ("#kw"). Clear ()
Driver.find_element_by_css_selector ("#kw"). Send_keys ("Selenium")
2, through class positioning
Driver.find_element_by_css_selector ("input.bg"). Click ()
When there is a space between the values of class, just add a dot to the middle of the space.
Such as:
Driver.find_element_by_css_selector ("Div.clearfix.oe_login_buttons"). Click ()
3, by attribute positioning
Driver.find_element_by_css_selector ("[placeholder= ' Please enter password ']"). Clear ()
4, through the level of element positioning
Driver.find_element_by_css_selector ("Div.clearfix.oe_login_buttons>button.btn.btn-primary"). Click ()
Often used in the work of the positioning method through the son to find a father, and then find the father's brother. I don't know if CSS can be implemented. Further additions and updates. Anyway, XPath can be implemented.
Finally, a complete code.
From selenium import Webdriver
Import time
Driver=webdriver. Chrome ()
Driver.maximize_window ()
Driver.implicitly_wait (20)
Driver.get ("http://www.***************")
Driver.find_element_by_css_selector ("[name= ' login ']"). Clear ()
Driver.find_element_by_css_selector ("[name= ' login ']"). Send_keys (U "Gorilla")
Driver.find_element_by_css_selector ("[placeholder= ' Please enter password ']"). Clear ()
Driver.find_element_by_css_selector ("[placeholder= ' Please enter password ']"). Send_keys ("13*********")
Driver.find_element_by_css_selector ("Div.clearfix.oe_login_buttons>button.btn.btn-primary"). Click ()
Time.sleep (3)
Driver.quit ()
A: UnitTest frame with selenium tool css_selector positioning.