The previous section based on Python Selenium automated Testing (i)--element positioning describes the element positioning method, now we can write a simple automated test script applet to practice.
from Seleniumimport webdriver
Driver=webdriver. Chrome ()
Driver.get ("http://www.baidu.com")
driver.find_element_by_id ("kw"). Send_keys ("Selenium2")
driver.find_element_by_id ("su"). Click ()
Driver.quit ()
Here's a brief explanation of the previous code.
(1)from seleniumimportwebdriver
Import the Selenium Webdriver package and only import the Webdriver package to use the Webdriver API for automated scripting development.
(2) Driver=webdriver. Chrome ()
The Webdriver Chrome is assigned to browser, and the browser object is available to start the browser, open the URL, and manipulate the page elements.
(3) Driver.get ("http://www.baidu.com")
After you get the browser object, you can send URLs (URLs) to the browser through the Getting () method.
(4) driver.find_element_by_id ("kw"). Send_keys ("Selenium2")
Through the id=kw positioning to Baidu's input box, and through the keyboard Input Method Send_keys () to the Baidu input box input "Selenium2".
(5) driver.find_element_by_id ("su"). Click ()
Through the ID=SU positioning "Baidu Click" Search button, and to the Search button to send click event clicks ().
(6) Driver.quit ()
Exit and close the window and related drivers.
Save the file as test.py, run the script, will see the script to launch the Chrome browser into Baidu page, enter the "Selenium2" click on the Search button, and finally close the browser process.
The next section is based on Python's Selenium Automation test (iii)--Control browser window size, forward, rewind, refresh we will continue to learn the Selenium automation test about browser operations.
More about Selenium automation test source code, welcome to see my github