Mushishi Selenium2 + Python_5, automatic test pattern

Modular drive test examples P138--
P142-- parametric search keywords
from selenium import webdriver
search_text = [ 'python', 'Chinese', 'text'] # store search keywords
for text in search_text: # for loop to iterate through the array
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("http://www.baidu.com")
driver.find_element_by_id ( 'kw'). send_keys (text) # traversing the array as a key element of every Baidu search
driver.find_element_by_id('su').click()
driver.quit()
P143-- read txt file
read (): read the entire file
readline (): read a line of data
readlines (): read the data for all rows
 
user_info.txt
zhangsan, 123
lysis, 111
 
user_info.py
user_file = open ( 'user_info.txt', 'r') # open the way for reading user_info.txt
lines = user_file.readlines () # read txt file in rows
user_file.close()
 
for line in lines:
username = line.split ( ',') [0] # of each row of the acquired data split () methods for the resolving the user name and password
password = line.split(',')[1]
print(username,password)
P144——读取csv文件
P146——读取xml文件
 

Guess you like

Origin www.cnblogs.com/TomBombadil/p/10977537.html