After selenium actual combat, the menu is added after login, compare whether the first three items in the menu are corresponding content (UI-0101) sharing (White Moon Black Feather website selenium automatic learning)

Insert picture description here

from selenium import webdriver
import time
# 创建 WebDriver 实例对象,指明使用chrome浏览器驱动
wd = webdriver.Chrome(r'D:\tools-work\chromedriver_win32\chromedriver.exe')

wd.implicitly_wait(5)#等待时间 一定要写
# WebDriver 实例对象的get方法 可以让浏览器打开指定网址
wd.get('http://127.0.0.1:8047/mgr/sign.html')

#输入用户名
#输入密码
#点击登录
#登录
wd.find_element_by_id("username").send_keys("byhy")
wd.find_element_by_id("password").send_keys("88888888")

wd.find_element_by_class_name('btn-primary').click() #可以用css  但是css中间有空格的这种 一般是指好几个元素

time.sleep(2)

# 上面2个可以合并成一个  找到span的所有菜单前3项内容
ul = wd.find_elements_by_css_selector('.sidebar-menu span')[:3]
#把列全部取出来
texts = [element.text for element in ul]


#检查菜单
if texts == ['客户', '药品', '订单']:
    print("测试通过")
else:
    print("测试不通过===================")

wd.quit()

Guess you like

Origin blog.csdn.net/weixin_41665637/article/details/112536749