我正在使用Selenium WebDriver 和 Java 。
我有一个表,我必须单击每列的标题,并想验证排序功能是否正常工作。我需要检查Asc
和Desc
订单。
所以我必须首先获取表的计数并获取标题文本,以便我单击每个 col 1-1 ,然后需要验证排序。
如何达到我的预期效果。以下是HTML源代码:
<div>
<table cellspacing="0" rules="all" border="1" id="ctl00_ContentPlaceHolder1_gvClinicalTrait" style="border-color:appworkspace;border-collapse:collapse;">
<tr class="gridTitleBar">
<th scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvClinicalTrait','Sort$TraitDate')">Date Collected</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvClinicalTrait','Sort$TraitDesc')">Clinical Trait Data</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvClinicalTrait','Sort$TraitSourceDesc')">Source</a></th><th scope="col"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvClinicalTrait','Sort$TraitValue')">Value</a></th>
</tr><tr class="gridBody" align="left">
<td>11/6/2008</td><td style="width:200px;">A1C</td><td style="width:200px;">d</td><td>6.00</td>
</tr><tr class="gridBody" align="left">
<td>9/17/2008</td><td style="width:200px;">BP</td><td style="width:200px;">e)</td><td>104/54</td>
</tr><tr class="gridBody" align="left">
<td>7/12/2008</td><td style="width:200px;">BP</td><td style="width:200px;">g</td><td>124/56</td>
</tr><tr class="gridBody" align="left">
<td>6/21/2008</td><td style="width:200px;">BP</td><td style="width:200px;">t</td><td>110/72</td>
</tr><tr class="gridBody" align="left">
<td>6/14/2008</td><td style="width:200px;">BP</td><td style="width:200px;">n</td><td>120/70</td>
</tr>
</table>
</div>
答案 0 :(得分:-1)
如何达到我的预期效果。以下是HTML源代码:
您需要为每个测试创建这样的循环:
SqlConnection
{ string result = driver.Find(by.xpath(&#34; // div [@id =&#39; ctl00_ContentPlaceHolder1_gvClinicalTrait&#39;] / tr [&#34; + i +&#34;] / td [& #34; + tdNumber +&#34;]&#34;))文本;
List<string> expectedValues = new List<string>("12","13","14");
int expectedNumber = expectedValues.Count;
int tdNumber = 2;
for (int i=1; i< expectedNumber; i++)
}
我没有尝试过这段代码,但即使它错了,它也会非常接近您需要的代码。