HTML源码:

<!DOCTYPE html>
<div lang="en"></div></div>
<head>
<meta charset="UTF-8">
<title>多选文本框</title>
</head>
<body>
<from>
<input type="radio" name="fruit" value="berry" />草莓</input>
<br/>
<input type="radio" name="fruit" value="watermelon" />西瓜</input>
<br/>
<input type="radio" name="fruit" value="orange" />橙子</input>
</from>
</body>
</html>

python+selenium源码:

from selenium import webdriver
import unittest
import time class LianXi_test(unittest.TestCase): def setUp(self):
self.driver = webdriver.Chrome()
self.url = r"E:\python\demo\Xpath\demo1.html"
self.driver.implicitly_wait(10)
self.driver.maximize_window() def test_get(self):
# ger自己的html网页
self.driver.get(self.url)
# 使用Xpath定位获取Value属性值为'berry'的input元素对象,也就是草莓选项
i = self.driver.find_element_by_xpath("//input[@value='berry']")
i.click()
time.sleep(1)
self.assertTrue(i.is_selected(), "草莓单选框未被选中") if i.is_selected(): # 果草莓单选项被成功选中,重新选择西瓜
o = self.driver.find_element_by_xpath("//input[@value='watermelon']")
o.click()
time.sleep(1)
# 选择西瓜后,断言草莓选项是否处于未选中状态
self.assertFalse(i.is_selected()) p = self.driver.find_elements_by_xpath("//input[@name='fruit']") for u in p:
time.sleep(1)
if u.get_attribute("value") == "orange":
time.sleep(1)
if not u.is_selected():
u.click()
time.sleep(1)
self.assertEqual(u.get_attribute("value"), "orange") def tearDown(self):
self.driver.quit() if __name__ == "__main__":
unittest.main()

selenium之复选框操作的更多相关文章

  1. python selenium单/复选框操作

    一.单选:radio 1.首先是定位选择框的位置 2.定位id,点击图标就可以了,代码如下(获取url地址方法:把上面源码粘贴到文本保存为.html后缀后用浏览器打开,在浏览器url地址栏复制出地址就 ...

  2. python之tkinter使用-复选框操作

    # tkinter复选框操作 import tkinter as tk root = tk.Tk() root.title('问卷调查') root.geometry('220x80') # 设置窗口 ...

  3. C#:复选框操作类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  4. JS及Dom练习 | 模态对话框及复选框操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Selenium之勾选框操作

    勾选框操作:       所谓勾选框,意思是可以勾选一个及以上或全部勾选.勾选框的图标一般都是方形的. 复选框勾选一般分为三种情况: ①勾选单个框,我们直接用元素定位的方式定位到点击即可. ②勾选多个 ...

  6. DataGridView 复选框 操作大全

    DataGridViewCheckBoxColumn dtCheck = new DataGridViewCheckBoxColumn(); dtCheck.DataPropertyName = &q ...

  7. seleniumu 3.0复选框操作(定位一组元素)

    一般验证复选框是否可以选择点击常用到定位一组元素去循环遍历执行点击事件.但是有时候在不同的浏览器下可能会存在差异化的最终结果. 目前谷歌浏览器常常存在多次点击同一复选框,导致最终最后两项复选框均未被勾 ...

  8. 【jQuery】对于复选框操作的attr与prop

    这个是在jQuery1.6版本号之后出现的鬼东西.受影响的主要有下拉列表select与复选框checkbox.众所周知.在jQuery中能够用attr()取出节点的属性,然而对于checkbox却不是 ...

  9. jQuery——复选框操作

    学习jQuer对表单.表格操作的过程中,按照书上的例子发现一个问题: <!DOCTYPE html> <html> <head> <title>复选框应 ...

随机推荐

  1. ARTS打卡计划第二周-Algorithm

    665. 非递减数列  https://leetcode-cn.com/problems/non-decreasing-array/ 给定一个长度为 n 的整数数组,你的任务是判断在最多改变 1 个元 ...

  2. 安装 mongo 4.0

    Centos 使用yum安装MongoDB 4.0 1.配置MongoDB的yum源 创建yum源文件: #touch /etc/yum.repos.d/mongodb-org-4.0.repo 添加 ...

  3. Node.js的内存问题

    v8堆内存限制默认是1GB,所以可能成为瓶颈. 但是Buffer的内存不受限制,而且可以开多个Nodejs实例然后通过代理进行负载均衡,不过不知道这样效果怎么样呢? 但是基本上应该内存的话不会成为单实 ...

  4. mysql-----04 多表查询

    本节主要介绍mysql的多表查询(多表连接查询.复合条件查询.子查询) 一.多表连接查询 #重点:外链接语法 select 字段列表 from 表1 inner|left|right join 表2 ...

  5. vue环境项目启动后因为eslint语法限制报错

    报错太多,截取了一部分. 解决方法找到项目根目录的build 找到webpack.base.conf.js 打开js文件找到下图的位置 再重新启动项目就好了

  6. innodb 关键特性(insert buffer)

    一.insert buffer 性能改善 insert buffer和数据页一样,也是物理页的一个组成部分. 在innodb存储引擎中,主键是行唯一的标识符.通常应用程序中行记录的插入顺序是按照主键递 ...

  7. pwnable.kr-flag-witeup

    嗯,看到提示,需要逆向哦. 欧克,运行flag,看到打印了一句话I will malloc() and strcpy the flag there. take it. IDA看看程序逻辑,shift+ ...

  8. ThinkPHP3.2 --- 中文乱码问题

    在thinkphp中初次运行时 会出现中文乱码问题,解决方法也很简单 只需要在入口文件index.php加上这段代码即可: <?php header("Content-Type: te ...

  9. 010Edit手写PE

    前言PE结构DOS头IMAGE_DOS_HEADERPE头介绍总大小[248字节]结构体含义标记(4字节)0x4550文件头(20字节)扩展头(224字节)为程序添加ExitProcess函数 前言 ...

  10. Linux驱动之LCD驱动编写

    在Linux驱动之内核自带的S3C2440的LCD驱动分析这篇博客中已经分析了编写LCD驱动的步骤,接下来就按照这个步骤来字尝试字节编写LCD驱动.用的LCD屏幕为tft屏,每个像素点为16bit.对 ...