Selenium WebDriver-操作复选框
2024-09-07 19:07:22
#encoding=utf-8
import unittest
import time
import chardet
from selenium import webdriver class VisitSogouByIE(unittest.TestCase): def setUp(self):
#启动IE浏览器
#self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer") def test_operateCheckBox(self):
url = "http://127.0.0.1/test_checkbox.html"
# 访问自定义的html网页
self.driver.get(url)
# 使用xpath定位获取value属性值为'berry'的input元素对象,也就是“草莓”选项
berryCheckBox = self.driver.find_element_by_xpath("//input[@value='berry']")
# 点击选择“草莓”选项
berryCheckBox.click()
# 断言“草莓”复选框被成功选中
self.assertTrue(berryCheckBox.is_selected(), u"草莓复选框未被选中!")
if berryCheckBox.is_selected():
# 如果“草莓”复选框被成功选中,再次点击取消选中
berryCheckBox.click()
# 断言“草莓”复选框处于未选中状态
self.assertFalse(berryCheckBox.is_selected())
# 查找所有name属性值为“fruit”的复选框元素对象,并存放在checkBoxList列表中
checkBoxList = self.driver.find_elements_by_xpath("//input[@name='fruit']")
# 遍历遍历checkBoxList列表中的所有复选框元素,让全部复选框处于被选中状态
for box in checkBoxList:
if not box.is_selected():
box.click()
time.sleep(3) def tearDown(self):
# 退出IE浏览器
self.driver.quit() if __name__ == '__main__':
unittest.main()
最新文章
- [moka同学笔记]六、Yii2.0课程笔记(魏曦老师教程)[徽章气泡]
- jQuery入门教程
- 利用mysql_multi来管理多实例:
- Android系统Surface机制的SurfaceFlinger服务渲染应用程序UI的过程分析
- ABAP 承运路单
- 点击cell弹出一个日期选择器
- VC++中几种字符标志的解释
- 4月1日学习笔记(CSS基础)
- LabVIEW系列——拍振现象重现
- Children of the Candy Corn
- []: secureCRT连接ubuntu问题- The remote system refused the connection
- GO中的数组切片
- c++ 回调函数使用
- 『性能』ServiceStack.Redis 和 StackExchange.Redis 性能比较
- Data Lake Analytics + OSS数据文件格式处理大全
- Java中常用类(包装类扩展知识)
- Redhat 下 XAMPP 安装和部署 DVWA 教程
- PHP源码编译安装
- django博客项目-设置django为中文语言
- 日志收集以及分析:Splunk