自学内容网 自学内容网

Python selenium库学习使用实操四

系列文章目录

Python selenium库学习使用实操
Python selenium库学习使用实操二
Python selenium库学习使用实操三


前言

Python selenium库学习使用实操二中提到了下拉框的操作,一种是标准的select标签,另外一种是非select标签的下拉框,本文主要记录非select标签下拉框的使用。本文以elementui的el-select组件为例。


在这里插入图片描述
在这里插入图片描述

一、元素获取

获取select元素,模拟点击,弹出选择项

try:
           selectElement = _driver.find_element(By.CLASS_NAME,"el-select")
           print(selectElement)
           selectElement.click()
           time.sleep(2)            
        except NoSuchElementException as e:
            print(e)

二、选项解析

查看下拉框选项,其dom结构如下

在这里插入图片描述

    liEleList = _driver.find_elements(By.CLASS_NAME, "el-select-dropdown__item")
    print('li count',len(liEleList))
    # 根据目标内容模拟点击
    driver.find_element("xpath","//span[text()='目标内容']").click()   

总结

`
以上就是下拉选择框的初步探索。


原文地址:https://blog.csdn.net/xs_2012/article/details/142765193

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!