环境:
编辑工具:
浏览器:
有问题可以联系qq:1776376537(html可以加qq要)
# coding:utf-8
#导入包
from common.base import Base
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
#打开浏览器
driver = webdriver.Firefox()
#打开本地html
driver.get("file:///D:/BaiduNetdiskDownload/web%E8%87%AA%E5%8A%A8%E5%8C%96selenium+python/%E8%BD%AF%E4%BB%B6%E5%AE%89%E8%A3%85%E5%8C%85/checkbox.html")
check = Base(driver)
loc1 = ("id","c1")
r1 = check.isSelected(loc1)
print(r1)
che1 = check.click(loc1)
r2 = check.isSelected(loc1)
print(r2)
#全部选中
loc_all = ("xpath",'.//*[@type="checkbox"]')
all = check.findElements(loc_all)
print(all)#list对象
def result(all):
r = []#判断全部被选中
for i in all:
if not i.is_selected():
i.click()
r.append(i.is_selected())#判断结果
else:
r.append(i.is_selected())
return r
# print(result(all))
rrrr = result(all)
print(rrrr)
for i in rrrr:
assert i == True