selenium中,怎么判断是否已选多选框

html文件

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <p>测试勾选</p>
    <div>
        <input type="checkbox" name="bicle" value="bicle">自行车
        <br>
        <input type="checkbox" name="car" value="car" checked> 汽车
    </div>
</body>
</html>

代码

click,点击就能控制是否点击

用 is_selected() 可以判断是否选中

python 复制代码
from selenium import webdriver
import time


# 创建浏览器驱动对象
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()            # 参数写浏览器驱动文件的路径,若配置到环境变量就不用写了
# 访问网址
driver.get("E:\django\接口准备1\多选框.html")


# 点击选择自行车
ele1 = driver.find_element(By.CSS_SELECTOR,'input[name="bicle"]')
ele1.click()

time.sleep(1)

# 点击汽车的选框(点击后会关闭)
ele2 = driver.find_element(By.CSS_SELECTOR,'input[name="car"]')
ele2.click()


print("自行车是否选中", ele1.is_selected())
print("汽车是否选中", ele2.is_selected())






# driver.close()
# driver.quit()         # 这个的效果就是离开整个浏览器
相关推荐
Run Freely9375 小时前
接口测试-postman-全局变量与环境变量
测试工具·postman
我的xiaodoujiao8 小时前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 8--基础知识 4--常用函数 2
前端·python·测试工具·ui
程序员小远11 小时前
常用的测试用例
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
(时光煮雨)12 小时前
【Python进阶】Python爬虫-Selenium
爬虫·python·selenium
依旧很淡定2 天前
Selenium(Python)创建Chrome浏览器实例
chrome·python·selenium
小熊出擊3 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
云闲不收3 天前
接口请求工具对比 apifox apipost swagger postman等
测试工具·postman
sitellla3 天前
Testify Go测试工具包入门教程
git·测试工具·其他·golang
我的xiaodoujiao3 天前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 9--基础知识 5--常用函数 3
前端·python·测试工具·ui
可可南木3 天前
ICT 数字测试原理 8 - -VCL 的测试参数
开发语言·功能测试·测试工具·pcb工艺