selenium webdriver学习(八)------------如何操作select下拉框(转)
下面我们来看一下selenium webdriver是如何来处理select下拉框的,以http://passport.51.com/reg2.5p这个页面为例。这个页面中有4个下拉框,下面演示4种选中下拉框选项的方法。select处理比较简单,直接看代码吧:)
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.support.ui.Select;
- public class SelectsStudy {
- /**
- * @author gongjf
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
- WebDriver dr = new FirefoxDriver();
- dr.get("http://passport.51.com/reg2.5p");
- //通过下拉列表中选项的索引选中第二项,即2011年
- Select selectAge = new Select(dr.findElement(By.id("User_Age")));
- selectAge.selectByIndex(2);
- //通过下拉列表中的选项的value属性选中"上海"这一项
- Select selectShen = new Select(dr.findElement(By.id("User_Shen")));
- selectShen.selectByValue("上海");
- //通过下拉列表中选项的可见文本选 中"浦东"这一项
- Select selectTown = new Select(dr.findElement(By.id("User_Town")));
- selectTown.selectByVisibleText("浦东");
- //这里只是想遍历一下下拉列表所有选项,用click进行选中选项
- Select selectCity = new Select(dr.findElement(By.id("User_City")));
- for(WebElement e : selectCity.getOptions())
- e.click();
- }
- }
从上面可以看出,对下拉框进行操作时首先要定位到这个下拉框,new 一个Selcet对象,然后对它进行操作。
selenium webdriver学习(八)------------如何操作select下拉框(转)的更多相关文章
- Selenium常用操作汇总二——如何操作select下拉框
下面我们来看一下selenium webdriver是如何来处理select下拉框的,以http://passport.51.com/reg2.5p这个页面为例.这个页面中有4个下拉框,下面演示4种选 ...
- jquery操作select下拉框的各种方法,获取选中项的值或文本,根据指定的值或文本选中select的option项等
简介jquery里对select进行各种操作的方法,如联动.取值.根据值或文本来选中指定的select下拉框指定的option选项,读取select选中项的值和文本等. 这一章,站长总结一下jquer ...
- JQuery操作select下拉框
JQuery操作select下拉框 获取Select选择的Text和Value $("#select_id").change(function(){//code...}); //为 ...
- Selenium系列(十) - 针对Select下拉框的操作和源码解读
如果你还想从头学起Selenium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1680176.html 其次,如果你不懂前端基础知识, ...
- Selenium2学习(十一)-- select下拉框
本篇以百度设置下拉选项框为案例,详细介绍select下拉框相关的操作方法. 一.认识select 1.打开百度-设置-搜索设置界面,如下图所示 2.箭头所指位置,就是select选项框,打开页面 ...
- jquery操作select下拉框的多种方法(选中,取值,赋值等)
Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Sel ...
- jQuery操作select下拉框的text值和value值的方法
1.jquery获取当前选中select的text值 $("#select1").find("option:selected").text(); 2.jquer ...
- jquery操作select下拉框:取值,赋值,删除
1.jQuery对select的取值 <select id="test"> <option value ="1">测试1</opt ...
- Python+Selenium操作select下拉框
首先需要倒入Select模块: from selenium.webdriver.support.select import Select 常用方法: 通过索引定位:select_by_index() ...
随机推荐
- python 轴向连接
- golang标准库中有些函数只有签名没有函数体是怎么回事?
- Ionic.Zip
1.Ionic.zIP 实现文件压缩和解压 2.压缩: /// <summary> /// 压缩文件 /// </summary> / ...
- BZOJ1455罗马游戏
左偏树裸题. 题面描述让人意识到了平面几何的重要性. //Achen #include<algorithm> #include<iostream> #include<cs ...
- selenium 常见问题之 nknown error: call function result missing ‘value’
运行时候出现错误提示如下: 出现该问题原因:chrome浏览器自动升级.导致和chromedriver支持的版本不匹配. 解决方案有两种(本人采用的是第一种方式解决办法.): 1.下载和当前使用的ch ...
- hdu 1711Number Sequence (KMP入门,子串第一次出现的位置)
Number Sequence Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机组成原理作业一 熟悉MIPS指令
第一题 .data outputd: .asciiz "Alpha","November","First","alpha" ...
- tablespaces
select * from user_tablespaces; select username,default_tablespace from user_users;
- POJ1190 洛谷P1731 NOI1999 生日蛋糕
生日蛋糕(蛋糕是谁?) Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20272 Accepted: 7219 Desc ...
- PHPCMS快速建站系列之getcache()的用法
/** * 读取缓存,默认为文件缓存,不加载缓存配置. * @param string $name 缓存名称 * @param $filepath 数据路径(模块名称) caches/cache_$f ...