HTML源页面:
//开始:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<div id="ctl00_ContentPlaceHolder1_control1_pnlEdit">
<h2>
<span id="ctl00_ContentPlaceHolder1_control1_lblEditHeader">Add New</span></h2>
<br /><br />
<div>
<table class="DetailsView" cellspacing="0" cellpadding="5" rules="all" border="1" id="ctl00_ContentPlaceHolder1_control1" style="height:50px;width:600px;border-collapse:collapse;">
<tr>
<td> </td><td>
</td>
</tr><tr>
<td>Category</td><td>
<div style="border-style: solid; border-width: 1px; border-color: inherit; overflow:auto; height:200px; width:300px;" >
<table id="ctl00_ContentPlaceHolder1_control1_lstCat" class="CheckBoxList" selectionmode="Multiple" border="0">
<tr>
<td><span style="padding-left:0px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_0" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$0" /><label for="ctl00_ContentPlaceHolder1_control1_lstCat_0">Item
1</label></span></td>
</tr><tr>
<td><span style="padding-left:15px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_1" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$1" />Item
1-2</span></td>
</tr><tr>
<td><span style="padding-left:15px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_2" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$2" /><span>Item
1-3</span></span></td>
</tr><tr>
<td><span style="padding-left:15px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_3" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$3" /><span>Item
1-4</span></span></td>
</tr><tr>
<td><span style="padding-left:0px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_4" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$4" /><span>Item
2</span></span></td>
</tr><tr>
<td><span style="padding-left:15px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_5" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$5" /><span>Item
2-1</span></span></td>
</tr><tr>
<td><span style="padding-left:0px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_6" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$6" /><span>Item
3</span></span></td>
</tr><tr>
<td><span style="padding-left:15px;"><input id="ctl00_ContentPlaceHolder1_control1_lstCat_7" type="checkbox" name="ctl00$ContentPlaceHolder1$control1$dv$lstCat$7" /><span>Item
3-1</span></span></td>
</tr>
</table>
</div>
</td>
</tr><tr>
<td> </td><td> </td>
</tr>
</table>
</div>
</div>
</body>
</html>
//结尾
编辑: 使用 Selenium WebDriver 选择元素后跟文本
我的问题类似于上面的帖子
结束编辑
下面是它在运行时呈现的我的页面源代码
例如,我有为每个复选框生成的唯一复选框 ID:
ctl00_ContentPlaceHolder1_Control1_stCat_1
ctl00_ContentPlaceHolder1_Control1_stCat_2
ctl00_ContentPlaceHolder1_Control1_stCat_3
..........................................
ctl00_ContentPlaceHolder1_Control1_stCat_8
etc..............
我的要求是:如果我通过了,Checkbox Text
那么它应该选择相关的复选框,例如:
如果我通过 Checkbox Text =Some text present.....
那么 Checkbox Idctl00_ContentPlaceHolder1_Control1_stCat_1
应该被选中
PS:Item 1, Item 2
只是真实数据中的一个例子我有一些随机的名字
下面是我的html代码生成:
<tr>
<td>Category</td>
<td>
<div style="border-style: solid; border-width: 1px; border-color: inherit; overflow:auto; height:200px; width:300px;">
<table id="ctl00_ContentPlaceHolder1_AddControl1_lstCat" class="CheckBoxList" border="0" selectionmode="Multiple">
<tbody>
<tr>
<td>
<span style="padding-left:15px;">
<input id="ctl00_ContentPlaceHolder1_Control1_stCat_1" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$1"/>
<label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_8">Item 1</label>
</span>
</td>
</tr>
<tr>
<td>
<span style="padding-left:15px;">
<input id="ctl00_ContentPlaceHolder1_Control1_stCat_2" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$2"/>
<label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_2">Item 2</label>
</span>
</td>
</tr>
<tr>
<td>
<span style="padding-left:15px;">
<input id="ctl00_ContentPlaceHolder1_Control1_stCat_3" type="checkbox" name="ctl00$ContentPlaceHolder1$AddControl1$cat$lstCat$3"/>
<label for="ctl00_ContentPlaceHolder1_AddControl1_lstCat_3">Item 3</label>
</span>
</td>
</tr>
.............
..............
................
.................
more...............