Python+selenium之获取文本值和下拉框选择数据
Python+selenium之获取文本值和下拉框选择数据
一、结合实例进行描述
1. 实例如下所示:
#新增标签操作
def func_labels(self):
self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='业务管理']").click()
time.sleep(1)
self.driver.find_element_by_xpath("//*[@class='menu-text'][text()='打标签']").click()
time.sleep(1)
self.driver.find_element_by_id("btn-addTag").click()#点击【新增标签】按钮
time.sleep(1)
self.driver.execute_script("$('#tag_receivingId_flexselect').blur();$('#tag_receivingId option:eq(2)').attr('selected',true).change();ecui.form.flexSelect('#tag_receivingId');")#运用js来下拉选择数据(隐藏属性)
#time.sleep(1)
self.driver.execute_script("$('#tag_senderId option:eq(1)').attr('selected',true).change()")#下拉框选中发货方
#time.sleep(1)
self.driver.find_element_by_id('tag_totalCnt').send_keys(3)#填写货品件数
#time.sleep(1)
self.driver.execute_script("$('#tagDetail_prod option:eq(1)').attr('selected',true).change()")#下拉选择“货品信息”
#time.sleep(1)
self.driver.find_element_by_id('tagDetail_prodCount').send_keys(5)#填写数量值
#time.sleep(1)
self.driver.find_element_by_xpath("//button[@data-bb-handler='success']").click()#点击【保存】按钮
#self.driver.find_element_by_xpath("//button[@class='btn btn-purple ehkey-saveAndPrint']").click()#点击【保存并打印】按钮
# < div
# id = "hid_new_tagno"
# style = "display: none" >
#
# < / div >
ls=self.driver.execute_script('return $("#hid_new_tagno").text();')#运用JS来获取内容值
time.sleep(2)
# 参考http://blog.csdn.net/eastmount/article/details/48108259
time.sleep(2)
self.driver.find_element_by_xpath("//span[@class='menu-text'][text()='托运单']").click()
time.sleep(1)
self.driver.find_element_by_xpath("//button[@id='btn-addTag']").click()
bs=self.driver.find_element_by_id("tag_tagNo")
bs.send_keys(ls)
bs.send_keys(Keys.RETURN)#回车
time.sleep(2)
self.driver.find_element_by_xpath("//button[@class='btn btn-success ehkey-save']").click()
self.driver.quit()
2.上述代码中:
①self.driver.execute_script("$('#tag_receivingId_flexselect').blur();$('#tag_receivingId option:eq(2)').attr('selected',true).change();ecui.form.flexSelect('#tag_receivingId');")#运用js来下拉选择数据(隐藏属性)
②在层级菜单中,一定需要加上一个延时,这里以time.sleep(2)为例,否则,会报错
③ls=self.driver.execute_script('return $("#hid_new_tagno").text();')#使用return返回值,运用JS来获取内容值
Python+selenium之获取文本值和下拉框选择数据的更多相关文章
- vue-如何清除下拉框选择数据
清除前 清除后 在选择select标签里加一个属性clearable便可实现该效果.
- PHP文本框的值随下拉框改变
初学PHP,下面是实现文本框内容随下拉框变化的代码实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- 获取 TUniConnection.SpecificOptions默认值和下拉框列表值
TUniConnection的SpecificOptions参数决定了数据库连接配置参数,但可惜的是,SpecificOptions设计器界面,Devart公司只能让它在设计期配置! Specific ...
- Selenium 3----警告框处理+下拉框选择
警告框处理 在WebDriver中处理JavaScript所生成的alert.confirm以及prompt十分简单,具体做法是使用 switch_to.alert 方法定位到 alert/confi ...
- robotframework文本类型的下拉框
对于下拉框定位和输入,这里主要遇到有两种类型的下拉选择. 其中一个类型是select-options格式,如图 这种方式的定位可以使用select from list by value或select ...
- robotframework自动化系列:文本类型的下拉框
对于下拉框定位和输入,这里主要遇到有两种类型的下拉选择. 其中一个类型是select-options格式,如图 这种方式的定位可以使用select from list by value或select ...
- jquery根据下拉框选择的值显示输入框
原理就是根据下拉框选择的值来控制显示那个输入框: html代码: 首先定义一个下拉框,$serviceTypeList就是后台传过来的所有属性, <div class="uk-form ...
- Selenium3 + Python3自动化测试系列八——警告框处理和下拉框选择
警告框处理 在WebDriver中处理JavaScript所生成的alert.confirm以及prompt十分简单,具体做法是使用 switch_to.alert 方法定位到 alert/confi ...
- 前端下拉框选择和动态生成调用div
进入到一个项目期中,一边做项目,一边学习其中用到的知识.这些知识都是零碎的,有数据库,有html,有js,还有django.趁周末时间,整理前面遇到过的前端相关的知识点. 下拉框选择 <html ...
随机推荐
- jsp基本语法总结
一,用jsp脚本元素调用java代码 1,jsp表达式的应用 jsp表达式将值直接插入到输出中: <%= Java Expression %> 代表一个值 隐式对象,在使用jsp表达式的 ...
- 如何发布本地maven项目jar包部署到nexus私服?
首先在我们的pom里面描述我们要部署的地址: <distributionManagement> <repository> <id>release</id> ...
- 解析theme()
drupal_render()只是对theme()的调用做了包装,真正做任务的还是theme(). function theme($hook, $variables = array()) { ... ...
- js处理url
需求:用js获得url的电话号码和状态 针对url地址:http://www.deikang.com/index.php?tel=15811296111&status=1&id=100 ...
- Linux-Vim使用技巧
cd /tmp 切换到/tmp目录下面 vim shijiazhuang.txt 编辑shijiazhuang.txt文件 welcome to shijiazhuang. yu hua qu c ...
- STL中map错误用法一例
[GBK]0G's fans( me ) 13:34:26typedef struct _TX_DATA{ int len; unsigned char buff[0x100]; } TX_DATA, ...
- ItelliJ项目打jar包
不是Eclipse里方便的export...了. 一.配置 . 点击View->Open Module Settings(快捷键是F4) . 在弹出的对话框中,点击最左侧树的Artifacts ...
- unity, Rigidbody.constraints
一,同时施加多个限制: 用按位或(bitwise OR)实现,例如: GetComponent<Rigidbody>().constraints=RigidbodyConstraints. ...
- Python3中使用HTMLTestRunner报No module named 'StringIO'解决方法
今天在学习使用HTMLTestRunner生成测试报告时遇到一个报错,如图所示: 网上搜索了下“No module named 'StringIO'”解决方法,原来我用的是Python 3.X版本,而 ...
- java 高精度 四则运算
java的大数处理对于ACM中的大数来说,相当的简单啊: 整数的运算 BigInteger 小数的运算 BigDecimal 导入类: import java.util.Scanner; im ...