python关于chromdriver自动化学习(2)

import unittest
import time
from selenium import webdriver
from ddt import data,ddt,unpack
@ddt
class forTestTest(unittest.TestCase):
#类的初始化
# @classmethod
# def setUpClass(cls) -> None:
# print()
# 因为是在函数内执行的浏览器操作,在函数执行完毕之后,程序内所有的步骤都结束了,关于这段程序的进程也就结束了,
# 浏览器包含在内;如果将浏览器全局后,打开浏览器不在函数内部,函数里面的程序执行完是不会关闭浏览器的。
chromedriver = "C:\Program Files\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
# 用例的初始化
def setUp(self):
# driver = webdriver.Chrome()
self.driver.get('http://test.51qdl.com//')
# 最大化窗口
self.driver.maximize_window()
self.driver.find_element_by_link_text('登录').click()
# 获取当前所有页面窗口的句柄
windows = self.driver.window_handles
# 切换至最新打开的窗口
self.driver.switch_to.window(windows[-1])
def tearDown(self):
print(1)
@data(['admin',"Woqu"])
@unpack
def test_one(self,account,psw):
#定位账户名输入框并输入账户名
self.driver.find_element_by_name('username').send_keys(account)
# 定位密码输入框并输入密码
self.driver.find_element_by_name("password").send_keys(psw)
#定位登录按钮并点击
self.driver.find_element_by_xpath('//button[@type="button"]').click()
time.sleep(3)
#相对定位该公众号按钮(需要进一步更新)
self.driver.find_element_by_xpath("//div[@class='name ng-binding']").click()
if __name__ == '__main__':
unittest.main()

部分参考文献:
https://blog.csdn.net/qq_43422918/article/details/97394705
https://www.cnblogs.com/lazy-sang/p/13932749.html
https://www.bilibili.com/video/BV1Qt4y1a74b?t=962&p=11(第十集)
posted @ 2020-12-19 11:31  Fricheer  阅读(99)  评论(0)    收藏  举报