Python怎么查看ul下有多少li?
发布时间:2026-03-04 22:00:07

selenium库可用于python中获得ul下有多少li。
selenium 它是一个完整的web应用程序测试系统,包括测试的录制(selenium IDE),编写及运行(Selenium Remote Control)并行处理测试(Selenium Grid)。
示例:
fromseleniumimportwebdriver
chrome=webdriver.Chrome()
chrome.get('https://www.bilibili.com')
ul=chrome.find_element_by_xpath('//*[@id="primary_menu"]/ul')
lis=ul.find_elements_by_xpath('li')
len(lis)#有多少li?
lis[-1].text#最后一个li
lis[-1].click()请关注Python自学网了解更多Python知识。
下一篇 python如何关闭文件?
