码迷,mamicode.com
首页 > 其他好文 > 详细

8.单选框和复选框

时间:2020-06-17 12:49:45      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:自动化   微信   webdriver   xpath   click   单选框   bdr   head   box   

# coding:utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get(r"E:\Selenium\radio_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.单选框和复选框

标签:自动化   微信   webdriver   xpath   click   单选框   bdr   head   box   

原文地址:https://www.cnblogs.com/Tofuir-miss/p/13151568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!