import unittest
import time
from selenium import webdriver
class forTestTest(unittest.TestCase):
#类的初始化
# @classmethod
# def setUpClass(cls) -> None:
# print()
#用例的初始化
# def setUp(self):
# print(3)
# def tearDown(self):
# print()
def test_1(self):
#调用chrom驱动
chromedriver = "C:\Program Files\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
# driver = webdriver.Chrome()
#打开目标网页
driver.get('http://test.51qdl.com//')
time.sleep(0.5)
# 最大化窗口
driver.maximize_window()
driver.find_element_by_link_text('登录').click()
time.sleep(1)
# 获取当前所有页面窗口的句柄
windows = driver.window_handles
# 切换至最新打开的窗口
driver.switch_to.window(windows[-1])
#定位账户名输入框并输入账户名
driver.find_element_by_name('username').send_keys("admin")
# 定位密码输入框并输入密码
driver.find_element_by_name("password").send_keys("Woqu")
#定位登录按钮并点击
driver.find_element_by_xpath('//button[@type="button"]').click()
time.sleep(3)
#相对定位该公众号按钮(需要进一步更新)
driver.find_element_by_xpath("//div[@class='name ng-binding']").click()
# time.sleep(0.5)
# driver.find_element_by_link_text("分销设置").click()
time.sleep(3)
# driver.find_element_by_id('su').click()
if __name__ == '__main__':
unittest.main()
部分参考文章:
https://blog.csdn.net/daiyu__zz/article/details/86175177
https://www.cnblogs.com/Zhan-W/p/10777152.html
https://www.cnblogs.com/yhms/p/10728765.html
https://www.bilibili.com/video/BV1xJ411v7Eb?p=2&t=1004