A, Python environment to build and selenium
① Download python: HTTPS: //www.python.org/
② install python and configuration environment variable: D: \ Python34
③ download pip: HTTPS: //pypi.python.org/pypi/pip
④cmd run into the extraction path pip : Python setup.py install
⑤ pip configuration environment variable: D: \ Python34 \ Scripts
⑥cmd run into the extraction path pip: pip install -U selenium # install pip
Second, the use of selenium webdirver browser module operates
Note: You need to install the browser version corresponding driver driving
webdriver: from selenium import webdriver # Import
b = webdriver.Chrome () # open Chrome
b.get ( 'http://www.baidu.com') # open Baidu
b.title # title until the current page 'Baidu 'in b.title
b.current_url # get current web page url' baidu 'in b.current_url
ele.clear () # empty value
ele.send_keys (arg) # input value
b.back () # fallback
ele.get_attribute ( arg)
Two, the webdriver browser module operation: positioning element
b.find_element_by_link_text (arg) # Gets the element according to the label text
b.find_element_by_partial_link_text (arg) # get fuzzy query according to the label text element
b.find_element_by_css_selector () # get elements based on css path
xpath positioned elements:. / // .. @id count () loval-name ()
b.find_element_by_xpath ( '/ HTML / body / form / input') #form all the input elements
b.find_element_by_xpath ( '/ html / body / form / input [1]') # according to the following standard positioning one input
Second, the mouse and keyboard to simulate user behavior
① introducing ActionChains: Import from selenium.webdriver.common.action_chains ActionChains
② for generating the simulated user behavior: ActionChains (Driver)
③ execution memory behavior: Perform ()
④ Example: driver.find_element_by_link_text ELE = (Arg)
ActionChains (Driver). move_to_element (ele) .perform ()
Second, the multi-window switch
d.window_handles # all open windows
d.switch_to_window (d.window_handles [1]) # The subscript target window