一、通过txt文件引入用户名密码
1 #coding=utf-8
2 from selenium import webdriver
3 #from selenium.common.exceptions import NosuchElementException
4 import unittest,os,time
5
6 source=open("F:\\script\\py_scripts\\login_parameter\\username.txt","r")#用户名文件
7 un = source.read()#读取用户名
8 source.close()
9
10 source2=open("F:\\script\\py_scripts\\login_parameter\\password.txt","r")#用户名文件
11 pw = source2.read()#读取用户名
12 source2.close()
13
14 def login():
15 #driver=self.driver
16 #driver.maximize_window()
17 driver.find_element_by_id("username").clear()
18 driver.find_element_by_id("username").send_keys(un)
19 print(un)
20 driver.find_element_by_id("password").clear()
21 driver.find_element_by_id("password").send_keys(pw)
22 print(pw)
23 driver.find_element_by_id("loginbtn").click()
24 time.sleep(3)
25
26 driver=webdriver.Chrome()
27 driver.get("http://cloud.pingnanlearning.com/test/login/index.php")
28 login()
二、通过字典引入用户名密码
login_parameter.py
1 #coding=utf-8
2 from selenium import webdriver
3 #from selenium.common.exceptions import NosuchElementException
4 import unittest,os,time
5 import userinfo
6 '''
7 source=open("F:\\script\\py_scripts\\login_parameter\\username.txt","r")#用户名文件
8 un = source.read()#读取用户名
9 source.close()
10
11 source2=open("F:\\script\\py_scripts\\login_parameter\\password.txt","r")#用户名文件
12 pw = source2.read()#读取用户名
13 source2.close()
14 '''
15 def login(un,pw):
16 driver.find_element_by_id("username").clear()
17 driver.find_element_by_id("username").send_keys(un)
18 print(un)
19 driver.find_element_by_id("password").clear()
20 driver.find_element_by_id("password").send_keys(pw)
21 print(pw)
22 driver.find_element_by_id("loginbtn").click()
23 time.sleep(3)
24
25 info=userinfo.zidian()
26 for un,pw in info.items():
27 driver=webdriver.Chrome()
28 driver.get("http://cloud.pingnanlearning.com/test/login/index.php")
29 login(un,pw)
1 #userinfo.py
2 def zidian():
3 data={'candy':'1','candy1':'1'}
4 print("success reader username and password!")
5 return data