8.单选框和复选框

Posted tofuir-miss

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8.单选框和复选框相关的知识,希望对你有一定的参考价值。

# coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get(r"E:Selenium adio_checkbox.html")
# 没点击操作前,判断选项框状态
s = driver.find_element_by_id("boy").is_selected()
print(s)
driver.find_element_by_id("boy").click()
# 点击后,判断元素是否为选中状态
r = driver.find_element_by_id("boy").is_selected()
print(r)
time.sleep(3)
# 复选框单选
driver.find_element_by_id("c1").click()
# 复选框全选
checkboxs = driver.find_elements_by_xpath(".//*[@type=‘checkbox‘]")
for i in checkboxs:
i.click()

# html示例代码
# < html >
# < head >
# < meta
# http - equiv = "content-type"
# content = "text/html;charset=utf-8" / >
# < title > 单选和复选 < / title >
# < / head >
# < body >
#
# < / form >
# < h4 > 单选:性别 < / h4 >
# < form >
# < label
# value = "radio" > 男 < / label >
# < input
# name = "sex"
# value = "male"
# id = "boy"
# type = "radio" > < br >
# < label
# value = "radio1" > 女 < / label >
# < input
# name = "sex"
# value = "female"
# id = "girl"
# type = "radio" >
# < / form >
#
# < h4 > 微信公众号:从零开始学自动化测试 < / h4 >
# < form >
# < !-- < label
# for ="c1" > checkbox1 < / label > -->
# < input
# id = "c1"
# type = "checkbox" > selenium < br >
# < !-- < label
# for ="c2" > checkbox2 < / label > -->
# < input
# id = "c2"
# type = "checkbox" > python < br >
# < !-- < label
# for ="c3" > checkbox3 < / label > -->
# < input
# id = "c3"
# type = "checkbox" > appium < br >
#
# < !-- < form >
# < input
# type = "radio"
# name = "sex"
# value = "male" / > Male
# < br / >
# < input
# type = "radio"
# name = "sex"
# value = "female" / > Female
# < / form > -->
#
# < / body >
# < / html >

以上是关于8.单选框和复选框的主要内容,如果未能解决你的问题,请参考以下文章

纯css3单选框和复选框样式美化效果

Selenium2+python自动化19-单选框和复选框

Selenium2+python自动化19-单选框和复选框

Selenium2+python自动化19-单选框和复选框(radioboxcheckbox)

章节十5-单选框和复选框

Selenium2+python自动化19-单选框和复选框(radioboxcheckbox)转载