WebDriver操作select下拉框
作者:网络转载 发布时间:[ 2016/3/2 14:28:57 ] 推荐标签:测试管理工具 软件测试工具
【代码】:
1 <select id="user_select" name="agreement.owner">
2 <option value="user1">张三</option>
3 <option value="user2">李四</option>
4 </select>
Select类常用的方法:
1. selectByVisibleText:下拉列表中,通过可见文本的值,选择选项
1 Select select = new Select(driver.findElementById("user_select"));
2 select.selectByVisibleText("张三");
2. selectByIndex:下拉列表中,通过选项的位置,选择选项
1 Select select = new Select(driver.findElementById("user_select"));
2 select.selectByIndex(1);
备注:
1. index是用0开始算
2. selectByValue:下拉列表中,通过选项的value属性的值,选择选项
1 Select select = new Select(driver.findElementById("user_select"));
2 select.selectByValue("user1");