Selenium Automated Test Guide for beginners, based on Python (ii)--Automated test Script applet

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.