`
aerchi
  • 浏览: 424446 次
  • 性别: Icon_minigender_1
  • 来自: 昆明
文章分类
社区版块
存档分类
最新评论

webdriver如何操作select

 
阅读更多
需要测试的网页用firefox查看如下
<formid="searchForm"enctype="application/x-www-form-urlencoded"action="/receive/asnList.xhtml"method="post"name="searchForm">
<inputtype="hidden"value="searchForm"name="searchForm">
<tablewidth="100%">
<tbody>
<tr>
<td>
<td>
<inputtype="text"style="width:118px"onblur="return ValidTextAreaLength(this,'30');"maxlength="30"name="searchForm.:j_id232">
</td>
<td>
<td>
<selectstyle="width:118px"size="1"name="searchForm.:j_id236">
<optionselected="selected"value="">-请选择-</option>
<optionvalue="1">1</option>
<optionvalue="2">2</option>
<optionvalue="3">3</option>

</select>
</td>

如果需要点击select控件,选择其中某个菜单,然后点击查询按钮,代码如下
Select asnselect=new Select(driver.findElement(By.xpath("//form[@id='searchForm' and @name='searchForm']/table/tbody/tr/td[4]/select")));
asnselect.selectByIndex(1);
driver.findElement(By.id("searchForm.:btnQuery")).click();
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics