示例代码如下:
<select id="ctl00_MainContentPlaceHolder_NoticeManage1_ddlNoticeType" class="select" name="ctl00
$MainContentPlaceHolder$NoticeManage1$ddlNoticeType">
<option value="0">请选择</option> <option value="8">重要消息</option> <option value="9">证券要闻</option> <option value="10">大赛规则</option> <option value="11">21212</option> </select>
有多种方式,先定位到选择框的id,然后再取值 //通过下拉列表中选项的索引选中第二项Select selectAge = new Select(dr.findElement(By.id("你要选择的值id"))); selectAge.selectByIndex(2); //通过下拉列表中的选项的value属性选中这一项 Select selectShen = new Select(dr.findElement(By.id("你要选择的值id"))); selectShen.selectByValue("value值"); //通过下拉列表中选项的可见文本选中 Select selectTown = new Select(dr.findElement(By.id("你要选择的值id"))); selectTown.selectByVisibleText("文本值");
//通过Xpath定位 Select selectSex = new Select(dr.findElement(By.xpath("//[@id='你要选择的id的值']/option[2]").click(); //表示定位到该id节点下第2个option元素
|
selenium获取下拉框中的选中的文本的方式
最新推荐文章于 2024-07-26 17:51:45 发布