The simplest way to master selenium is to learn by example, and the test examples and analysis of previous projects are given below.
#-*-Coding:utf-8-*-import timefrom Selenium import webdriver# use the Firefox browser to show the effect, creating an instance of Selenium webdriver Driver = webdr Iver. Firefox () #driver. Get method to open test URL 127.0.0.1:8000/chasingsomeonedriver.get (' http://127.0.0.1:8000/ChasingSomeone/') # Maximized screen (except for display with negligible) Driver.maximize_window () Sleep units are calculated in seconds, without adding unit Time.sleep (1) # Find the page element and enter the user name and password, specific find_element_by_* The method will summarize the # Send_keys function to the corresponding page element in the anchor element signin_email = driver.find_element_by_name (' username ') Signin_email.send_keys (" [email protected] ") Signin_password = driver.find_element_by_name (' password ') Signin_password.send_keys (" 123 ") Time.sleep (2) # Find the login buttom and click submit Signin_submit_button = driver.find_element_by_name (' login ') signin_submit_ Button.Click () Time.sleep (2) # Exit Driver.close ()
This is one of the simplest examples of Python selenium, and the added functionality will be based on a simple example of this extension
Then give an example of the official website, you can analyze, analysis can be confirmed by the last officer net, attached link
From selenium import webdriverfrom selenium.webdriver.common.keys import keysdriver = Webdriver. Firefox () driver.get ("http://www.python.org") assert "Python" in Driver.titleelem = Driver.find_element_by_name ("q") Elem.clear () Elem.send_keys ("Pycon") Elem.send_keys (Keys.return) assert "No results found." Not in Driver.page_ Sourcedriver.close ()
Content Reference http://selenium-python.readthedocs.io/installation.html
Selenium python bindings preliminary usage and simple reference examples