webdriver如何操作select
上一篇 /
下一篇 2012-06-08 15:41:57
/ 个人分类:原创
示例:
需要
测试的网页用firefox查看如下
<form id="searchForm" enctype="application/x-www-form-urlencoded" action="/receive/asnList.xhtml" method="post" name="searchForm"><input type="hidden" value="searchForm" name="searchForm"> <table width="100%"> <tbody> <tr> <td> <td> <input type="text" style="width:118px" onblur="return ValidTextAreaLength(this,'30');" maxlength="30" name="searchForm.:j_id232"> </td> <td> <td> <select style="width:118px" size="1" name="searchForm.:j_id236"> <option selected="selected" value="">-请选择-</option> <option value="1">1</option> <option value="2">2</option> <option value="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();
收藏
举报
TAG: