要求是驗證下表的列順序與列標題名稱的順序是否正確。驗證來自硒的表列順序
因此,我已經寫下來掩蓋我的要求,它接受在所要求的順序表標題名稱的數組列表[字符串]的方法。
但它顯然不通過軟認定爲「isDisplayed()方法總是返回「假」做我的要求。
任何人都可以建議我懇請進一步指出修改並把它固定的嗎?
爲表HTLM代碼:
<table id="examMarkEntryExamList" class="display table table-bordered table-striped dynamic-table display_header_class">
<thead>
<tr>
<th class="text-center sortable sorted order1">Academic Year</th>
<th class="text-center sortable sorted order1">Curriculum</th>
<th class="text-center sortable sorted order1">Grade</th>
<th class="text-center sortable sorted order1">Semester/Term</th>
<th class="text-center sortable sorted order1">
<a class="pagination-cuser-point">Exam Code</a>
</th>
<th class="text-center sortable sorted order1">Actions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>2016-2016</td>
<td>LOCAL</td>
<td>GRADE11</td>
<td>2nd Term</td>
<td>G11SecondTerm</td>
<td>
</tr>
</tbody>
</table>
硒【JAVA]的方法來驗證列的順序
public void verifyColumnOrder(WebDriver driver, String tableId, ArrayList<String> columnHeaderList) {
SoftAssert softassert = new SoftAssert();
String relativeXpath = "//table[contains(@id,'"+tableId+"')]/";
for (String columnHeader : columnHeaderList) {
relativeXpath = relativeXpath + "/following-sibling::th[contains(.,'" + columnHeader + "')]";
softassert.assertTrue(driver.findElement(By.xpath(relativeXpath)).isDisplayed());
}
softassert.assertAll();
}
將findElements更改爲findElement。否則,你將在不能編譯的列表上調用getText()。否則在getText – Grasshopper
@Grasshoppe之前追加'[0]',謝謝。 –