I. Overview
1, in the preparation of functional test cases, assumes an expected result, the actual results obtained are compared with the embodiment in the process of performing the intended result, such a failure is determined by use cases
2, automated test cases to be executed by a machine, the machine does not like people, have generally thinking and judgment, then we would get some information from the page to demonstrate the use case execution success or failure
3, several of the most commonly used authentication information is title, url, text three kinds of text acquired by the user authentication information is a good text
title is to get the title of the current page
current_url is to get the current page url
text is get the text message
Second, exemplified
. 1 from Selenium the webdriver Import
2 Import Time
. 3 DR = webdriver.Chrome ()
. 4 dr.implicitly_wait ( 30 )
. 5 dr.maximize_window ()
. 6 DR. GET ( ' http://www.126.com ' )
. 7
. 8 # Printing current page title
. 9 title = dr.title
10 Print (title)
. 11
12 is # Url print the current page
13 is URL = dr.current_url
14 Print (URL)
15
16 # mailbox login
. 17 name = dr.find_element_by_id ('idInput').clear()
18 name.send_keys('username')
19 pwd=dr.find_element_by_id('pwdInput').clear()
20 pwd.send_keys('password')
21 dr.find_element_by_id('loginBtn').click()
22 time.sleep(3)
23
24 #获取当前用户的text
25 text=dr.find_element_by_id('spnUid').text
26 print(text)
27
28 dr.quit()