Writing the first Python Selenium program (ii)

Source: Internet
Author: User

The previous section describes how to build a selenium system environment, so this section explains how to start writing the first automated test script.

selenium2.x the browser native API into the Webdriver API, you can directly manipulate the elements of the browser page, and even manipulate the browser itself (screenshots, window size, start, close, install plug-ins, configuration certificates, etc.), so just like the real user in the same operation. In fact, selenium is to simulate the user's behavior, to achieve automated testing.

Then we now implement a Baidu search selenium automated test cases, below our actual test process how to operate.

1. Open the browser;

2. Enter the URL "http://www.baiud.com";

3. Enter selenium within the search box;

4. Click "Baidu" to search selenium related information;

5. Determine if the search results are correct

The above procedure is actually our actual test process operation process, that is, our test cases, below we convert the text into code

#-*-coding:utf-8-*- fromSeleniumImportWebdriverImport Time fromSelenium.common.exceptionsImportNosuchelementexceptiondriver=Webdriver. Chrome () Driver.get ("https://www.baidu.com/")#open Browser, enter URLDriver.maximize_window () search_element= driver.find_element_by_id ('kw')#Position the input box seatSearch_element.send_keys ("Selenium")#Enter search informationButton_element = driver.find_element_by_id ('su')#Locate the Search button's seatButton_element.click ()#Click the Search buttonTime.sleep (1) Driver.save_screenshot ('Baidu.png')#Get search ResultsTime.sleep (1) Driver.quit ()#Close Browser

In this way, we have completed an automated test case to determine whether the result is correct, followed by the explanation of the assertion.

The following section describes how to locate elements.

Writing the first Python Selenium program (ii)

Related Article

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.