In the recent web course design I have come into contact with the Selenium Web Automation test tool, which can be used to navigate to the target element through a series of find_element () methods, and to send an analog key operation to automate the operation.
First, use Pip to install the Selenium Python module.
Here are the routines I wrote. The Find_element_by_name method is to locate the element through the Name property and then send the analog key via Send_keys (). Based on this kind of operation can basically complete a variety of web simulation operations.
Import timefrom Selenium import webdriverfrom selenium.webdriver.common.keys import Keyschrome_driver_path = "/usr/ Local/lib/python2.7/dist-packages/selenium/webdriver/chrome/chromedriver "Driver = webdriver. Chrome (Chrome_driver_path) driver.get ("Http://localhost:8000/") driver.get ("Http://localhost:8000/login") assert " Bookstore "In driver.titleelem_username = Driver.find_element_by_name (" username ") Elem_username.send_keys (" Tiger1 ") Elem_password = driver.find_element_by_name ("password") Elem_password.send_keys ("Tiger1") Elem_password.send_keys ( Keys.return) Time.sleep (5) Driver.close ()
If you encounter the following error
Selenium.common.exceptions.WebDriverException:Message: ' Chromedriver executable needs to being available in the path.
Workaround in Http://selenium-python.readthedocs.org/faq.html#how-to-use-chromedriver
Web Automation test Tool--selenium