TA的每日心情 | 开心 2023-12-6 14:48 |
---|
签到天数: 285 天 连续签到: 1 天 [LV.8]测试军长
|
#python + selenium 程序与数据分离 开端
#userinfo.py 脚本
#!/usr/bin/python3
#coding=utf-8
def fun(un=username,pw=password):
print("success reader username and password!")
return(un,pw)
#login_python_userinfo_biaozhunhua.py 脚本
#!/usr/bin/python3
#coding=utf-8
from selenium import webdriver
import unittest,time
import os
from selenium.webdriver.common.keys import Keys
import userinfo #倒入userinfo.py函数
class login_python_userinfo(unittest.TestCase):
@classmethod
def setUpClass(self):
self.driver = webdriver.Firefox()
driver = self.driver
driver.get("http://www.baidu.com")
time.sleep(2)
print("打开百度网址成功")
driver.maximize_window()
driver.implicitly_wait(30)
def test_login(self):
self.us,self.pw = userinfo.fun()
print(self.us,self.pw)
driver = self.driver
driver.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[3]/a[7]").click()
#try:
#element0 = driver.find_element_by_name("tj_login")
#for ele0 in element0:
#if ele0.is_displayed():
#ele0.click()
#except OSError as err:
# print("OS Error: {0}".format(err))
#except:
# print("click_error or find_name_error")
time.sleep(2)
print("点击登录按钮成功")
time.sleep(1)
driver.find_element_by_id("TANGRAM__PSP_10__footerULoginBtn").click()
print("点击 用户名登录 按钮")
time.sleep(1)
driver.find_element_by_id("TANGRAM__PSP_10__userName").send_keys(self.us)
driver.find_element_by_id("TANGRAM__PSP_10__password").send_keys(self.pw)
time.sleep(2)
driver.find_element_by_id("TANGRAM__PSP_10__submit").click()
print("登录成功")
time.sleep(5)
@classmethod
def tearDownClass(self):
self.driver.quit()
if __name__=='__main__':
unittest.main()
|
|